예제 #1
0
        public void TestThatCreateThrowsArgumentNullExceptionIfColumnNameCollectionIsNull()
        {
            IStorageProxy sut = CreateSut();

            Assert.That(sut, Is.Not.Null);

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Create(CreateMySqlDataReader(), CreateFoodWasteDataProvider(), null));

            TestHelper.AssertArgumentNullExceptionIsValid(result, "columnNameCollection");
        }
예제 #2
0
        public void TestThatCreateCreatesProxy(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);

            // ReSharper disable StringLiteralTypo
            IStorageProxy result = sut.Create(dataReader, dataProvider, "StorageIdentifier", "HouseholdIdentifier", "SortOrder", "StorageTypeIdentifier", "Descr", "Temperature", "CreationTime", "HouseholdName", "HouseholdDescr", "HouseholdCreationTime", "StorageTypeSortOrder", "StorageTypeTemperature", "StorageTypeTemperatureRangeStartValue", "StorageTypeTemperatureRangeEndValue", "StorageTypeCreatable", "StorageTypeEditable", "StorageTypeDeletable");

            // ReSharper restore StringLiteralTypo
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Identifier, Is.Not.Null);
            Assert.That(result.Identifier, Is.EqualTo(identifier));
            Assert.That(result.Household, Is.Not.Null);
            Assert.That(result.Household, Is.EqualTo(householdProxy));
            Assert.That(result.SortOrder, Is.EqualTo(sortOrder));
            Assert.That(result.StorageType, Is.Not.Null);
            Assert.That(result.StorageType, Is.EqualTo(storageTypeProxy));
            if (string.IsNullOrWhiteSpace(description) == false)
            {
                Assert.That(result.Description, Is.Not.Null);
                Assert.That(result.Description, Is.Not.Empty);
                Assert.That(result.Description, Is.EqualTo(description));
            }
            else
            {
                Assert.That(result.Description, Is.Null);
            }
            Assert.That(result.Temperature, Is.EqualTo(temperature));
            Assert.That(result.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());
        }
예제 #3
0
        public void TestThatCreateThrowsArgumentNullExceptionIfDataProviderIsNull()
        {
            IStorageProxy sut = CreateSut();

            Assert.That(sut, Is.Not.Null);

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Create(CreateMySqlDataReader(), null, _fixture.Create <string>(), _fixture.Create <string>(), _fixture.Create <string>()));

            TestHelper.AssertArgumentNullExceptionIsValid(result, "dataProvider");
        }