public void TestThatMapDataMapsDataIntoProxy(bool hasDescription) { IStorageProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); Guid identifier = Guid.NewGuid(); Guid householdIdentifier = Guid.NewGuid(); int sortOrder = GetLegalSortOrder(); Guid storageTypeIdentifier = Guid.NewGuid(); string description = hasDescription ? _fixture.Create <string>() : null; IRange <int> temperatureRange = DomainObjectMockBuilder.BuildIntRange(); int temperature = GetLegalTemperature(temperatureRange); DateTime creationTime = DateTime.Now; MySqlDataReader dataReader = CreateMySqlDataReader(identifier, householdIdentifier, sortOrder, storageTypeIdentifier, description, temperature, creationTime); HouseholdProxy householdProxy = BuildHouseholdProxy(); StorageTypeProxy storageTypeProxy = BuildStorageTypeProxy(temperatureRange: temperatureRange); IFoodWasteDataProvider dataProvider = CreateFoodWasteDataProvider(householdProxy, storageTypeProxy); sut.MapData(dataReader, dataProvider); Assert.That(sut.Identifier, Is.Not.Null); Assert.That(sut.Identifier, Is.EqualTo(identifier)); Assert.That(sut.Household, Is.Not.Null); Assert.That(sut.Household, Is.EqualTo(householdProxy)); Assert.That(sut.SortOrder, Is.EqualTo(sortOrder)); Assert.That(sut.StorageType, Is.Not.Null); Assert.That(sut.StorageType, Is.EqualTo(storageTypeProxy)); if (string.IsNullOrWhiteSpace(description) == false) { Assert.That(sut.Description, Is.Not.Null); Assert.That(sut.Description, Is.Not.Empty); Assert.That(sut.Description, Is.EqualTo(description)); } else { Assert.That(sut.Description, Is.Null); } Assert.That(sut.Temperature, Is.EqualTo(temperature)); Assert.That(sut.CreationTime, Is.EqualTo(creationTime).Within(1).Milliseconds); dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("StorageIdentifier")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetInt16(Arg <string> .Is.Equal("SortOrder")), opt => opt.Repeat.Once()); // ReSharper disable StringLiteralTypo dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("Descr")), opt => opt.Repeat.Once()); // ReSharper restore StringLiteralTypo dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(4)), opt => opt.Repeat.Once()); if (string.IsNullOrWhiteSpace(description) == false) { dataReader.AssertWasCalled(m => m.GetString(Arg <int> .Is.Equal(4)), opt => opt.Repeat.Once()); } else { dataReader.AssertWasNotCalled(m => m.GetString(Arg <int> .Is.Equal(4))); } dataReader.AssertWasCalled(m => m.GetInt16(Arg <string> .Is.Equal("Temperature")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetMySqlDateTime(Arg <string> .Is.Equal("CreationTime")), opt => opt.Repeat.Once()); dataProvider.AssertWasNotCalled(m => m.Clone()); dataProvider.AssertWasCalled(m => m.Create( Arg <IHouseholdProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 4 && e[0] == "HouseholdIdentifier" && e[1] == "HouseholdName" && // ReSharper disable StringLiteralTypo e[2] == "HouseholdDescr" && // ReSharper restore StringLiteralTypo e[3] == "HouseholdCreationTime")), opt => opt.Repeat.Once()); dataProvider.AssertWasCalled(m => m.Create( Arg <IStorageTypeProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 8 && e[0] == "StorageTypeIdentifier" && e[1] == "StorageTypeSortOrder" && e[2] == "StorageTypeTemperature" && e[3] == "StorageTypeTemperatureRangeStartValue" && e[4] == "StorageTypeTemperatureRangeEndValue" && e[5] == "StorageTypeCreatable" && e[6] == "StorageTypeEditable" && e[7] == "StorageTypeDeletable")), opt => opt.Repeat.Once()); }
public void TestThatMapDataThrowsArgumentNullExceptionIfDataProviderIsNull() { IStorageProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.MapData(CreateMySqlDataReader(), null)); TestHelper.AssertArgumentNullExceptionIsValid(result, "dataProvider"); }