Ejemplo n.º 1
0
		public RouteValues RouteValues(object dataObject)
		{
			var propertiesList = PropertiesList(dataObject);

			var expectedProps = new RouteValues();
			expectedProps.AddRangeWithParse(propertiesList);
			return expectedProps;
		}
Ejemplo n.º 2
0
        public RouteValues RouteValues(object dataObject)
        {
            var propertiesList = PropertiesList(dataObject);

            var expectedProps = new RouteValues();

            expectedProps.AddRangeWithParse(propertiesList);
            return(expectedProps);
        }
Ejemplo n.º 3
0
		public void ReadsEmptyDataAsFail()
		{
			var data = new Dictionary<string, string>();
			var props = new RouteValues(data);
			props.CheckDataOk();

			Assert.That(props.DataOk, Is.False, "data ok");
			Assert.That(props.Controller, Is.Null, "controller");
			Assert.That(props.Action, Is.Null, "action");
		}
Ejemplo n.º 4
0
        internal static void GeneratesActionUrl(RouteCollection routes, HttpMethod httpMethod, string expectedUrl, 
            RouteValues fromProps, string appPath, string requestBody)
        {
            fromProps.CheckDataOk();
            if (!fromProps.DataOk)
            {
                return;
            }

            var routeValueDict = fromProps.AsRouteValueDictionary();

            GeneratesActionUrl(routes, httpMethod, expectedUrl,
                fromProps.Action, fromProps.Controller, appPath, routeValueDict, requestBody);
        }
Ejemplo n.º 5
0
        internal static void HasRoute(RouteCollection routes, HttpMethod method, string url, string body, BodyFormat bodyFormat, RouteValues expectedProps)
        {
            var pathUrl = UrlHelpers.PrependTilde(url);
            var httpContext = HttpMockery.ContextForUrl(method, pathUrl, body);
            var routeData = GetRouteDataWithAttributeFilter(routes, httpContext);

            if (routeData == null)
            {
                var message = string.Format("Should have found the route to '{0}'", url);
                Asserts.Fail(message);
            }

            var webRouteReader = new Reader();
            var actualProps = webRouteReader.GetRequestProperties(routeData, httpContext.Request, bodyFormat);
            var verifier = new Verifier(expectedProps, actualProps, url);
            verifier.VerifyExpectations();
        }
Ejemplo n.º 6
0
		public void TestCreateWithObjectDictionary()
		{
			var valuesIn = new Dictionary<string, object>
				{
					 { "controller", "foo" },
					 { "action", "bar" },
					 { "area", "fish" },
					 { "Id", 3 },
				};

			var values = new RouteValues(valuesIn);

			Assert.That(values, Is.Not.Null);
			Assert.That(values.Controller, Is.EqualTo("foo"));
			Assert.That(values.Action, Is.EqualTo("bar"));
			Assert.That(values.Area, Is.EqualTo("fish"));

			Assert.That(values.GetRouteValue("Id", RouteValueOrigin.Unknown).Value, Is.EqualTo(3));
		}
		public void ShouldSortValuesAlphabeticallyByName()
		{
			var valuesIn = new Dictionary<string, string>
				{
					 { "controller", "foo" },
					 { "action", "bar" },
					 { "z", "a" },
					 { "b", "b" },
					 { "a", "z" }
				};

			var routeValues = new RouteValues(valuesIn);

			routeValues.Sort();

			Assert.That(routeValues.Values[0].Name, Is.EqualTo("a"));
			Assert.That(routeValues.Values[1].Name, Is.EqualTo("b"));
			Assert.That(routeValues.Values[2].Name, Is.EqualTo("z"));
		}
Ejemplo n.º 8
0
        public RouteValues GetRequestProperties(RouteData routeData, HttpRequestBase request, BodyFormat bodyFormat)
        {
            RouteValues result;

            if (routeData == null)
            {
                result = new RouteValues();
            }
            else
            {
                result = new RouteValues(routeData.Values);
            }

            var requestParams = ReadRequestParams(request.Params);
            result.AddRange(requestParams);

            var bodyContent = ReadPropertiesFromBodyContent(request, bodyFormat);
            result.AddRange(bodyContent);

            result.Area = ReadAreaFromRouteData(routeData);
            return result;
        }
