Exemple #1
0
        public void TestThatTranslationsMapsTranslationsIntoProxyWhenCreateHasBeenCalledAndMapDataHasNotBeenCalled()
        {
            IStorageTypeProxy sut = CreateSut();

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

            Guid            storageTypeIdentifier = Guid.NewGuid();
            MySqlDataReader dataReader            = CreateMySqlDataReader(storageTypeIdentifier);

            IEnumerable <TranslationProxy> translationProxyCollection = _fixture.CreateMany <TranslationProxy>().ToList();
            IFoodWasteDataProvider         dataProvider = CreateFoodWasteDataProvider(translationProxyCollection);

            IStorageTypeProxy result = sut.Create(dataReader, dataProvider, "StorageTypeIdentifier", "SortOrder", "Temperature", "TemperatureRangeStartValue", "TemperatureRangeEndValue", "Creatable", "Editable", "Deletable");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Translation, Is.Null);
            Assert.That(result.Translations, Is.Not.Null);
            Assert.That(result.Translations, Is.Not.Empty);
            Assert.That(result.Translations, Is.EqualTo(translationProxyCollection));

            dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Once());

            IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT t.TranslationIdentifier AS TranslationIdentifier,t.OfIdentifier AS OfIdentifier,ti.TranslationInfoIdentifier AS InfoIdentifier,ti.CultureName AS CultureName,t.Value AS Value FROM Translations AS t INNER JOIN TranslationInfos AS ti ON ti.TranslationInfoIdentifier=t.InfoIdentifier WHERE t.OfIdentifier=@ofIdentifier ORDER BY ti.CultureName")
                                                   .AddCharDataParameter("@ofIdentifier", storageTypeIdentifier)
                                                   .Build();

            dataProvider.AssertWasCalled(m => m.GetCollection <TranslationProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once());
        }
