public void Try_mess_with_serialization_changing_almost_everything() { Dictionary <String, ClassWithArray> dic = new Dictionary <string, ClassWithArray>(); var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; dic["test"] = obj; var serialized = JsonConvert.SerializeObject(dic, GetSettingsForTest()); Console.WriteLine(serialized); //Simulate another assembly var oldVersion = serialized.Replace("Jarvis.Framework.Tests, Version=1.0.0.0", "Altro.Assembly.Divertente, Version=0.9.0.0"); //now change namespacve oldVersion = oldVersion.Replace( "Jarvis.Framework.Tests.BusTests.JarvisFrameworkRebusSerializationBinderTests+ClassWithArray", "Altro.Assembly.Divertente.Tests.Supercalifragilistichespiralidoso.JarvisFrameworkRebusSerializationBinderTests+ClassWithArray"); Console.WriteLine(oldVersion); //Cannot survive deserialization with full information Assert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetSettingsForTest())); //we can survive update version only with default var deserialized = JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetDefaultSettings()); Assert.That(deserialized["test"].DomainEvents, Is.EquivalentTo(new[] { "Test" })); }
public void DeserializeWithArrayTest() { var obj = new ClassWithArray(); using (var stream = new StreamWriter("ClassWithArray.json", false, Encoding.Default)) { stream.Write($@"{{ ""Array"": [ ""1"", ""2"", ""3"" ] }}"); } using (var stream = new StreamReader("ClassWithArray.json")) { Serializer.Deserialize(stream, obj); } var list = new List <string> { "1", "2", "3" }; Assert.Equal(list, obj.Array); }
public void Full_Serialization_survive_update_change_namespace() { Dictionary <String, ClassWithArray> dic = new Dictionary <string, ClassWithArray>(); var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; dic["test"] = obj; var serialized = JsonConvert.SerializeObject(dic, GetSettingsForTest()); Console.WriteLine(serialized); //Simulate that the serialization was done by an older version of the framework. var oldVersion = serialized.Replace( "Jarvis.Framework.Tests.BusTests.JarvisFrameworkRebusSerializationBinderTests+ClassWithArray", "Jarvis.Framework.Tests.This_was_in_an_old_namespace.JarvisFrameworkRebusSerializationBinderTests+ClassWithArray"); Console.WriteLine(oldVersion); //Cannot survive deserialization with full information Assert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetSettingsForTest())); //we can survive update version only with default var deserialized = JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetDefaultSettings()); Assert.That(deserialized["test"].DomainEvents, Is.EquivalentTo(new[] { "Test" })); }
public void CanInjectAnArrayOfMockServices2() { AutoMocker <ClassWithArray> mocker = createAutoMocker <ClassWithArray>(); ClassWithArray theClass = mocker.ClassUnderTest; theClass.Services.Length.ShouldEqual(0); }
public void A_configuration_object_is_bound() { const string json = @"{ Value: [47,22] }"; _binder = ConfigurationBinderFactory.New(x => { x.AddJson(json); }); _configuration = _binder.Bind <ClassWithArray>(); }
public void A_configuration_object_is_bound() { const string json = @"{ Value: [47,22] }"; _binder = ConfigurationBinderFactory.New(x => { x.AddJson(json); }); _configuration = _binder.Bind<ClassWithArray>(); }
public void CanInjectAnArrayOfMockServices1() { AutoMocker <ClassWithArray> mocker = createAutoMocker <ClassWithArray>(); IMockedService[] services = mocker.CreateMockArrayFor <IMockedService>(3); ClassWithArray theClass = mocker.ClassUnderTest; theClass.Services.Length.ShouldEqual(3); }
public void Class_with_Array() { var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; var serialized = JsonConvert.SerializeObject(obj, GetSettingsForTest()); Console.WriteLine(serialized); Assert.That(!serialized.Contains("System.Private.CoreLib")); }
public void Component_ObjectContainsArray_ResultIsTheSameAsInput() { //Arrange ClassWithArray testClass = _fixture.Create <ClassWithArray>(); //Act var result = AvroConvert.Serialize(testClass); var deserialized = AvroConvert.Deserialize <ClassWithArray>(result); //Assert Assert.NotNull(result); Assert.NotNull(deserialized); Assert.Equal(testClass.theArray.Length, deserialized.theArray.Length); }
public void Full_Serialization_survive_update_version() { Dictionary <String, ClassWithArray> dic = new Dictionary <string, ClassWithArray>(); var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; dic["test"] = obj; var serialized = JsonConvert.SerializeObject(dic, GetSettingsForTest()); //Simulate that the serialization was done by an older version of the framework. var oldVersion = serialized.Replace("Jarvis.Framework.Tests, Version=1.0.0.0", "Jarvis.Framework.Tests, Version=0.9.0.0"); //we can survive update version var deserialized = JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetSettingsForTest()); Assert.That(deserialized["test"].DomainEvents, Is.EquivalentTo(new[] { "Test" })); }
public void Cannot_survive_changing_name_of_final_class() { Dictionary <String, ClassWithArray> dic = new Dictionary <string, ClassWithArray>(); var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; dic["test"] = obj; var serialized = JsonConvert.SerializeObject(dic, GetSettingsForTest()); Console.WriteLine(serialized); //Simulate that the serialization was done by an older version of the framework. var oldVersion = serialized.Replace( "Jarvis.Framework.Tests.BusTests.JarvisFrameworkRebusSerializationBinderTests+ClassWithArray", "This.is.A.Complete.Mess.Of.Type.Name"); Console.WriteLine(oldVersion); Assert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetSettingsForTest())); }
public void Class_With_Primitive_Arrays_Test() { ClassWithArray classWithArray = new ClassWithArray { //ArrayToArray = new short[] { 1, 2, 3 }, //ArrayToList = new List<short> { 1, 2, 3 }, //ListToArray = new short[] { 1, 2, 3 }, ListToList = new List <short> { 1, 2, 3 }, }; ClassWithArrayDto dto; Mapper.CreateMap <ClassWithArray, ClassWithArrayDto>(); dto = Mapper.Map <ClassWithArray, ClassWithArrayDto>(classWithArray); Assert.IsNotNull(dto); //Assert.AreEqual(3, dto.ArrayToArray.Count()); //Assert.AreEqual(3, dto.ArrayToList.Count); //Assert.AreEqual(3, dto.ListToArray.Count()); Assert.AreEqual(3, dto.ListToList.Count); }
public void SerializeWithArrayTest() { var obj = new ClassWithArray { Array = new List <string> { "1", "2", "3" } }; using (var stream = new StreamWriter("ClassWithArray.json", false, Encoding.Default)) { Serializer.Serialize(stream, obj); } using (var stream = new StreamReader("ClassWithArray.json")) { Assert.Equal($@"{{ ""Array"": [ ""1"", ""2"", ""3"" ] }}", stream.ReadToEnd()); } }
public void Full_Serialization_survive_update_change_assembly() { Dictionary <String, ClassWithArray> dic = new Dictionary <string, ClassWithArray>(); var obj = new ClassWithArray(); obj.DomainEvents = new[] { "Test" }; dic["test"] = obj; var serialized = JsonConvert.SerializeObject(dic, GetSettingsForTest()); Console.WriteLine(serialized); //Simulate that the serialization was done by an older version of the framework. var actualVersion = Assembly.GetExecutingAssembly().GetName().Version; var oldVersion = serialized.Replace($"Jarvis.Framework.Tests, Version={actualVersion}", $"Jarvis.Framework.OldAssembly, Version={actualVersion}"); Console.WriteLine(oldVersion); Assert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetSettingsForTest())); //we can survive update version only with default var deserialized = JsonConvert.DeserializeObject <Dictionary <String, ClassWithArray> >(oldVersion, GetDefaultSettings()); Assert.That(deserialized["test"].DomainEvents, Is.EquivalentTo(new[] { "Test" })); }
public void MultipleXmlElementAttributesOnArray() { var test = new ClassWithArray(); test.list = new object[] { 3, "apepe", new AnotherArrayListType(), new DerivedArrayListType() }; Serialize(test); var expected_text = "<:ClassWithArray http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>"; Assert.AreEqual(WriterText, expected_text, WriterText); }
private bool Equals(ClassWithArray other) { return Equals(other.Array.Count, Array.Count); }
private bool Equals(ClassWithArray other) { return(Equals(other.Array.Count, Array.Count)); }