public static void Equal(IReadOnlyList <object> expectedCollection, IReadOnlyList <object> actualCollection) { if (expectedCollection == null) { Assert.Null(actualCollection); return; } Assert.Equal(expectedCollection.Count, actualCollection.Count); var count = expectedCollection.Count; for (var index = 0; index < count; ++index) { var expected = expectedCollection[index]; var actual = actualCollection[index]; ObjectAssert.Equal(expected, actual); } }
public static void Equal(object expected, object actual) { // Handle when 'expected' is null. if (expected == null) { Assert.Null(actual); return; } // Handle when 'expected' is not null. Assert.NotNull(actual); var actualType = actual.GetType(); if (actualType.IsSubclassOf(typeof(JToken))) { var actualJToken = (JToken)actual; ObjectAssert.Equal(expected, actualJToken); } else { Assert.Equal(expected, actual); } }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(object expected, JToken actualJToken) { // Handle when 'expected' is null. if (expected == null) { ObjectAssert.IsNull(actualJToken); return; } // Handle when 'expected' is not null. Assert.NotNull(actualJToken); var actualJTokenType = actualJToken.Type; switch (actualJTokenType) { case JTokenType.Array: { var expectedArray = ((IEnumerable <object>)expected).ToList(); var actualJArray = (JArray)actualJToken; Assert.Equal(expectedArray.Count, actualJArray.Count); var count = expectedArray.Count; for (var i = 0; i < count; ++i) { var expectedItem = expectedArray[i]; var actualJTokenItem = actualJArray[i]; ObjectAssert.Equal(expectedItem, actualJTokenItem); } } break; case JTokenType.Object: { var actualJObject = (JObject)actualJToken; ObjectAssert.Equal(expected, actualJObject); } break; case JTokenType.Integer: { var expectedInteger = Convert.ToInt64(expected); var actualInteger = (long)actualJToken; Assert.Equal(expectedInteger, actualInteger); } break; case JTokenType.Float: { var expectedFloat = Convert.ToDecimal(expected); var actualFloat = (decimal)actualJToken; Assert.Equal(expectedFloat, actualFloat); } break; case JTokenType.String: { var expectedString = Convert.ToString(expected); var actualString = (string)actualJToken; Assert.Equal(expectedString, actualString); } break; case JTokenType.Boolean: { var expectedBool = Convert.ToBoolean(expected); var actualBool = (bool)actualJToken; Assert.Equal(expectedBool, actualBool); } break; case JTokenType.Date: { var expectedDate = (DateTimeOffset)expected; var actualDate = (DateTimeOffset)actualJToken; Assert.Equal(expectedDate, actualDate); } break; default: Assert.True(false, String.Format("Unknown actual JTokenType [value={0}] in expected object to actual JToken assert method.", actualJTokenType)); break; } }