Exemple #2
0
        public void TestThatTranslationsMapsTranslationsAndDataSourceStatementsIntoProxyWhenMapDataHasBeenCalledAndMapRelationsHasNotBeenCalled()
        {
            IDataProviderProxy sut = CreateSut();

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

            Guid            dataSourceStatementIdentifier = Guid.NewGuid();
            MySqlDataReader dataReader = CreateMySqlDataReader(Guid.NewGuid(), _fixture.Create <string>(), _fixture.Create <bool>(), dataSourceStatementIdentifier);

            IEnumerable <TranslationProxy> translationProxyCollection = BuildTranslationProxyCollection(dataSourceStatementIdentifier);
            IFoodWasteDataProvider         dataProvider = CreateFoodWasteDataProvider(translationProxyCollection);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut.Translation, Is.Null);
            Assert.That(sut.Translations, Is.Not.Null);
            Assert.That(sut.Translations, Is.Not.Empty);
            Assert.That(sut.Translations, Is.EqualTo(translationProxyCollection));
            Assert.That(sut.DataSourceStatement, Is.Null);
            Assert.That(sut.DataSourceStatements, Is.Not.Null);
            Assert.That(sut.DataSourceStatements, Is.Not.Empty);
            Assert.That(sut.DataSourceStatements, Is.EqualTo(translationProxyCollection));

            dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Times(1));

            IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT t.TranslationIdentifier AS TranslationIdentifier,t.OfIdentifier AS OfIdentifier,ti.TranslationInfoIdentifier AS InfoIdentifier,ti.CultureName AS CultureName,t.Value AS Value FROM Translations AS t INNER JOIN TranslationInfos AS ti ON ti.TranslationInfoIdentifier=t.InfoIdentifier WHERE t.OfIdentifier=@ofIdentifier ORDER BY ti.CultureName")
                                                   .AddCharDataParameter("@ofIdentifier", dataSourceStatementIdentifier)
                                                   .Build();

            dataProvider.AssertWasCalled(m => m.GetCollection <TranslationProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once());
        }
        public void TestThatMapRelationsMapsBodyTranslationsIntoProxy(bool withBodyTranslation)
        {
            Guid subjectTranslationIdentifier = Guid.NewGuid();
            Guid?bodyTranslationIdentifier    = withBodyTranslation ? Guid.NewGuid() : (Guid?)null;

            IStaticTextProxy sut = CreateSut(Guid.NewGuid(), _fixture.Create <StaticTextType>(), subjectTranslationIdentifier, bodyTranslationIdentifier);

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

            List <TranslationProxy> translationProxyCollection = new List <TranslationProxy>(BuildTranslationProxyCollection(subjectTranslationIdentifier));

            if (bodyTranslationIdentifier.HasValue)
            {
                translationProxyCollection.AddRange(BuildTranslationProxyCollection(bodyTranslationIdentifier.Value));
            }
            IFoodWasteDataProvider dataProvider = CreateFoodWasteDataProvider(translationProxyCollection);

            sut.MapRelations(dataProvider);

            Assert.That(sut.Translation, Is.Null);
            Assert.That(sut.Translations, Is.Not.Null);
            Assert.That(sut.Translations, Is.Not.Empty);
            Assert.That(sut.Translations, Is.EqualTo(translationProxyCollection));
            Assert.That(sut.BodyTranslation, Is.Null);
            Assert.That(sut.BodyTranslations, Is.Not.Null);
            if (bodyTranslationIdentifier.HasValue)
            {
                Assert.That(sut.BodyTranslations, Is.Not.Empty);
                foreach (TranslationProxy translationProxy in translationProxyCollection.Where(m => m.TranslationOfIdentifier == bodyTranslationIdentifier.Value))
                {
                    Assert.That(sut.BodyTranslations.Contains(translationProxy), Is.True);
                }
            }
            else
            {
                Assert.That(sut.BodyTranslations, Is.Empty);
            }

            dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Times(1 + Convert.ToInt32(bodyTranslationIdentifier.HasValue)));
            dataProvider.AssertWasCalled(m => m.GetCollection <TranslationProxy>(Arg <MySqlCommand> .Is.NotNull), opt => opt.Repeat.Times(1 + Convert.ToInt32(bodyTranslationIdentifier.HasValue)));

            if (bodyTranslationIdentifier.HasValue == false)
            {
                return;
            }
            MySqlCommand cmd = (MySqlCommand)dataProvider.GetArgumentsForCallsMadeOn(m => m.GetCollection <TranslationProxy>(Arg <MySqlCommand> .Is.NotNull))
                               .Last()
                               .ElementAt(0);

            new DbCommandTestBuilder("SELECT t.TranslationIdentifier AS TranslationIdentifier,t.OfIdentifier AS OfIdentifier,ti.TranslationInfoIdentifier AS InfoIdentifier,ti.CultureName AS CultureName,t.Value AS Value FROM Translations AS t INNER JOIN TranslationInfos AS ti ON ti.TranslationInfoIdentifier=t.InfoIdentifier WHERE t.OfIdentifier=@ofIdentifier ORDER BY ti.CultureName")
            .AddCharDataParameter("@ofIdentifier", bodyTranslationIdentifier.Value)
            .Build()
            .Run(cmd);
        }
