<commit_before>﻿// # Copyright © 2011, Novus Craft
// # All rights reserved. 

using System;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Machine.Specifications;
using Moq;

namespace NovusCraft.Specifications.Utils
{
	public static class RouteTestExtensions
	{
		public static void ShouldBeIgnored(this string requestUrl)
		{
			var httpContext = new Mock<HttpContextBase>();
			httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns(requestUrl);

			var routeData = RouteTable.Routes.GetRouteData(httpContext.Object);
			routeData.ShouldNotBeNull();
			routeData.RouteHandler.ShouldBeOfType<StopRoutingHandler>();
		}

		public static void ShouldMapTo<TController>(this string requestUrl, Expression<Action<TController>> action) where TController : Controller
		{
			var httpContext = new Mock<HttpContextBase>();
			httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns(requestUrl);

			var routeData = RouteTable.Routes.GetRouteData(httpContext.Object);
			routeData.ShouldNotBeNull();

			var controllerName = typeof(TController).Name.Replace("Controller", string.Empty);
			routeData.Values["controller"].ShouldEqual(controllerName);

			var actionName = ((MethodCallExpression)action.Body).Method.Name;
			routeData.Values["action"].ShouldEqual(actionName);
		}
	}
}<commit_msg>Refactored RouteTestExtensions<commit_after>﻿// # Copyright © 2011, <NAME>
// # All rights reserved. 

using System;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Machine.Specifications;
using Moq;

namespace NovusCraft.Specifications.Utils
{
	public static class RouteTestExtensions
	{
		public static void ShouldBeIgnored(this string requestUrl)
		{
			var routeData = GetRouteData(requestUrl);

			routeData.ShouldNotBeNull();
			routeData.RouteHandler.ShouldBeOfType<StopRoutingHandler>();
		}

		public static void ShouldMapTo<TController>(this string requestUrl, Expression<Action<TController>> action) where TController : Controller
		{
			var routeData = GetRouteData(requestUrl);

			routeData.ShouldNotBeNull();

			var controllerName = typeof(TController).Name.Replace("Controller", string.Empty);
			routeData.Values["controller"].ShouldEqual(controllerName);

			var actionName = ((MethodCallExpression)action.Body).Method.Name;
			routeData.Values["action"].ShouldEqual(actionName);
		}

		static RouteData GetRouteData(string requestUrl)
		{
			var httpContext = new Mock<HttpContextBase>();
			httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns(requestUrl);

			var routeData = RouteTable.Routes.GetRouteData(httpContext.Object);
			return routeData;
		}
	}
}
{'fraction_non_alphanumeric': 0.10731174972717351, 'fraction_numerical': 0.0029101491451436886, 'mean_word_length': 5.773399014778325, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676731', 'n_tokens_mistral': 856, 'n_tokens_neox': 773, 'n_words': 155}