Esempio n. 1
0
		private void VerifyValue(RouteValue expectedValue, RouteValue actualValue)
		{
			if (expectedValue.Value is DateTime)
			{
				VerifyDateTimeValue(expectedValue, actualValue);
			}
			else
			{
				var actualValueString = (actualValue == null) ? string.Empty : actualValue.ValueAsString;
				VerifyStringValue(expectedValue.ValueAsString, actualValueString, expectedValue.Name);
			}
		}
Esempio n. 2
0
 private void VerifyValue(RouteValue expectedValue, RouteValue actualValue)
 {
     if (expectedValue.Value is DateTime)
     {
         VerifyDateTimeValue(expectedValue, actualValue);
     }
     else
     {
         var actualValueString = (actualValue == null) ? string.Empty : actualValue.ValueAsString;
         VerifyStringValue(expectedValue.ValueAsString, actualValueString, expectedValue.Name);
     }
 }
		public IList<RouteValue> ReadBody(string body)
		{
			var values = new List<RouteValue>();

			if (string.IsNullOrWhiteSpace(body))
			{
				return values;
			}

			var json = JObject.Parse(body);

			foreach (var jsonProp in json.Properties())
			{
				var routeValue = new RouteValue(jsonProp.Name, ConvertValue(jsonProp.Value), RouteValueOrigin.Body);
				values.Add(routeValue);
			}

			return values;
		}
Esempio n. 4
0
        private int SortRouteValueByAlphaAndDefault(RouteValue a, RouteValue b)
        {
            var result = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);

            if (result == 0)
            {
                if (a.Value == RouteParameter.Optional)
                {
                    return(1);
                }
                if (b.Value == RouteParameter.Optional)
                {
                    return(-1);
                }

                return((int)a.Origin - (int)b.Origin);
            }

            return(result);
        }
Esempio n. 5
0
		private void AddRouteValue(RouteValue value)
		{
			switch (value.Name.ToLowerInvariant())
			{
				case "controller":
					Controller = value.ValueAsString;
					break;

				case "action":
					Action = value.ValueAsString;
					break;

				case "area":
					Area = value.ValueAsString;
					break;

				default:
					Add(value);
					break;
			}
		}
Esempio n. 6
0
        private void AddRouteValue(RouteValue value)
        {
            switch (value.Name.ToLowerInvariant())
            {
            case "controller":
                Controller = value.ValueAsString;
                break;

            case "action":
                Action = value.ValueAsString;
                break;

            case "area":
                Area = value.ValueAsString;
                break;

            default:
                Add(value);
                break;
            }
        }
Esempio n. 7
0
        private void VerifyDateTimeValue(RouteValue expectedValue, RouteValue actualValue)
        {
            DateTime expectedDateTime       = (DateTime)(expectedValue.Value);
            string   expectedDateTimeString = expectedDateTime.ToString("s", CultureInfo.InvariantCulture);

            DateTime actualDateTime;
            string   actualDateTimeString;
            bool     actualValueParsed;

            if (actualValue.Value is DateTime)
            {
                actualDateTime       = (DateTime)(actualValue.Value);
                actualDateTimeString = actualDateTime.ToString("s", CultureInfo.InvariantCulture);
                actualValueParsed    = true;
            }
            else
            {
                actualDateTimeString = actualValue.ValueAsString;
                actualValueParsed    = DateTime.TryParse(actualDateTimeString, out actualDateTime);
            }

            if (actualValueParsed)
            {
                if (expectedDateTime != actualDateTime)
                {
                    var mismatchErrorMessage = string.Format("Expected '{0}', not '{1}' for '{2}' at url '{3}'.",
                                                             expectedDateTimeString, actualDateTimeString, expectedValue.Name, url);
                    Asserts.Fail(mismatchErrorMessage);
                }
            }
            else
            {
                var parseFailErrorMessage = string.Format("Actual value '{0}' could not be parsed as a DateTime at url '{1}'.",
                                                          actualDateTimeString, url);
                Asserts.Fail(parseFailErrorMessage);
            }

            expectationsDone++;
        }
Esempio n. 8
0
		private void VerifyDateTimeValue(RouteValue expectedValue, RouteValue actualValue)
		{
			DateTime expectedDateTime = (DateTime)(expectedValue.Value);
			string expectedDateTimeString = expectedDateTime.ToString("s", CultureInfo.InvariantCulture);

			DateTime actualDateTime;
			string actualDateTimeString;
			bool actualValueParsed;

			if (actualValue.Value is DateTime)
			{
				actualDateTime = (DateTime)(actualValue.Value);
				actualDateTimeString = actualDateTime.ToString("s", CultureInfo.InvariantCulture);
				actualValueParsed = true;
			}
			else
			{
				actualDateTimeString = actualValue.ValueAsString;
				actualValueParsed = DateTime.TryParse(actualDateTimeString, out actualDateTime);
			}

			if (actualValueParsed)
			{
				if (expectedDateTime != actualDateTime)
				{
					var mismatchErrorMessage = string.Format("Expected '{0}', not '{1}' for '{2}' at url '{3}'.",
						expectedDateTimeString, actualDateTimeString, expectedValue.Name, url);
					Asserts.Fail(mismatchErrorMessage);
				}
			}
			else
			{
				var parseFailErrorMessage = string.Format("Actual value '{0}' could not be parsed as a DateTime at url '{1}'.",
					actualDateTimeString, url);
				Asserts.Fail(parseFailErrorMessage);
			}

			expectationsDone++;
		}
		private static RouteValues RouteValuesContainingId()
		{
			var values = new RouteValues();
			var idValue = new RouteValue("Id", 42, RouteValueOrigin.Unknown);
			values.Add(idValue);

			return values;
		}
Esempio n. 10
0
		public void Add(RouteValue value)
		{
			values.Add(value);
		}
Esempio n. 11
0
		private int SortRouteValueByAlphaAndDefault(RouteValue a, RouteValue b)
		{
			var result = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);

			if (result == 0)
			{
				if (a.Value == RouteParameter.Optional)
				{
					return 1;
				}
				if (b.Value == RouteParameter.Optional)
				{
					return -1;
				}

				return (int)a.Origin - (int)b.Origin;
			}

			return result;
		}
Esempio n. 12
0
		private static bool RouteValueMatches(RouteValue routeValue, string name, RouteValueOrigin expectedOrigin)
		{
			return string.Equals(name, routeValue.Name, StringComparison.OrdinalIgnoreCase) && RouteValueOriginHelpers.Matches(expectedOrigin, routeValue.Origin);
		}
Esempio n. 13
0
 public void Add(RouteValue value)
 {
     values.Add(value);
 }
Esempio n. 14
0
 private static bool RouteValueMatches(RouteValue routeValue, string name, RouteValueOrigin expectedOrigin)
 {
     return(string.Equals(name, routeValue.Name, StringComparison.OrdinalIgnoreCase) && RouteValueOriginHelpers.Matches(expectedOrigin, routeValue.Origin));
 }