Exemple #4
0
        public void TestThatMapDataMapsDataIntoProxy(bool isPrimary)
        {
            IFoodItemGroupProxy sut = CreateSut();

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

            Guid            foodItemGroupIdentifier = Guid.NewGuid();
            MySqlDataReader dataReader = CreateMySqlDataReader(foodItemGroupIdentifier, isPrimary);

            Guid                   foodItemIdentifier  = Guid.NewGuid();
            FoodItemProxy          foodItemProxy       = BuildFoodItemProxy(identifier: foodItemIdentifier);
            Guid                   foodGroupIdentifier = Guid.NewGuid();
            FoodGroupProxy         foodGroupProxy      = BuildFoodGroupProxy(identifier: foodGroupIdentifier);
            IFoodWasteDataProvider dataProvider        = CreateFoodWasteDataProvider(foodItemProxy, foodGroupProxy);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut.Identifier, Is.Not.Null);
            Assert.That(sut.Identifier, Is.EqualTo(foodItemGroupIdentifier));
            Assert.That(sut.FoodItem, Is.Not.Null);
            Assert.That(sut.FoodItem, Is.EqualTo(foodItemProxy));
            Assert.That(sut.FoodItemIdentifier, Is.Not.Null);
            Assert.That(sut.FoodItemIdentifier, Is.EqualTo(foodItemIdentifier));
            Assert.That(sut.FoodGroup, Is.Not.Null);
            Assert.That(sut.FoodGroup, Is.EqualTo(foodGroupProxy));
            Assert.That(sut.FoodGroupIdentifier, Is.Not.Null);
            Assert.That(sut.FoodGroupIdentifier, Is.EqualTo(foodGroupIdentifier));
            Assert.That(sut.IsPrimary, Is.EqualTo(isPrimary));

            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("FoodItemGroupIdentifier")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("IsPrimary")), opt => opt.Repeat.Once());

            dataProvider.AssertWasNotCalled(m => m.Clone());
            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <IFoodItemProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 2 &&
                                                                     e[0] == "FoodItemIdentifier" &&
                                                                     e[1] == "FoodItemIsActive")),
                                         opt => opt.Repeat.Once());
            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <IFoodGroupProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 3 &&
                                                                     e[0] == "FoodGroupIdentifier" &&
                                                                     e[1] == "FoodGroupParentIdentifier" &&
                                                                     e[2] == "FoodGroupIsActive")),
                                         opt => opt.Repeat.Once());
        }
Exemple #5
0
        public void TestThatMapRelationsCallsCloneOnDataProviderOneTime()
        {
            IStorageTypeProxy sut = CreateSut(Guid.NewGuid());

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

            IFoodWasteDataProvider dataProvider = CreateFoodWasteDataProvider();

            sut.MapRelations(dataProvider);

            dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Once());
        }
        public void TestThatMapDataMapsDataIntoProxy()
        {
            IForeignKeyProxy sut = CreateSut();

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

            Guid            foreignKeyIdentifier    = Guid.NewGuid();
            Guid            foreignKeyForIdentifier = Guid.NewGuid();
            Type            foreignKeyForType       = typeof(DataProvider);
            string          foreignKeyValue         = _fixture.Create <string>();
            MySqlDataReader dataReader = CreateMySqlDataReader(foreignKeyIdentifier, foreignKeyForIdentifier, foreignKeyForType, foreignKeyValue);

            IDataProviderProxy     dataProviderProxy = BuildDataProviderProxy();
            IFoodWasteDataProvider dataProvider      = CreateFoodWasteDataProvider(dataProviderProxy);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Identifier, Is.Not.Null);
            Assert.That(sut.Identifier, Is.EqualTo(foreignKeyIdentifier));
            Assert.That(sut.DataProvider, Is.Not.Null);
            Assert.That(sut.DataProvider, Is.EqualTo(dataProviderProxy));
            Assert.That(sut.ForeignKeyForIdentifier, Is.EqualTo(foreignKeyForIdentifier));
            Assert.That(sut.ForeignKeyForTypes, Is.Not.Null);
            Assert.That(sut.ForeignKeyForTypes, Is.Not.Empty);
            Assert.That(sut.ForeignKeyForTypes.Count(), Is.EqualTo(4));
            Assert.That(sut.ForeignKeyForTypes.Contains(typeof(IDomainObject)), Is.True);
            Assert.That(sut.ForeignKeyForTypes.Contains(typeof(IIdentifiable)), Is.True);
            Assert.That(sut.ForeignKeyForTypes.Contains(typeof(ITranslatable)), Is.True);
            Assert.That(sut.ForeignKeyForTypes.Contains(typeof(IDataProvider)), Is.True);
            Assert.That(sut.ForeignKeyValue, Is.Not.Null);
            Assert.That(sut.ForeignKeyValue, Is.Not.Empty);
            Assert.That(sut.ForeignKeyValue, Is.EqualTo(foreignKeyValue));

            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("ForeignKeyIdentifier")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("ForeignKeyForIdentifier")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("ForeignKeyForTypes")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("ForeignKeyValue")), opt => opt.Repeat.Once());

            dataProvider.AssertWasNotCalled(m => m.Clone());

            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <IDataProviderProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 4 &&
                                                                     e[0] == "DataProviderIdentifier" &&
                                                                     e[1] == "DataProviderName" &&
                                                                     e[2] == "HandlesPayments" &&
                                                                     e[3] == "DataSourceStatementIdentifier")),
                                         opt => opt.Repeat.Once());
        }
        public void TestThatHouseholdMemberGetByMailAddressCallsGetCollectionOnFoodWasteDataProvider()
        {
            IHouseholdDataRepository sut = CreateSut();

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

            string mailAddress = _fixture.Create <string>();

            sut.HouseholdMemberGetByMailAddress(mailAddress);

            IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT HouseholdMemberIdentifier,MailAddress,Membership,MembershipExpireTime,ActivationCode,ActivationTime,PrivacyPolicyAcceptedTime,CreationTime FROM HouseholdMembers WHERE MailAddress=@mailAddress")
                                                   .AddVarCharDataParameter("@mailAddress", mailAddress, 128)
                                                   .Build();

            _foodWasteDataProviderMock.AssertWasCalled(m => m.GetCollection <HouseholdMemberProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once());
        }
