public void ReturnsWhatTheSerializeToByteArrayExtensionMethodOnTheDefaultBinarySerializerReturns() { var foo = new Foo { Bar = "abc123" }; var result = foo.ToBinary(); var expectedResult = DefaultBinarySerializer.Current.SerializeToByteArray(foo, foo.GetType()); Assert.That(result, Is.EqualTo(expectedResult)); }
public void ExpressionPropertyInvoker_GetPropertyValue_Test() { var foo = new Foo(); var propertyInfo = foo.GetType().GetProperty("Bar"); foo.Bar = "Hello"; var result = ExpressionPropertyInvoker.Instance .GetPropertyValue(propertyInfo, foo); Assert.That(result, Is.EqualTo(foo.Bar)); }
public void ExpressionPropertyInvoker_SetPropertyValue_Test() { var foo = new Foo(); var propertyInfo = foo.GetType().GetProperty("Bar"); ExpressionPropertyInvoker.Instance.ConvertValueFn = new SqliteOrmLiteDialectProvider().ConvertDbValue; ExpressionPropertyInvoker.Instance .SetPropertyValue(propertyInfo, typeof(string), foo, "Hello"); Assert.That(foo.Bar, Is.EqualTo(foo.Bar)); }
public void Test_structs_with_double_quotes() { var dto = new Foo { Content1 = "My \"quoted\" content", Name = "My \"quoted\" name" }; JsConfig<Text>.SerializeFn = text => text.ToString(); JsConfig<Text>.DeSerializeFn = v => new Text(v); var json = JsonSerializer.SerializeToString(dto, dto.GetType()); Assert.That(json, Is.EqualTo("{\"Name\":\"My \\\"quoted\\\" name\",\"Content1\":\"My \\\"quoted\\\" content\"}")); var foo = JsonSerializer.DeserializeFromString<Foo>(json); Assert.That(foo.Name, Is.EqualTo(dto.Name)); Assert.That(foo.Content1, Is.EqualTo(dto.Content1)); }
public void Test_structs() { JsConfig<Text>.SerializeFn = text => text.ToString(); var dto = new Foo { Content1 = "My content", Name = "My name" }; var json = JsonSerializer.SerializeToString(dto, dto.GetType()); Assert.That(json, Is.EqualTo("{\"Name\":\"My name\",\"Content1\":\"My content\"}")); }
private static void CompareFoo(Foo original, Foo clone, string message) { Assert.IsNotNull(clone, message); Assert.AreNotSame(original, clone); Assert.AreEqual(original.Id, clone.Id, message + ": Id"); Assert.AreEqual(original.Name, clone.Name, message + ": Name"); Assert.AreEqual(typeof(Foo), clone.GetType(), message); }