public void ApproxEquals() { Assert.IsTrue(MathUtils.ApproxEquals(0.0, 0.0)); Assert.IsTrue(MathUtils.ApproxEquals(1000.0, 1000.0000000000001)); Assert.IsFalse(MathUtils.ApproxEquals(1000.0, 1000.000000000001)); Assert.IsFalse(MathUtils.ApproxEquals(0.0, 0.00001)); }
public void SpecifiedTest() { SpecifiedTestClass c = new SpecifiedTestClass(); c.Name = "James"; c.Age = 27; c.NameSpecified = false; string json = JsonConvertX.SerializeObject(c, Formatting.Indented); StringAssert.AreEqual(@"{ ""Age"": 27 }", json); SpecifiedTestClass deserialized = JsonConvertX.DeserializeObject <SpecifiedTestClass>(json); Assert.IsNull(deserialized.Name); Assert.IsFalse(deserialized.NameSpecified); Assert.IsFalse(deserialized.WeightSpecified); Assert.IsFalse(deserialized.HeightSpecified); Assert.IsFalse(deserialized.FavoriteNumberSpecified); Assert.AreEqual(27, deserialized.Age); c.NameSpecified = true; c.WeightSpecified = true; c.HeightSpecified = true; c.FavoriteNumber = 23; json = JsonConvertX.SerializeObject(c, Formatting.Indented); StringAssert.AreEqual(@"{ ""Name"": ""James"", ""Age"": 27, ""Weight"": 0, ""Height"": 0, ""FavoriteNumber"": 23 }", json); deserialized = JsonConvertX.DeserializeObject <SpecifiedTestClass>(json); Assert.AreEqual("James", deserialized.Name); Assert.IsTrue(deserialized.NameSpecified); Assert.IsTrue(deserialized.WeightSpecified); Assert.IsTrue(deserialized.HeightSpecified); Assert.IsTrue(deserialized.FavoriteNumberSpecified); Assert.AreEqual(27, deserialized.Age); Assert.AreEqual(23, deserialized.FavoriteNumber); }
public void SerializeMultiValueEntityKeyCameCase() { EntityKey e = new EntityKey("DataServicesTestDatabaseEntities.Folder", new List <EntityKeyMember> { new EntityKeyMember("GuidId", new Guid("A4E8BA80-EB24-4591-BB1C-62D3AD83701E")), new EntityKeyMember("IntId", int.MaxValue), new EntityKeyMember("LongId", long.MaxValue), new EntityKeyMember("StringId", "String!"), new EntityKeyMember("DateTimeId", new DateTime(2000, 12, 10, 10, 50, 0, DateTimeKind.Utc)) }); string json = JsonConvertX.SerializeObject(e, Formatting.Indented); StringAssert.AreEqual(@"{ ""$id"": ""1"", ""EntitySetName"": ""Folder"", ""EntityContainerName"": ""DataServicesTestDatabaseEntities"", ""EntityKeyValues"": [ { ""Key"": ""GuidId"", ""Type"": ""System.Guid"", ""Value"": ""a4e8ba80-eb24-4591-bb1c-62d3ad83701e"" }, { ""Key"": ""IntId"", ""Type"": ""System.Int32"", ""Value"": ""2147483647"" }, { ""Key"": ""LongId"", ""Type"": ""System.Int64"", ""Value"": ""9223372036854775807"" }, { ""Key"": ""StringId"", ""Type"": ""System.String"", ""Value"": ""String!"" }, { ""Key"": ""DateTimeId"", ""Type"": ""System.DateTime"", ""Value"": ""12/10/2000 10:50:00"" } ] }", json); EntityKey newKey = JsonConvertX.DeserializeObject <EntityKey>(json); Assert.IsFalse(ReferenceEquals(e, newKey)); Assert.AreEqual(5, newKey.EntityKeyValues.Length); Assert.AreEqual("GuidId", newKey.EntityKeyValues[0].Key); Assert.AreEqual(new Guid("A4E8BA80-EB24-4591-BB1C-62D3AD83701E"), newKey.EntityKeyValues[0].Value); Assert.AreEqual("IntId", newKey.EntityKeyValues[1].Key); Assert.AreEqual(int.MaxValue, newKey.EntityKeyValues[1].Value); Assert.AreEqual("LongId", newKey.EntityKeyValues[2].Key); Assert.AreEqual(long.MaxValue, newKey.EntityKeyValues[2].Value); Assert.AreEqual("StringId", newKey.EntityKeyValues[3].Key); Assert.AreEqual("String!", newKey.EntityKeyValues[3].Value); Assert.AreEqual("DateTimeId", newKey.EntityKeyValues[4].Key); Assert.AreEqual(new DateTime(2000, 12, 10, 10, 50, 0, DateTimeKind.Utc), newKey.EntityKeyValues[4].Value); }