Exemple #8
0
        public void TestThatMapRelationsCallsGetCollectionOnDataProviderToGetTranslations()
        {
            Guid storageTypeIdentifier = Guid.NewGuid();

            IStorageTypeProxy sut = CreateSut(storageTypeIdentifier);

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

            IFoodWasteDataProvider dataProvider = CreateFoodWasteDataProvider();

            sut.MapRelations(dataProvider);

            IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT t.TranslationIdentifier AS TranslationIdentifier,t.OfIdentifier AS OfIdentifier,ti.TranslationInfoIdentifier AS InfoIdentifier,ti.CultureName AS CultureName,t.Value AS Value FROM Translations AS t INNER JOIN TranslationInfos AS ti ON ti.TranslationInfoIdentifier=t.InfoIdentifier WHERE t.OfIdentifier=@ofIdentifier ORDER BY ti.CultureName")
                                                   .AddCharDataParameter("@ofIdentifier", storageTypeIdentifier)
                                                   .Build();

            dataProvider.AssertWasCalled(m => m.GetCollection <TranslationProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once());
        }
        public void TestThatMapDataMapsDataIntoProxy()
        {
            ITranslationProxy sut = CreateSut();

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

            Guid            identifier = Guid.NewGuid();
            Guid            translationOfIdentifier = Guid.NewGuid();
            string          value      = _fixture.Create <string>();
            MySqlDataReader dataReader = CreateMySqlDataReader(identifier, translationOfIdentifier, value);

            ITranslationInfoProxy  translationInfoProxy = BuildTranslationInfoProxy(Guid.NewGuid());
            IFoodWasteDataProvider dataProvider         = CreateFoodWasteDataProvider(translationInfoProxy);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut.Identifier, Is.Not.Null);
            Assert.That(sut.Identifier, Is.EqualTo(identifier));
            Assert.That(sut.TranslationOfIdentifier, Is.EqualTo(translationOfIdentifier));
            Assert.That(sut.TranslationInfo, Is.Not.Null);
            Assert.That(sut.TranslationInfo, Is.EqualTo(translationInfoProxy));
            Assert.That(sut.Value, Is.Not.Null);
            Assert.That(sut.Value, Is.Not.Empty);
            Assert.That(sut.Value, Is.EqualTo(value));

            dataReader.AssertWasCalled(m => m.GetString("TranslationIdentifier"), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString("OfIdentifier"), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString("Value"), opt => opt.Repeat.Once());

            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <ITranslationInfoProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 2 &&
                                                                     e[0] == "InfoIdentifier" &&
                                                                     e[1] == "CultureName")),
                                         opt => opt.Repeat.Once());
        }
Exemple #10
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());
        }
