public void WhenCollectionIsNull_ShouldReturnInstanceOfAnObjectOfTheSpecifiedType() { //Arange IApiTypeConverter apiTypeConverterStub = MockRepository.GenerateStub <IApiTypeConverter>(); IObjectConverter objectConverter = new Converters.ObjectConverter(apiTypeConverterStub); ICollection <KeyValuePair <string, string> > nullCollection = null; //Act SomeTestingObject someTestingObject = objectConverter.ToObject <SomeTestingObject>(nullCollection); //Assert Assert.IsNotNull(someTestingObject); Assert.IsInstanceOf(typeof(SomeTestingObject), someTestingObject); }
public void WhenCollectionIsEmpty_ShouldReturnInstanceOfAnObjectWithUnsetProperties() { //Arange IApiTypeConverter apiTypeConverterStub = MockRepository.GenerateStub <IApiTypeConverter>(); IObjectConverter objectConverter = new Converters.ObjectConverter(apiTypeConverterStub); ICollection <KeyValuePair <string, string> > emptyCollection = new List <KeyValuePair <string, string> >(); //Act SomeTestingObject someTestingObject = objectConverter.ToObject <SomeTestingObject>(emptyCollection); //Assert Assert.AreEqual(0, someTestingObject.IntProperty); Assert.AreEqual(null, someTestingObject.StringProperty); Assert.AreEqual(null, someTestingObject.DateTimeNullableProperty); Assert.AreEqual(null, someTestingObject.BooleanNullableStatusProperty); }
public void WhenCollectionContainsInvalidStringProperty_ShouldReturnTheObjectWithItsStringPropertySetToTheDefaultValue(string invalidStringPropertyName) { //Arange IApiTypeConverter apiTypeConverterStub = MockRepository.GenerateStub <IApiTypeConverter>(); IObjectConverter objectConverter = new Converters.ObjectConverter(apiTypeConverterStub); ICollection <KeyValuePair <string, string> > collection = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(invalidStringPropertyName, "some value") }; //Act SomeTestingObject someTestingObject = objectConverter.ToObject <SomeTestingObject>(collection); //Assert Assert.IsNull(someTestingObject.StringProperty); }
public void WhenCollectionContainsValidStringProperty_ShouldSetTheObjectStringPropertyValueToTheCollectionStringPropertyValue(string stringPropertyName) { //Arange IApiTypeConverter apiTypeConverterStub = MockRepository.GenerateStub <IApiTypeConverter>(); IObjectConverter objectConverter = new Converters.ObjectConverter(apiTypeConverterStub); ICollection <KeyValuePair <string, string> > collection = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(stringPropertyName, "some value") }; //Act SomeTestingObject someTestingObject = objectConverter.ToObject <SomeTestingObject>(collection); //Assert Assert.AreEqual("some value", someTestingObject.StringProperty); }