Ejemplo n.º 9
0
		public void AsRouteValueDictionaryReadsAllValues()
		{
			var data = new Dictionary<string, object>
				{
					{ "id", 3 }
				};

			var values = new RouteValues(data);
			values.Controller = "foo";
			values.Action = "bar";
			values.Area = "fish";

			var outValues = values.AsRouteValueDictionary();

			Assert.That(outValues.Count, Is.EqualTo(4));
			Assert.That(outValues["controller"], Is.EqualTo("foo"));
			Assert.That(outValues["action"], Is.EqualTo("bar"));
			Assert.That(outValues["area"], Is.EqualTo("fish"));
			Assert.That(outValues["id"], Is.EqualTo(3));
		}
Ejemplo n.º 10
0
		public void ReadsControllerAndActionToDataOk()
		{
			var data = new Dictionary<string, string>
				{
					{ "controller", "foo" },
					{ "action", "bar" },
				};

			var props = new RouteValues(data);
			props.CheckDataOk();

			Assert.That(props.DataOk, Is.True, "data ok");
		}
Ejemplo n.º 11
0
		public void ReadsControllerAndAction()
		{
			var data = new Dictionary<string, string>
				{
					{ "controller", "foo" },
					{ "action", "bar" },
				};

			var props = new RouteValues(data);

			Assert.That(props.Controller, Is.EqualTo("foo"), "controller");
			Assert.That(props.Action, Is.EqualTo("bar"), "action");
			Assert.That(props.Values.Count, Is.EqualTo(0), "route values empty");
		}
Ejemplo n.º 12
0
		public void ReadsEmptyDataWithoutRouteValues()
		{
			var data = new Dictionary<string, string>();
			var props = new RouteValues(data);

			Assert.That(props.Values, Is.Not.Null, "route values null");
			Assert.That(props.Values.Count, Is.EqualTo(0), "route values empty");
		}
Ejemplo n.º 13
0
		public void ReadRouteValueDictionary()
		{
			var data = new RouteValueDictionary
				{
					{ "controller", "foo" },
					{ "action", "bar" },
					{ "id", 3 },
				};

			var values = new RouteValues(data);

			Assert.That(values, Is.Not.Null);
			Assert.That(values.Controller, Is.EqualTo("foo"));
			Assert.That(values.Action, Is.EqualTo("bar"));

			Assert.That(values.GetRouteValue("Id", RouteValueOrigin.Unknown).Value, Is.EqualTo(3));
		}
Ejemplo n.º 14
0
		public Verifier(RouteValues expected, RouteValues actual, string url)
		{
			this.expected = expected;
			this.actual = actual;
			this.url = url;
		}
Ejemplo n.º 15
0
		private static RouteValues RouteValuesContainingId()
		{
			var values = new RouteValues();
			var idValue = new RouteValue("Id", 42, RouteValueOrigin.Unknown);
			values.Add(idValue);

			return values;
		}
Ejemplo n.º 16
0
 public static void HasRoute(RouteCollection routes, string url, IDictionary<string, string> expectedProps)
 {
     var expectedRouteValues = new RouteValues(expectedProps);
     WebRouteAssert.HasRoute(routes, HttpMethod.Get, url, string.Empty, BodyFormat.None, expectedRouteValues);
 }
			public void SameNamedValuesAreSortedByOrigin()
			{
				var routeValues = new RouteValues();

				routeValues.Add(new RouteValue("a", "ccc", RouteValueOrigin.Params));
				routeValues.Add(new RouteValue("a", "aaa", RouteValueOrigin.Body));
				routeValues.Add(new RouteValue("a", "bbb", RouteValueOrigin.Path));

				routeValues.Sort();

				Assert.That(routeValues.Values[0].Name, Is.EqualTo("a"));
				Assert.That(routeValues.Values[1].Name, Is.EqualTo("a"));
				Assert.That(routeValues.Values[2].Name, Is.EqualTo("a"));

				Assert.That(routeValues.Values[0].Origin, Is.EqualTo(RouteValueOrigin.Path));
				Assert.That(routeValues.Values[1].Origin, Is.EqualTo(RouteValueOrigin.Params));
				Assert.That(routeValues.Values[2].Origin, Is.EqualTo(RouteValueOrigin.Body));
			}
Ejemplo n.º 18
0
 public static void HasRoute(RouteCollection routes, string url, HttpMethod httpMethod, string body, BodyFormat bodyFormat, IDictionary<string, string> expectedProps)
 {
     var expectedRouteValues = new RouteValues(expectedProps);
     WebRouteAssert.HasRoute(routes, httpMethod, url, body, bodyFormat, expectedRouteValues);
 }
Ejemplo n.º 19
0
 public static void GeneratesActionUrl(RouteCollection routes, string expectedUrl, IDictionary<string, string> fromProps, string appPath = "/")
 {
     var expectedRouteValues = new RouteValues(fromProps);
     WebRouteAssert.GeneratesActionUrl(routes, HttpMethod.Get, expectedUrl, expectedRouteValues, appPath, null);
 }