Exemple #11
0
        public void TestThatMapDataMapsDataIntoProxy()
        {
            IMemberOfHouseholdProxy sut = CreateSut();

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

            Guid            memberOfHouseholdIdentifier = Guid.NewGuid();
            Guid            householdMemberIdentifier   = Guid.NewGuid();
            Guid            householdIdentifier         = Guid.NewGuid();
            DateTime        creationTime = DateTime.Now;
            MySqlDataReader dataReader   = CreateMySqlDataReader(memberOfHouseholdIdentifier, householdMemberIdentifier, householdIdentifier, creationTime);

            HouseholdMemberProxy   householdMemberProxy = BuildHouseholdMemberProxy(identifier: householdMemberIdentifier);
            HouseholdProxy         householdProxy       = BuildHouseholdProxy(identifier: householdIdentifier);
            IFoodWasteDataProvider dataProvider         = CreateFoodWasteDataProvider(householdMemberProxy, householdProxy);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Identifier, Is.Not.Null);
            Assert.That(sut.Identifier, Is.EqualTo(memberOfHouseholdIdentifier));
            Assert.That(sut.HouseholdMember, Is.Not.Null);
            Assert.That(sut.HouseholdMember, Is.EqualTo(householdMemberProxy));
            Assert.That(sut.HouseholdMemberIdentifier, Is.Not.Null);
            Assert.That(sut.HouseholdMemberIdentifier, Is.EqualTo(householdMemberIdentifier));
            Assert.That(sut.Household, Is.Not.Null);
            Assert.That(sut.Household, Is.EqualTo(householdProxy));
            Assert.That(sut.HouseholdIdentifier, Is.Not.Null);
            Assert.That(sut.HouseholdIdentifier, Is.EqualTo(householdIdentifier));
            Assert.That(sut.CreationTime, Is.EqualTo(creationTime).Within(1).Milliseconds);

            dataReader.AssertWasCalled(m => m.GetString("MemberOfHouseholdIdentifier"), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetMySqlDateTime("CreationTime"), opt => opt.Repeat.Once());

            dataProvider.AssertWasNotCalled(m => m.Clone());

            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <IHouseholdMemberProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 8 &&
                                                                     e[0] == "HouseholdMemberIdentifier" &&
                                                                     e[1] == "HouseholdMemberMailAddress" &&
                                                                     e[2] == "HouseholdMemberMembership" &&
                                                                     e[3] == "HouseholdMemberMembershipExpireTime" &&
                                                                     e[4] == "HouseholdMemberActivationCode" &&
                                                                     e[5] == "HouseholdMemberActivationTime" &&
                                                                     e[6] == "HouseholdMemberPrivacyPolicyAcceptedTime" &&
                                                                     e[7] == "HouseholdMemberCreationTime")),
                                         opt => opt.Repeat.Once());
            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());
        }
