public void ObjectExtenderContainerConverterConvertFromTypeCompliantWithXmlSerializer() { MockServiceProvider mockServiceProvider = new MockServiceProvider(); Type[] types = { typeof(TestSerializableObject) }; MockServiceProviderService mockService = new MockServiceProviderService(); mockService.ObjectExtenderTypes.Add(types[0]); mockServiceProvider.AddService(typeof(IExtensionProviderService), mockService); ObjectExtenderContainerConverter converter = new ObjectExtenderContainerConverter(mockServiceProvider); TestSerializableObject testObject1 = new TestSerializableObject(); testObject1.ValueOne = "TestDataOne"; testObject1.ValueTwo = 33; string stringRepresentation; ObjectExtenderContainer container1 = new ObjectExtenderContainer(); container1.ObjectExtenders.Add(testObject1); stringRepresentation = GenericSerializer.Serialize<ObjectExtenderContainer>(container1, types); ObjectExtenderContainer container2 = converter.ConvertFrom(stringRepresentation) as ObjectExtenderContainer; Assert.IsNotNull(container2, "container is null"); Assert.IsNotNull(container2.ObjectExtenders, "ObjectExtenders is null"); Assert.AreEqual(1, container2.ObjectExtenders.Count, "container.ObjectExtenders.Count != 1"); TestSerializableObject testObject2 = container2.ObjectExtenders[0] as TestSerializableObject; Assert.AreEqual(testObject1.ValueOne, testObject2.ValueOne, "Not equal"); Assert.AreEqual(testObject1.ValueTwo, testObject2.ValueTwo, "Not equal"); }
public void ObjectExtenderContainerConverterCanConvertFromString() { MockServiceProvider mockServiceProvider = new MockServiceProvider(); MockServiceProviderService mockService = new MockServiceProviderService(); mockServiceProvider.AddService(typeof(IExtensionProviderService), mockService); ObjectExtenderContainerConverter converter = new ObjectExtenderContainerConverter(mockServiceProvider); Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string"); }
public void ExtensionProviderContainerConverterConvertToExtensionProvider() { MockExtensionProvider provider = new MockExtensionProvider(); MockServiceProvider mockServiceProvider = new MockServiceProvider(); MockServiceProviderService mockService = new MockServiceProviderService(); mockServiceProvider.AddService(typeof(IExtensionProviderService), mockService); ExtensionProviderConverter converter = new ExtensionProviderConverter(mockServiceProvider); MockExtensionProvider provider1 = converter.ConvertFrom(provider.ToString()) as MockExtensionProvider; Assert.AreEqual(provider.Id, provider1.Id, "Not Equal"); Assert.AreEqual(provider.Description, provider1.Description, "Not Equal"); Assert.AreEqual(provider.Name, provider1.Name, "Not Equal"); }
public void ObjectExtenderContainerConverterConvertToTypeCompliantWithXmlSerializer() { MockServiceProvider mockServiceProvider = new MockServiceProvider(); MockServiceProviderService mockService = new MockServiceProviderService(); mockServiceProvider.AddService(typeof(IExtensionProviderService), mockService); ObjectExtenderContainerConverter converter = new ObjectExtenderContainerConverter(mockServiceProvider); TestSerializableObject testObject1 = new TestSerializableObject(); testObject1.ValueOne = "TestDataOne"; testObject1.ValueTwo = 33; string stringRepresentation; Type[] types = { typeof(TestSerializableObject) }; ObjectExtenderContainer container1 = new ObjectExtenderContainer(); container1.ObjectExtenders.Add(testObject1); stringRepresentation = GenericSerializer.Serialize<ObjectExtenderContainer>(container1, types); string stringRepresentation2 = converter.ConvertTo(stringRepresentation, typeof(string)) as string; Assert.AreEqual(stringRepresentation, stringRepresentation2, "Not equal"); }