public void TestThatDeleteRelationsThrowsArgumentNullExceptionIfDataProviderIsNull()
        {
            ITranslationProxy sut = CreateSut();

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

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.DeleteRelations(null));

            TestHelper.AssertArgumentNullExceptionIsValid(result, "dataProvider");
        }
        public void TestThatMapDataThrowsArgumentNullExceptionIfDataReaderIsNull()
        {
            ITranslationProxy sut = CreateSut();

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

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

            TestHelper.AssertArgumentNullExceptionIsValid(result, "dataReader");
        }
Example #3
0
        internal ValidationResult(Guid validationContextId, ITranslationProxy translationProxy, IExecutionOptions executionOptions, T model = null, IErrorsCollection errorsCollection = null)
        {
            TranslationProxy = translationProxy ?? throw new ArgumentNullException(nameof(translationProxy));
            ErrorsCollection = errorsCollection ?? Errors.ErrorsCollection.Empty;
            ExecutionOptions = executionOptions ?? throw new ArgumentNullException(nameof(executionOptions));

            ValidationDate      = DateTime.UtcNow;
            ValidationContextId = validationContextId;

            Model = model;
        }
        public void TestThatConstructorInitializeTranslation()
        {
            ITranslationProxy sut = CreateSut();

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Identifier, Is.Null);
            Assert.That(sut.Identifier.HasValue, Is.False);
            Assert.That(sut.TranslationOfIdentifier, Is.EqualTo(Guid.Empty));
            Assert.That(sut.TranslationInfo, Is.Null);
            Assert.That(sut.Value, Is.Null);
        }
        public void TestThatDeleteRelationsThrowsIntranetRepositoryExceptionWhenIdentifierIsNull()
        {
            ITranslationProxy sut = CreateSut();

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Identifier, Is.Null);
            Assert.That(sut.Identifier.HasValue, Is.False);

            IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.DeleteRelations(CreateFoodWasteDataProvider()));

            TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier");
        }
        public void TestThatCreateDeleteCommandReturnsSqlCommandForDelete()
        {
            Guid identifier = Guid.NewGuid();

            ITranslationProxy sut = CreateSut(identifier);

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

            new DbCommandTestBuilder("DELETE FROM Translations WHERE TranslationIdentifier=@translationIdentifier")
            .AddCharDataParameter("@translationIdentifier", identifier)
            .Build()
            .Run(sut.CreateDeleteCommand());
        }
        public void TestThatCreateGetCommandReturnsSqlCommand()
        {
            Guid identifier = Guid.NewGuid();

            ITranslationProxy sut = CreateSut(identifier);

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

            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.TranslationIdentifier=@translationIdentifier")
            .AddCharDataParameter("@translationIdentifier", identifier)
            .Build()
            .Run(sut.CreateGetCommand());
        }
        public void TestThatUniqueIdGetterGetsUniqueIdentificationForTranslationProxy()
        {
            Guid identifier = Guid.NewGuid();

            ITranslationProxy sut = CreateSut(identifier);

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

            string uniqueId = sut.UniqueId;

            Assert.That(uniqueId, Is.Not.Null);
            Assert.That(uniqueId, Is.Not.Empty);
            Assert.That(uniqueId, Is.EqualTo(identifier.ToString("D").ToUpper()));
        }
        public void TestThatUniqueIdGetterThrowsIntranetRepositoryExceptionWhenTranslationHasNoIdentifier()
        {
            ITranslationProxy sut = CreateSut();

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

            sut.Identifier = null;

            // ReSharper disable UnusedVariable
            IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => { var uniqueId = sut.UniqueId; });

            // ReSharper restore UnusedVariable

            TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier");
        }
        public void TestThatCreateUpdateCommandReturnsSqlCommandForUpdate()
        {
            Guid identifier = Guid.NewGuid();
            Guid translationOfIdentifier               = Guid.NewGuid();
            Guid translationInfoIdentifier             = Guid.NewGuid();
            ITranslationInfoProxy translationInfoProxy = BuildTranslationInfoProxy(translationInfoIdentifier);
            string value = _fixture.Create <string>();

            ITranslationProxy sut = CreateSut(identifier, translationOfIdentifier, translationInfoProxy, value);

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

            new DbCommandTestBuilder("UPDATE Translations SET OfIdentifier=@ofIdentifier,InfoIdentifier=@translationInfoIdentifier,Value=@value WHERE TranslationIdentifier=@translationIdentifier")
            .AddCharDataParameter("@translationIdentifier", identifier)
            .AddCharDataParameter("@ofIdentifier", translationOfIdentifier)
            .AddCharDataParameter("@translationInfoIdentifier", translationInfoIdentifier)
            .AddVarCharDataParameter("@value", value, 4096)
            .Build()
            .Run(sut.CreateUpdateCommand());
        }
        public void TestThatCreateInsertCommandReturnsSqlCommandForInsert()
        {
            Guid identifier = Guid.NewGuid();
            Guid translationOfIdentifier               = Guid.NewGuid();
            Guid translationInfoIdentifier             = Guid.NewGuid();
            ITranslationInfoProxy translationInfoProxy = BuildTranslationInfoProxy(translationInfoIdentifier);
            string value = _fixture.Create <string>();

            ITranslationProxy sut = CreateSut(identifier, translationOfIdentifier, translationInfoProxy, value);

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

            new DbCommandTestBuilder("INSERT INTO Translations (TranslationIdentifier,OfIdentifier,InfoIdentifier,Value) VALUES(@translationIdentifier,@ofIdentifier,@translationInfoIdentifier,@value)")
            .AddCharDataParameter("@translationIdentifier", identifier)
            .AddCharDataParameter("@ofIdentifier", translationOfIdentifier)
            .AddCharDataParameter("@translationInfoIdentifier", translationInfoIdentifier)
            .AddVarCharDataParameter("@value", value, 4096)
            .Build()
            .Run(sut.CreateInsertCommand());
        }
        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());
        }
        /// <summary>
        /// Creates an object mapper which can map objects in the food waste domain.
        /// </summary>
        static FoodWasteObjectMapper()
        {
            var mapperConfiguration = new MapperConfiguration(config =>
            {
                config.CreateMap <IHousehold, HouseholdIdentificationView>()
                .ForMember(m => m.HouseholdIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Name));

                config.CreateMap <IHousehold, HouseholdView>()
                .ForMember(m => m.HouseholdIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Name))
                .ForMember(m => m.Description, opt => opt.MapFrom(s => s.Description))
                .ForMember(m => m.CreationTime, opt => opt.MapFrom(s => s.CreationTime))
                .ForMember(m => m.HouseholdMembers, opt => opt.MapFrom(s => s.HouseholdMembers))
                .ForMember(m => m.Storages, opt => opt.MapFrom(s => s.Storages));

                config.CreateMap <IHousehold, IHouseholdProxy>()
                .ConstructUsing(m =>
                {
                    IHouseholdProxy householdProxy = m as IHouseholdProxy;
                    if (householdProxy != null)
                    {
                        return(householdProxy);
                    }
                    householdProxy = new HouseholdProxy(m.Name, m.Description, m.CreationTime)
                    {
                        Identifier = m.Identifier
                    };
                    lock (SyncRoot)
                    {
                        _mappingHousehold = householdProxy;
                        try
                        {
                            if (_mappingHouseholdMember == null)
                            {
                                foreach (var householdMember in m.HouseholdMembers)
                                {
                                    if (householdMember is IHouseholdMemberProxy)
                                    {
                                        if (householdProxy.HouseholdMembers.Contains(householdMember))
                                        {
                                            continue;
                                        }
                                        householdProxy.HouseholdMemberAdd(householdMember);
                                        continue;
                                    }
                                    if (Mapper != null)
                                    {
                                        var householdMemberProxy = Mapper.Map <IHouseholdMember, IHouseholdMemberProxy>(householdMember);
                                        if (householdProxy.HouseholdMembers.Contains(householdMemberProxy))
                                        {
                                            continue;
                                        }
                                        householdProxy.HouseholdMemberAdd(householdMemberProxy);
                                    }
                                }
                            }
                            else if (householdProxy.HouseholdMembers.Contains(_mappingHouseholdMember) == false)
                            {
                                householdProxy.HouseholdMemberAdd(_mappingHouseholdMember);
                            }
                            foreach (IStorage storage in m.Storages.OrderBy(n => n.SortOrder).ThenByDescending(n => n.CreationTime))
                            {
                                if (storage is IStorageProxy)
                                {
                                    if (householdProxy.Storages.Contains(storage))
                                    {
                                        continue;
                                    }
                                    householdProxy.StorageAdd(storage);
                                    continue;
                                }
                                if (Mapper != null)
                                {
                                    IStorageProxy storageProxy = Mapper.Map <IStorage, IStorageProxy>(storage);
                                    if (householdProxy.Storages.Contains(storageProxy))
                                    {
                                        continue;
                                    }
                                    householdProxy.StorageAdd(storageProxy);
                                }
                            }
                        }
                        finally
                        {
                            _mappingHousehold = null;
                        }
                    }
                    return(householdProxy);
                });

                config.CreateMap <IStorageType, StorageTypeIdentificationView>()
                .ForMember(m => m.StorageTypeIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty));

                config.CreateMap <IStorageType, StorageTypeView>()
                .ForMember(m => m.StorageTypeIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.SortOrder, opt => opt.MapFrom(s => s.SortOrder))
                .ForMember(m => m.Temperature, opt => opt.MapFrom(s => s.Temperature))
                .ForMember(m => m.TemperatureRange, opt => opt.MapFrom(s => s.TemperatureRange))
                .ForMember(m => m.Creatable, opt => opt.MapFrom(s => s.Creatable))
                .ForMember(m => m.Editable, opt => opt.MapFrom(s => s.Editable))
                .ForMember(m => m.Deletable, opt => opt.MapFrom(s => s.Deletable));

                config.CreateMap <IStorageType, StorageTypeSystemView>()
                .ForMember(m => m.StorageTypeIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.SortOrder, opt => opt.MapFrom(s => s.SortOrder))
                .ForMember(m => m.Temperature, opt => opt.MapFrom(s => s.Temperature))
                .ForMember(m => m.TemperatureRange, opt => opt.MapFrom(s => s.TemperatureRange))
                .ForMember(m => m.Creatable, opt => opt.MapFrom(s => s.Creatable))
                .ForMember(m => m.Editable, opt => opt.MapFrom(s => s.Editable))
                .ForMember(m => m.Deletable, opt => opt.MapFrom(s => s.Deletable))
                .ForMember(m => m.Translations, opt => opt.MapFrom(s => s.Translations));

                config.CreateMap <IStorage, StorageIdentificationView>()
                .ForMember(m => m.StorageIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.SortOrder, opt => opt.MapFrom(s => s.SortOrder));

                config.CreateMap <IStorage, StorageView>()
                .ForMember(m => m.StorageIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Household, opt => opt.MapFrom(s => s.Household))
                .ForMember(m => m.SortOrder, opt => opt.MapFrom(s => s.SortOrder))
                .ForMember(m => m.StorageType, opt => opt.MapFrom(s => s.StorageType))
                .ForMember(m => m.Description, opt =>
                {
                    opt.Condition(s => string.IsNullOrWhiteSpace(s.Description) == false);
                    opt.MapFrom(s => s.Description);
                })
                .ForMember(m => m.Temperature, opt => opt.MapFrom(s => s.Temperature))
                .ForMember(m => m.CreationTime, opt => opt.MapFrom(s => s.CreationTime));

                config.CreateMap <IStorage, IStorageProxy>()
                .ConstructUsing(m =>
                {
                    IStorageProxy storageProxy = m as IStorageProxy;
                    if (storageProxy != null)
                    {
                        return(storageProxy);
                    }
                    IHouseholdProxy householdProxy;
                    lock (SyncRoot)
                    {
                        if (_mappingHousehold == null)
                        {
                            householdProxy = m.Household as IHouseholdProxy;
                            if (householdProxy == null && Mapper != null)
                            {
                                householdProxy = Mapper.Map <IHousehold, IHouseholdProxy>(m.Household);
                            }
                        }
                        else
                        {
                            householdProxy = _mappingHousehold;
                        }
                    }
                    IStorageTypeProxy storageTypeProxy = m.StorageType as IStorageTypeProxy;
                    if (storageTypeProxy == null && Mapper != null)
                    {
                        storageTypeProxy = Mapper.Map <IStorageType, IStorageTypeProxy>(m.StorageType);
                    }
                    return(new StorageProxy(householdProxy, m.SortOrder, storageTypeProxy, m.Temperature, m.CreationTime, m.Description));
                });

                config.CreateMap <IStorageType, IStorageTypeProxy>()
                .ConstructUsing(m =>
                {
                    IStorageTypeProxy storageTypeProxy = m as IStorageTypeProxy;
                    if (storageTypeProxy != null)
                    {
                        return(storageTypeProxy);
                    }
                    IRange <int> temperatureRange = new Range <int>(m.TemperatureRange.StartValue, m.TemperatureRange.EndValue);
                    storageTypeProxy = new StorageTypeProxy(m.SortOrder, m.Temperature, temperatureRange, m.Creatable, m.Editable, m.Deletable)
                    {
                        Identifier = m.Identifier
                    };
                    foreach (ITranslation translation in m.Translations)
                    {
                        if (translation is ITranslationProxy)
                        {
                            storageTypeProxy.TranslationAdd(translation);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            storageTypeProxy.TranslationAdd(Mapper.Map <ITranslation, ITranslationProxy>(translation));
                        }
                    }
                    return(storageTypeProxy);
                });

                config.CreateMap <IHouseholdMember, HouseholdMemberIdentificationView>()
                .ForMember(m => m.HouseholdMemberIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.MailAddress, opt => opt.MapFrom(s => s.MailAddress));

                config.CreateMap <IHouseholdMember, HouseholdMemberView>()
                .ForMember(m => m.HouseholdMemberIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.MailAddress, opt => opt.MapFrom(s => s.MailAddress))
                .ForMember(m => m.Membership, opt => opt.MapFrom(s => s.Membership))
                .ForMember(m => m.MembershipExpireTime, opt =>
                {
                    opt.Condition(s => s.MembershipHasExpired == false);
                    opt.MapFrom(s => s.MembershipExpireTime);
                })
                .ForMember(m => m.CanRenewMembership, opt => opt.MapFrom(s => s.CanRenewMembership))
                .ForMember(m => m.CanUpgradeMembership, opt => opt.MapFrom(s => s.CanUpgradeMembership))
                .ForMember(m => m.ActivationTime, opt => opt.MapFrom(s => s.ActivationTime))
                .ForMember(m => m.IsActivated, opt => opt.MapFrom(s => s.IsActivated))
                .ForMember(m => m.PrivacyPolicyAcceptedTime, opt => opt.MapFrom(s => s.PrivacyPolicyAcceptedTime))
                .ForMember(m => m.IsPrivacyPolicyAccepted, opt => opt.MapFrom(s => s.IsPrivacyPolicyAccepted))
                .ForMember(m => m.HasReachedHouseholdLimit, opt => opt.MapFrom(s => s.HasReachedHouseholdLimit))
                .ForMember(m => m.CanCreateStorage, opt => opt.MapFrom(s => s.CanCreateStorage))
                .ForMember(m => m.CanUpdateStorage, opt => opt.MapFrom(s => s.CanUpdateStorage))
                .ForMember(m => m.CanDeleteStorage, opt => opt.MapFrom(s => s.CanDeleteStorage))
                .ForMember(m => m.UpgradeableMemberships, opt => opt.MapFrom(s => s.UpgradeableMemberships))
                .ForMember(m => m.CreationTime, opt => opt.MapFrom(s => s.CreationTime))
                .ForMember(m => m.Households, opt => opt.MapFrom(s => s.Households))
                .ForMember(m => m.Payments, opt => opt.MapFrom(s => s.Payments));

                config.CreateMap <IHouseholdMember, IHouseholdMemberProxy>()
                .ConstructUsing(m =>
                {
                    IHouseholdMemberProxy householdMemberProxy = m as IHouseholdMemberProxy;
                    if (householdMemberProxy != null)
                    {
                        return(householdMemberProxy);
                    }
                    householdMemberProxy = new HouseholdMemberProxy(m.MailAddress, m.Membership, m.MembershipExpireTime, m.ActivationCode, m.CreationTime)
                    {
                        Identifier                = m.Identifier,
                        ActivationTime            = m.ActivationTime,
                        PrivacyPolicyAcceptedTime = m.PrivacyPolicyAcceptedTime
                    };
                    lock (SyncRoot)
                    {
                        _mappingHouseholdMember = householdMemberProxy;
                        try
                        {
                            if (_mappingHousehold == null)
                            {
                                foreach (var household in m.Households)
                                {
                                    if (household is IHouseholdProxy)
                                    {
                                        if (householdMemberProxy.Households.Contains(household))
                                        {
                                            continue;
                                        }
                                        householdMemberProxy.HouseholdAdd(household);
                                        continue;
                                    }
                                    if (Mapper != null)
                                    {
                                        var householdProxy = Mapper.Map <IHousehold, IHouseholdProxy>(household);
                                        if (householdMemberProxy.Households.Contains(householdProxy))
                                        {
                                            continue;
                                        }
                                        householdMemberProxy.HouseholdAdd(householdProxy);
                                    }
                                }
                            }
                            else if (householdMemberProxy.Households.Contains(_mappingHousehold) == false)
                            {
                                householdMemberProxy.HouseholdAdd(_mappingHousehold);
                            }
                            foreach (var payment in m.Payments)
                            {
                                if (payment is IPaymentProxy)
                                {
                                    householdMemberProxy.PaymentAdd(payment);
                                    continue;
                                }
                                if (Mapper != null)
                                {
                                    householdMemberProxy.PaymentAdd(Mapper.Map <IPayment, IPaymentProxy>(payment));
                                }
                            }
                        }
                        finally
                        {
                            _mappingHouseholdMember = null;
                        }
                    }
                    return(householdMemberProxy);
                });

                config.CreateMap <IPayment, PaymentView>()
                .ForMember(m => m.PaymentIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Stakeholder, opt => opt.MapFrom(s => s.Stakeholder))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider))
                .ForMember(m => m.PaymentTime, opt => opt.MapFrom(s => s.PaymentTime))
                .ForMember(m => m.PaymentReference, opt => opt.MapFrom(s => s.PaymentReference))
                .ForMember(m => m.PaymentReceipt, opt => opt.MapFrom(s => s.PaymentReceipt == null ? null : Convert.ToBase64String(s.PaymentReceipt.ToArray())))
                .ForMember(m => m.CreationTime, opt => opt.MapFrom(s => s.CreationTime));

                config.CreateMap <IPayment, IPaymentProxy>()
                .ConstructUsing(m =>
                {
                    IPaymentProxy paymentProxy = m as IPaymentProxy;
                    if (paymentProxy != null)
                    {
                        return(paymentProxy);
                    }
                    IStakeholder stakeholderProxy = null;
                    if (m.Stakeholder != null)
                    {
                        switch (m.Stakeholder.StakeholderType)
                        {
                        case StakeholderType.HouseholdMember:
                            lock (SyncRoot)
                            {
                                if (_mappingHouseholdMember != null)
                                {
                                    stakeholderProxy = _mappingHouseholdMember;
                                }
                                else if (m.Stakeholder is IHouseholdMember)
                                {
                                    stakeholderProxy = m.Stakeholder as IHouseholdMemberProxy;
                                    if (stakeholderProxy == null && Mapper != null)
                                    {
                                        stakeholderProxy = Mapper.Map <IHouseholdMember, IHouseholdMemberProxy>((IHouseholdMember)m.Stakeholder);
                                    }
                                }
                            }
                            break;
                        }
                    }
                    var dataProviderProxy = m.DataProvider as IDataProviderProxy;
                    if (dataProviderProxy == null && Mapper != null)
                    {
                        dataProviderProxy = Mapper.Map <IDataProvider, IDataProviderProxy>(m.DataProvider);
                    }
                    return(new PaymentProxy(stakeholderProxy, dataProviderProxy, m.PaymentTime, m.PaymentReference, m.PaymentReceipt, m.CreationTime)
                    {
                        Identifier = m.Identifier
                    });
                });

                config.CreateMap <IStakeholder, StakeholderView>()
                .ForMember(m => m.StakeholderIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.MailAddress, opt => opt.MapFrom(s => s.MailAddress));

                config.CreateMap <IFoodItemCollection, FoodItemCollectionView>()
                .ForMember(m => m.FoodItems, opt => opt.MapFrom <IEnumerable <IFoodItem> >(s => s))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider));

                config.CreateMap <IFoodItemCollection, FoodItemCollectionSystemView>()
                .ForMember(m => m.FoodItems, opt => opt.MapFrom(s => s))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider));

                config.CreateMap <IFoodItem, FoodItemIdentificationView>()
                .ForMember(m => m.FoodItemIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty));

                config.CreateMap <IFoodItem, FoodItemView>()
                .ForMember(m => m.FoodItemIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.PrimaryFoodGroup, opt => opt.MapFrom(s => s.PrimaryFoodGroup))
                .ForMember(m => m.IsActive, opt => opt.MapFrom(s => s.IsActive))
                .ForMember(m => m.FoodGroups, opt => opt.MapFrom(s => s.FoodGroups));

                config.CreateMap <IFoodItem, FoodItemSystemView>()
                .ForMember(m => m.FoodItemIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.PrimaryFoodGroup, opt => opt.MapFrom(s => s.PrimaryFoodGroup))
                .ForMember(m => m.IsActive, opt => opt.MapFrom(s => s.IsActive))
                .ForMember(m => m.FoodGroups, opt => opt.MapFrom(s => s.FoodGroups))
                .ForMember(m => m.Translations, opt => opt.MapFrom(s => s.Translations))
                .ForMember(m => m.ForeignKeys, opt => opt.MapFrom(s => s.ForeignKeys));

                config.CreateMap <IFoodItem, IFoodItemProxy>()
                .ConvertUsing(m =>
                {
                    IFoodItemProxy foodItemProxy = m as IFoodItemProxy;
                    if (foodItemProxy != null)
                    {
                        return(foodItemProxy);
                    }
                    IFoodGroupProxy primaryFoodGroup = null;
                    if (m.PrimaryFoodGroup != null)
                    {
                        primaryFoodGroup = m.PrimaryFoodGroup as IFoodGroupProxy;
                        if (primaryFoodGroup == null && Mapper != null)
                        {
                            primaryFoodGroup = Mapper.Map <IFoodGroup, IFoodGroupProxy>(m.PrimaryFoodGroup);
                        }
                    }
                    foodItemProxy = new FoodItemProxy(primaryFoodGroup)
                    {
                        Identifier = m.Identifier,
                        IsActive   = m.IsActive
                    };
                    foreach (var foodGroup in m.FoodGroups)
                    {
                        if (primaryFoodGroup != null && primaryFoodGroup.Identifier == foodGroup.Identifier)
                        {
                            continue;
                        }
                        if (foodGroup is IFoodGroupProxy)
                        {
                            foodItemProxy.FoodGroupAdd(foodGroup);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            foodItemProxy.FoodGroupAdd(Mapper.Map <IFoodGroup, IFoodGroupProxy>(foodGroup));
                        }
                    }
                    foreach (var translation in m.Translations)
                    {
                        if (translation is ITranslationProxy)
                        {
                            foodItemProxy.TranslationAdd(translation);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            foodItemProxy.TranslationAdd(Mapper.Map <ITranslation, ITranslationProxy>(translation));
                        }
                    }
                    foreach (var foreignKey in m.ForeignKeys)
                    {
                        if (foreignKey is IForeignKeyProxy)
                        {
                            foodItemProxy.ForeignKeyAdd(foreignKey);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            foodItemProxy.ForeignKeyAdd(Mapper.Map <IForeignKey, IForeignKeyProxy>(foreignKey));
                        }
                    }
                    return(foodItemProxy);
                });

                config.CreateMap <IFoodGroupCollection, FoodGroupTreeView>()
                .ForMember(m => m.FoodGroups, opt => opt.MapFrom(s => s))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider));

                config.CreateMap <IFoodGroupCollection, FoodGroupTreeSystemView>()
                .ForMember(m => m.FoodGroups, opt => opt.MapFrom(s => s))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider));

                config.CreateMap <IFoodGroup, FoodGroupIdentificationView>()
                .ForMember(m => m.FoodGroupIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty));

                config.CreateMap <IFoodGroup, FoodGroupView>()
                .ForMember(m => m.FoodGroupIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.IsActive, opt => opt.MapFrom(s => s.IsActive))
                .ForMember(m => m.Parent, opt =>
                {
                    opt.Condition(s => s.Parent != null);
                    opt.MapFrom(s => s.Parent);
                })
                .ForMember(m => m.Children, opt => opt.MapFrom(s => s.Children));

                config.CreateMap <IFoodGroup, FoodGroupSystemView>()
                .ForMember(m => m.FoodGroupIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Translation != null ? s.Translation.Value : string.Empty))
                .ForMember(m => m.IsActive, opt => opt.MapFrom(s => s.IsActive))
                .ForMember(m => m.Parent, opt =>
                {
                    opt.Condition(s => s.Parent != null);
                    opt.MapFrom(s => s.Parent);
                })
                .ForMember(m => m.Translations, opt => opt.MapFrom(s => s.Translations))
                .ForMember(m => m.ForeignKeys, opt => opt.MapFrom(s => s.ForeignKeys))
                .ForMember(m => m.Children, opt => opt.MapFrom(s => s.Children));

                config.CreateMap <IFoodGroup, IFoodGroupProxy>()
                .ConvertUsing(m =>
                {
                    IFoodGroupProxy foodGroupProxy = m as IFoodGroupProxy;
                    if (foodGroupProxy != null)
                    {
                        return((IFoodGroupProxy)m);
                    }
                    IFoodGroupProxy parentFoodGroupProxy = null;
                    if (m.Parent != null)
                    {
                        parentFoodGroupProxy = m.Parent as IFoodGroupProxy;
                        if (parentFoodGroupProxy == null && Mapper != null)
                        {
                            parentFoodGroupProxy = Mapper.Map <IFoodGroup, IFoodGroupProxy>(m.Parent);
                        }
                    }
                    var childFoodGroupProxyCollection = new List <IFoodGroupProxy>();
                    foreach (var child in m.Children)
                    {
                        IFoodGroupProxy childFoodGroupProxy = child as IFoodGroupProxy;
                        if (childFoodGroupProxy != null)
                        {
                            childFoodGroupProxyCollection.Add((IFoodGroupProxy)child);
                            continue;
                        }
                        childFoodGroupProxy = new FoodGroupProxy
                        {
                            Identifier = m.Identifier,
                            Parent     = parentFoodGroupProxy,
                            IsActive   = m.IsActive
                        };
                        childFoodGroupProxyCollection.Add(childFoodGroupProxy);
                    }
                    foodGroupProxy = new FoodGroupProxy(childFoodGroupProxyCollection)
                    {
                        Identifier = m.Identifier,
                        Parent     = parentFoodGroupProxy,
                        IsActive   = m.IsActive
                    };
                    foreach (var translation in m.Translations)
                    {
                        if (translation is ITranslationProxy)
                        {
                            foodGroupProxy.TranslationAdd(translation);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            foodGroupProxy.TranslationAdd(Mapper.Map <ITranslation, ITranslationProxy>(translation));
                        }
                    }
                    foreach (var foreignKey in m.ForeignKeys)
                    {
                        if (foreignKey is IForeignKeyProxy)
                        {
                            foodGroupProxy.ForeignKeyAdd(foreignKey);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            foodGroupProxy.ForeignKeyAdd(Mapper.Map <IForeignKey, IForeignKeyProxy>(foreignKey));
                        }
                    }
                    return(foodGroupProxy);
                });

                config.CreateMap <IForeignKey, ForeignKeyView>()
                .ForMember(m => m.ForeignKeyIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider))
                .ForMember(m => m.ForeignKeyForIdentifier, opt => opt.MapFrom(s => s.ForeignKeyForIdentifier))
                .ForMember(m => m.ForeignKey, opt => opt.MapFrom(s => s.ForeignKeyValue));

                config.CreateMap <IForeignKey, ForeignKeySystemView>()
                .ForMember(m => m.ForeignKeyIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.DataProvider, opt => opt.MapFrom(s => s.DataProvider))
                .ForMember(m => m.ForeignKeyForIdentifier, opt => opt.MapFrom(s => s.ForeignKeyForIdentifier))
                .ForMember(m => m.ForeignKey, opt => opt.MapFrom(s => s.ForeignKeyValue));

                config.CreateMap <IForeignKey, IForeignKeyProxy>()
                .ConvertUsing(m =>
                {
                    IForeignKeyProxy foreignKeyProxy = m as IForeignKeyProxy;
                    if (foreignKeyProxy != null)
                    {
                        return(foreignKeyProxy);
                    }
                    var dataProvider = m.DataProvider as IDataProviderProxy;
                    if (dataProvider == null && Mapper != null)
                    {
                        dataProvider = Mapper.Map <IDataProvider, IDataProviderProxy>(m.DataProvider);
                    }
                    foreignKeyProxy = new ForeignKeyProxy(dataProvider, m.ForeignKeyForIdentifier, m.ForeignKeyForTypes, m.ForeignKeyValue)
                    {
                        Identifier = m.Identifier
                    };
                    return(foreignKeyProxy);
                });

                config.CreateMap <IStaticText, StaticTextView>()
                .ForMember(m => m.StaticTextIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.StaticTextType, opt => opt.MapFrom(s => (int)s.Type))
                .ForMember(m => m.SubjectTranslation, opt => opt.MapFrom(s => s.SubjectTranslation != null ? s.SubjectTranslation.Value : string.Empty))
                .ForMember(m => m.BodyTranslation, opt => opt.MapFrom(s => s.BodyTranslationIdentifier.HasValue ? s.BodyTranslation != null ? s.BodyTranslation.Value : string.Empty : null));

                config.CreateMap <IStaticText, StaticTextSystemView>()
                .ForMember(m => m.StaticTextIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.StaticTextType, opt => opt.MapFrom(s => (int)s.Type))
                .ForMember(m => m.SubjectTranslationIdentifier, opt => opt.MapFrom(s => s.SubjectTranslationIdentifier))
                .ForMember(m => m.SubjectTranslation, opt => opt.MapFrom(s => s.SubjectTranslation != null ? s.SubjectTranslation.Value : string.Empty))
                .ForMember(m => m.SubjectTranslations, opt => opt.MapFrom(s => s.SubjectTranslations))
                .ForMember(m => m.BodyTranslationIdentifier, opt => opt.MapFrom(s => s.BodyTranslationIdentifier.HasValue ? (Guid?)s.BodyTranslationIdentifier.Value : null))
                .ForMember(m => m.BodyTranslation, opt => opt.MapFrom(s => s.BodyTranslationIdentifier.HasValue ? s.BodyTranslation != null ? s.BodyTranslation.Value : string.Empty : null))
                .ForMember(m => m.BodyTranslations, opt => opt.MapFrom(s => s.BodyTranslationIdentifier.HasValue ? s.BodyTranslations : null));

                config.CreateMap <IStaticText, IStaticTextProxy>()
                .ConvertUsing(m =>
                {
                    IStaticTextProxy staticTextProxy = m as IStaticTextProxy;
                    if (staticTextProxy != null)
                    {
                        return(staticTextProxy);
                    }
                    staticTextProxy = new StaticTextProxy(m.Type, m.SubjectTranslationIdentifier, m.BodyTranslationIdentifier)
                    {
                        Identifier = m.Identifier
                    };
                    foreach (var translation in m.Translations)
                    {
                        if (translation is ITranslationProxy)
                        {
                            staticTextProxy.TranslationAdd(translation);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            staticTextProxy.TranslationAdd(Mapper.Map <ITranslation, ITranslationProxy>(translation));
                        }
                    }
                    return(staticTextProxy);
                });

                config.CreateMap <IDataProvider, DataProviderView>()
                .ForMember(m => m.DataProviderIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Name))
                .ForMember(m => m.DataSourceStatement, opt => opt.MapFrom(s => s.DataSourceStatement != null ? s.DataSourceStatement.Value : string.Empty));

                config.CreateMap <IDataProvider, DataProviderSystemView>()
                .ForMember(m => m.DataProviderIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.Name, opt => opt.MapFrom(s => s.Name))
                .ForMember(m => m.HandlesPayments, opt => opt.MapFrom(s => s.HandlesPayments))
                .ForMember(m => m.DataSourceStatementIdentifier, opt => opt.MapFrom(s => s.DataSourceStatementIdentifier))
                .ForMember(m => m.DataSourceStatements, opt => opt.MapFrom(s => s.DataSourceStatements));

                config.CreateMap <IDataProvider, IDataProviderProxy>()
                .ConvertUsing(m =>
                {
                    IDataProviderProxy dataProviderProxy = m as IDataProviderProxy;
                    if (dataProviderProxy != null)
                    {
                        return(dataProviderProxy);
                    }
                    dataProviderProxy = new DataProviderProxy(m.Name, m.HandlesPayments, m.DataSourceStatementIdentifier)
                    {
                        Identifier = m.Identifier
                    };
                    foreach (var translation in m.Translations)
                    {
                        if (translation is ITranslationProxy)
                        {
                            dataProviderProxy.TranslationAdd(translation);
                            continue;
                        }
                        if (Mapper != null)
                        {
                            dataProviderProxy.TranslationAdd(Mapper.Map <ITranslation, ITranslationProxy>(translation));
                        }
                    }
                    return(dataProviderProxy);
                });

                config.CreateMap <ITranslation, TranslationSystemView>()
                .ForMember(m => m.TranslationIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.TranslationOfIdentifier, opt => opt.MapFrom(s => s.TranslationOfIdentifier))
                .ForMember(m => m.TranslationInfo, opt => opt.MapFrom(s => s.TranslationInfo))
                .ForMember(m => m.Translation, opt => opt.MapFrom(s => s.Value));

                config.CreateMap <ITranslation, ITranslationProxy>()
                .ConvertUsing(m =>
                {
                    ITranslationProxy translationProxy = m as ITranslationProxy;
                    if (translationProxy != null)
                    {
                        return(translationProxy);
                    }
                    var translationInfoProxy = m.TranslationInfo as ITranslationInfoProxy;
                    if (translationInfoProxy == null && Mapper != null)
                    {
                        translationInfoProxy = Mapper.Map <ITranslationInfo, ITranslationInfoProxy>(m.TranslationInfo);
                    }
                    return(new TranslationProxy(m.TranslationOfIdentifier, translationInfoProxy, m.Value)
                    {
                        Identifier = m.Identifier
                    });
                });

                config.CreateMap <ITranslationInfo, TranslationInfoSystemView>()
                .ForMember(m => m.TranslationInfoIdentifier, opt => opt.MapFrom(s => s.Identifier ?? Guid.Empty))
                .ForMember(m => m.CultureName, opt => opt.MapFrom(s => s.CultureName));

                config.CreateMap <ITranslationInfo, ITranslationInfoProxy>()
                .ConvertUsing(m =>
                {
                    ITranslationInfoProxy translationInfoProxy = m as ITranslationInfoProxy;
                    return(translationInfoProxy ?? new TranslationInfoProxy(m.CultureName)
                    {
                        Identifier = m.Identifier
                    });
                });

                config.CreateMap <IIdentifiable, ServiceReceiptResponse>()
                .ForMember(m => m.Identifier, opt => opt.MapFrom(s => s.Identifier))
                .ForMember(m => m.EventDate, opt => opt.MapFrom(s => DateTime.Now));

                config.CreateMap <IRange <int>, IntRangeView>()
                .ForMember(m => m.StartValue, opt => opt.MapFrom(s => s.StartValue))
                .ForMember(m => m.EndValue, opt => opt.MapFrom(s => s.EndValue));

                config.CreateMap <bool, BooleanResultResponse>()
                .ForMember(m => m.Result, opt => opt.MapFrom(s => s))
                .ForMember(m => m.EventDate, opt => opt.MapFrom(s => DateTime.Now));
            });

            mapperConfiguration.AssertConfigurationIsValid();

            Mapper = mapperConfiguration.CreateMapper();
        }