Exemple #12
0
        public void TestThatMapDataMapsDataIntoProxy(StakeholderType stakeholderType, bool hasPaymentReceipt)
        {
            IPaymentProxy sut = CreateSut();

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

            Guid     paymentIdentifier      = Guid.NewGuid();
            Guid     stakeholderIdentifier  = Guid.NewGuid();
            Guid     dataProviderIdentifier = Guid.NewGuid();
            DateTime paymentTime            = DateTime.Now.AddDays(_random.Next(1, 7) * -1).AddMinutes(_random.Next(120, 240));
            string   paymentReference       = _fixture.Create <string>();

            byte[]          paymentReceipt = hasPaymentReceipt ? _fixture.CreateMany <byte>(_random.Next(1024, 4096)).ToArray() : null;
            DateTime        creationTime   = DateTime.Now;
            MySqlDataReader dataReader     = CreateMySqlDataReader(paymentIdentifier, stakeholderIdentifier, stakeholderType, dataProviderIdentifier, paymentTime, paymentReference, paymentReceipt, creationTime);

            DataProviderProxy      dataProviderProxy    = BuildDataProviderProxy();
            HouseholdMemberProxy   householdMemberProxy = BuildHouseholdMemberProxy();
            IFoodWasteDataProvider dataProvider         = CreateFoodWasteDataProvider(dataProviderProxy, householdMemberProxy);

            sut.MapData(dataReader, dataProvider);

            Assert.That(sut.Identifier, Is.Not.Null);
            Assert.That(sut.Identifier, Is.EqualTo(paymentIdentifier));
            Assert.That(sut.Stakeholder, Is.Not.Null);
            Assert.That(sut.Stakeholder, Is.EqualTo(householdMemberProxy));
            Assert.That(sut.DataProvider, Is.Not.Null);
            Assert.That(sut.DataProvider, Is.EqualTo(dataProviderProxy));
            Assert.That(sut.PaymentTime, Is.EqualTo(paymentTime).Within(1).Milliseconds);
            Assert.That(sut.PaymentReference, Is.Not.Null);
            Assert.That(sut.PaymentReference, Is.Not.Empty);
            Assert.That(sut.PaymentReference, Is.EqualTo(paymentReference));
            if (paymentReceipt != null)
            {
                Assert.That(sut.PaymentReceipt, Is.Not.Null);
                Assert.That(sut.PaymentReceipt, Is.Not.Empty);
                Assert.That(sut.PaymentReceipt, Is.EqualTo(paymentReceipt));
            }
            else
            {
                Assert.That(sut.PaymentReceipt, Is.Null);
            }
            Assert.That(sut.CreationTime, Is.EqualTo(creationTime).Within(1).Milliseconds);

            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("PaymentIdentifier")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("StakeholderType")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetMySqlDateTime(Arg <string> .Is.Equal("PaymentTime")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("PaymentReference")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("PaymentReceipt")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(6)), opt => opt.Repeat.Once());
            if (paymentReceipt != null)
            {
                dataReader.AssertWasCalled(m => m.GetTextReader(Arg <int> .Is.Equal(6)), opt => opt.Repeat.Once());
            }
            else
            {
                dataReader.AssertWasNotCalled(m => m.GetTextReader(Arg <int> .Is.Equal(6)));
            }
            dataReader.AssertWasCalled(m => m.GetMySqlDateTime(Arg <string> .Is.Equal("CreationTime")), opt => opt.Repeat.Once());

            dataProvider.AssertWasNotCalled(m => m.Clone());

            switch (stakeholderType)
            {
            case StakeholderType.HouseholdMember:
                dataProvider.AssertWasCalled(m => m.Create(
                                                 Arg <IHouseholdMemberProxy> .Is.TypeOf,
                                                 Arg <MySqlDataReader> .Is.Equal(dataReader),
                                                 Arg <string[]> .Matches(e => e != null && e.Length == 8 &&
                                                                         e[0] == "StakeholderIdentifier" &&
                                                                         e[1] == "HouseholdMemberMailAddress" &&
                                                                         e[2] == "HouseholdMemberMembership" &&
                                                                         e[3] == "HouseholdMemberMembershipExpireTime" &&
                                                                         e[4] == "HouseholdMemberActivationCode" &&
                                                                         e[5] == "HouseholdMemberActivationTime" &&
                                                                         e[6] == "HouseholdMemberPrivacyPolicyAcceptedTime" &&
                                                                         e[7] == "HouseholdMemberCreationTime")),
                                             opt => opt.Repeat.Once());
                break;

            default:
                throw new NotSupportedException($"The stakeholderType '{stakeholderType}' is not supported.");
            }

            dataProvider.AssertWasCalled(m => m.Create(
                                             Arg <IDataProviderProxy> .Is.TypeOf,
                                             Arg <MySqlDataReader> .Is.Equal(dataReader),
                                             Arg <string[]> .Matches(e => e != null && e.Length == 4 &&
                                                                     e[0] == "DataProviderIdentifier" &&
                                                                     e[1] == "DataProviderName" &&
                                                                     e[2] == "DataProviderHandlesPayments" &&
                                                                     e[3] == "DataProviderDataSourceStatementIdentifier")),
                                         opt => opt.Repeat.Once());
        }