Ejemplo n.º 20
0
		public void ReadsOtherValuesAsRouteValues()
		{
			var data = new Dictionary<string, string>
				{
					{ "controller", "foo" },
					{ "action", "bar" },
					{ "fish", "hallibut" },
				};

			var props = new RouteValues(data);
			props.CheckDataOk();

			Assert.That(props.DataOk, Is.True, "data ok");
			Assert.That(props.Values.Count, Is.EqualTo(1), "route values not empty");

			var output = props.GetRouteValue("fish", RouteValueOrigin.Unknown);

			Assert.That(output, Is.Not.Null, "route value missing");
			Assert.That(output.ValueAsString, Is.EqualTo("hallibut"), "route value wrong");
		}
Ejemplo n.º 21
0
 public static void HasApiRoute(HttpConfiguration config, string url, HttpMethod httpMethod, string body, BodyFormat bodyFormat,  IDictionary<string, string> expectedProps)
 {
     var expectedRouteValues = new RouteValues(expectedProps);
     ApiRouteAssert.HasRoute(config, url, httpMethod, body, bodyFormat, expectedRouteValues);
 }
Ejemplo n.º 22
0
		public void TestCreate()
		{
			var values = new RouteValues();
			Assert.That(values, Is.Not.Null);
		}
Ejemplo n.º 23
0
		public void FailsAreReported()
		{
			var data = new Dictionary<string, string>();
			var routeValues = new RouteValues(data);
			routeValues.CheckDataOk();

			Assert.That(assertEngine.FailCount, Is.EqualTo(2));
			Assert.That(routeValues.DataOk, Is.False);
		}
		public void ShouldPutOptionalRouteValuesinPlace()
		{
			var valuesIn = new Dictionary<string, object>
				{
					 { "controller", "foo" },
					 { "action", "bar" },
					 { "z", "a" },
					 { "b", "b" },
					 { "a", RouteParameter.Optional }
				};

			var routeValues = new RouteValues(valuesIn);

			routeValues.Sort();

			Assert.That(routeValues.Values[0].Name, Is.EqualTo("a"));
			Assert.That(routeValues.Values[1].Name, Is.EqualTo("b"));
			Assert.That(routeValues.Values[2].Name, Is.EqualTo("z"));
		}
Ejemplo n.º 25
0
 public static void GeneratesActionUrl(RouteCollection routes, HttpMethod httpMethod, string expectedUrl,
     IDictionary<string, string> fromProps, string appPath = null, string requestBody = null)
 {
     var fromRouteValues = new RouteValues(fromProps);
     WebRouteAssert.GeneratesActionUrl(routes, httpMethod, expectedUrl, fromRouteValues, appPath, requestBody);
 }
Ejemplo n.º 26
0
		public void ReadsNoControllerDataAsFail()
		{
			var data = new Dictionary<string, string>
				{
					{ "action", "foo" }
				};

			var props = new RouteValues(data);
			props.CheckDataOk();

			Assert.That(props.DataOk, Is.False, "data ok");
		}
			public void ShouldPutOptionalRouteValuesAfterSameNamedOnes()
			{
				var valuesIn = new Dictionary<string, object>
					{
						 { "controller", "foo" },
						 { "action", "bar" },
						 { "a", RouteParameter.Optional }
					};

				var routeValues = new RouteValues(valuesIn);

				routeValues.Add(new RouteValue("a", "zzz", RouteValueOrigin.Params));

				routeValues.Sort();

				Assert.That(routeValues.Values[0].Name, Is.EqualTo("a"));
				Assert.That(routeValues.Values[1].Name, Is.EqualTo("a"));
				Assert.That(routeValues.Values[0].Value, Is.EqualTo("zzz"));
				Assert.That(routeValues.Values[1].Value, Is.EqualTo(RouteParameter.Optional));
			}
Ejemplo n.º 28
0
 public Verifier(RouteValues expected, RouteValues actual, string url)
 {
     this.expected = expected;
     this.actual   = actual;
     this.url      = url;
 }
Ejemplo n.º 29
0
 public static void HasApiRoute(HttpConfiguration config, string url, HttpMethod httpMethod, Dictionary<string, string> headers, IDictionary<string, string> expectedProps)
 {
     var expectedRouteValues = new RouteValues(expectedProps);
     ApiRouteAssert.HasRoute(config, url, httpMethod, headers, string.Empty, BodyFormat.None, expectedRouteValues);
 }