예제 #1
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());
        }
예제 #2
0
        public void TestThatCreateCreatesProxy(bool handlesPayments)
        {
            IDataProviderProxy sut = CreateSut();

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

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

            IFoodWasteDataProvider dataProvider = CreateFoodWasteDataProvider();

            IDataProviderProxy result = sut.Create(dataReader, dataProvider, "DataProviderIdentifier", "Name", "HandlesPayments", "DataSourceStatementIdentifier");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Identifier, Is.Not.Null);
            Assert.That(result.Identifier, Is.EqualTo(identifier));
            Assert.That(result.Name, Is.Not.Null);
            Assert.That(result.Name, Is.Not.Empty);
            Assert.That(result.Name, Is.EqualTo(name));
            Assert.That(result.HandlesPayments, Is.EqualTo(handlesPayments));
            Assert.That(result.DataSourceStatementIdentifier, Is.Not.EqualTo(Guid.Empty));
            Assert.That(result.DataSourceStatementIdentifier, Is.EqualTo(dataSourceStatementIdentifier));

            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("DataProviderIdentifier")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("Name")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("HandlesPayments")), opt => opt.Repeat.Once());
            dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("DataSourceStatementIdentifier")), opt => opt.Repeat.Once());

            dataProvider.AssertWasNotCalled(m => m.Clone());
        }
        /// <summary>
        /// Creates a mockup for the data provider which can access data in the food waste repository.
        /// </summary>
        /// <returns>Mockup for the data provider which can access data in the food waste repository.</returns>
        private IFoodWasteDataProvider CreateFoodWasteDataProvider(IDataProviderProxy dataProviderProxy = null)
        {
            IFoodWasteDataProvider foodWasteDataProvider = MockRepository.GenerateMock <IFoodWasteDataProvider>();

            foodWasteDataProvider.Stub(m => m.Create(Arg <IDataProviderProxy> .Is.Anything, Arg <MySqlDataReader> .Is.Anything, Arg <string[]> .Is.Anything))
            .Return(dataProviderProxy ?? BuildDataProviderProxy())
            .Repeat.Any();
            return(foodWasteDataProvider);
        }
        /// <summary>
        /// Builds a mockup for a data proxy for a given data provider.
        /// </summary>
        /// <param name="dataProviderIdentifier">Identifier for the data provider.</param>
        /// <returns>Mockup for a data proxy for a given data provider.</returns>
        private IDataProviderProxy BuildDataProviderProxy(Guid?dataProviderIdentifier = null)
        {
            IDataProviderProxy dataProviderProxyMock = MockRepository.GenerateMock <IDataProviderProxy>();

            dataProviderProxyMock.Stub(m => m.Identifier)
            .Return(dataProviderIdentifier ?? Guid.NewGuid())
            .Repeat.Any();
            return(dataProviderProxyMock);
        }
예제 #5
0
        public void TestThatCreateThrowsArgumentNullExceptionIfColumnNameCollectionIsNull()
        {
            IDataProviderProxy sut = CreateSut();

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

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

            TestHelper.AssertArgumentNullExceptionIsValid(result, "columnNameCollection");
        }
예제 #6
0
        public void TestThatDeleteRelationsThrowsNotSupportedExceptionWhenDataProviderIsNotNull()
        {
            IDataProviderProxy sut = CreateSut();

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

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

            TestHelper.AssertNotSupportedExceptionIsValid(result);
        }
예제 #7
0
        public void TestThatSaveRelationsThrowsNotSupportedExceptionWhenDataProviderIsNull()
        {
            IDataProviderProxy sut = CreateSut();

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

            NotSupportedException result = Assert.Throws <NotSupportedException>(() => sut.SaveRelations(null, _fixture.Create <bool>()));

            TestHelper.AssertNotSupportedExceptionIsValid(result);
        }
예제 #8
0
        public void TestThatMapRelationsThrowsArgumentNullExceptionIfDataProviderIsNull()
        {
            IDataProviderProxy sut = CreateSut();

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

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

            TestHelper.AssertArgumentNullExceptionIsValid(result, "dataProvider");
        }
예제 #9
0
        public void TestThatCreateThrowsArgumentNullExceptionIfDataProviderIsNull()
        {
            IDataProviderProxy 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");
        }
        /// <summary>
        /// Creates an instance of a data proxy to a given foreign key to a domain object in the food waste domain.
        /// </summary>
        /// <returns>Instance of a data proxy to a given foreign key to a domain object in the food waste domain.</returns>
        private IForeignKeyProxy CreateSut(Guid identifier, IDataProviderProxy dataProviderProxy, Guid foreignKeyForIdentifier, Type foreignKeyForType, string foreignKeyValue)
        {
            ArgumentNullGuard.NotNull(dataProviderProxy, nameof(dataProviderProxy))
            .NotNull(foreignKeyForType, nameof(foreignKeyForType))
            .NotNullOrWhiteSpace(foreignKeyValue, nameof(foreignKeyValue));

            return(new ForeignKeyProxy(dataProviderProxy, foreignKeyForIdentifier, foreignKeyForType, foreignKeyValue)
            {
                Identifier = identifier
            });
        }
예제 #11
0
        public void TestThatCreateDeleteCommandReturnsSqlCommandForDelete()
        {
            Guid identifier = Guid.NewGuid();

            IDataProviderProxy sut = CreateSut(identifier);

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

            new DbCommandTestBuilder("DELETE FROM DataProviders WHERE DataProviderIdentifier=@dataProviderIdentifier")
            .AddCharDataParameter("@dataProviderIdentifier", identifier)
            .Build()
            .Run(sut.CreateDeleteCommand());
        }
예제 #12
0
        public void TestThatCreateGetCommandReturnsSqlCommand()
        {
            Guid identifier = Guid.NewGuid();

            IDataProviderProxy sut = CreateSut(identifier);

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

            new DbCommandTestBuilder("SELECT DataProviderIdentifier,Name,HandlesPayments,DataSourceStatementIdentifier FROM DataProviders WHERE DataProviderIdentifier=@dataProviderIdentifier")
            .AddCharDataParameter("@dataProviderIdentifier", identifier)
            .Build()
            .Run(sut.CreateGetCommand());
        }
        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());
        }
예제 #14
0
        public void TestThatUniqueIdGetterGetsUniqueIdentificationForDataProviderProxy()
        {
            Guid identifier = Guid.NewGuid();

            IDataProviderProxy 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()));
        }
예제 #15
0
        public void TestThatUniqueIdGetterThrowsIntranetRepositoryExceptionWhenDataProviderProxyHasNoIdentifier()
        {
            IDataProviderProxy 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");
        }
예제 #16
0
        public void TestThatConstructorInitializeDataProviderProxy()
        {
            IDataProviderProxy sut = CreateSut();

            Assert.That(sut, Is.Not.Null);
            Assert.That(sut.Identifier, Is.Null);
            Assert.That(sut.Identifier.HasValue, Is.False);
            Assert.That(sut.Translation, Is.Null);
            Assert.That(sut.Translations, Is.Not.Null);
            Assert.That(sut.Translations, Is.Empty);
            Assert.That(sut.Name, Is.Null);
            Assert.That(sut.HandlesPayments, Is.False);
            Assert.That(sut.DataSourceStatementIdentifier, Is.EqualTo(Guid.Empty));
            Assert.That(sut.DataSourceStatement, Is.Null);
            Assert.That(sut.DataSourceStatements, Is.Not.Null);
            Assert.That(sut.DataSourceStatements, Is.Empty);
        }
예제 #17
0
        public void TestThatCreateInsertCommandReturnsSqlCommandForInsert(bool handlesPayments)
        {
            Guid   identifier = Guid.NewGuid();
            string name       = _fixture.Create <string>();
            Guid   dataSourceStatementIdentifier = Guid.NewGuid();

            IDataProviderProxy sut = CreateSut(identifier, name, handlesPayments, dataSourceStatementIdentifier);

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

            new DbCommandTestBuilder("INSERT INTO DataProviders (DataProviderIdentifier,Name,HandlesPayments,DataSourceStatementIdentifier) VALUES(@dataProviderIdentifier,@name,@handlesPayments,@dataSourceStatementIdentifier)")
            .AddCharDataParameter("@dataProviderIdentifier", identifier)
            .AddVarCharDataParameter("@name", name, 256)
            .AddBitDataParameter("@handlesPayments", handlesPayments)
            .AddCharDataParameter("@dataSourceStatementIdentifier", dataSourceStatementIdentifier)
            .Build()
            .Run(sut.CreateInsertCommand());
        }
예제 #18
0
        public void TestThatCreateUpdateCommandReturnsSqlCommandForUpdate(bool handlesPayments)
        {
            Guid   identifier = Guid.NewGuid();
            string name       = _fixture.Create <string>();
            Guid   dataSourceStatementIdentifier = Guid.NewGuid();

            IDataProviderProxy sut = CreateSut(identifier, name, handlesPayments, dataSourceStatementIdentifier);

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

            new DbCommandTestBuilder("UPDATE DataProviders SET Name=@name,HandlesPayments=@handlesPayments,DataSourceStatementIdentifier=@dataSourceStatementIdentifier WHERE DataProviderIdentifier=@dataProviderIdentifier")
            .AddCharDataParameter("@dataProviderIdentifier", identifier)
            .AddVarCharDataParameter("@name", name, 256)
            .AddBitDataParameter("@handlesPayments", handlesPayments)
            .AddCharDataParameter("@dataSourceStatementIdentifier", dataSourceStatementIdentifier)
            .Build()
            .Run(sut.CreateUpdateCommand());
        }
        public void TestThatCreateUpdateCommandReturnsSqlCommandForUpdate()
        {
            Guid identifier                      = Guid.NewGuid();
            Guid dataProviderIdentifier          = Guid.NewGuid();
            IDataProviderProxy dataProviderProxy = BuildDataProviderProxy(dataProviderIdentifier);
            Guid   foreignKeyForIdentifier       = Guid.NewGuid();
            Type   foreignKeyForType             = typeof(DataProvider);
            string foreignKeyValue               = _fixture.Create <string>();

            IForeignKeyProxy sut = CreateSut(identifier, dataProviderProxy, foreignKeyForIdentifier, foreignKeyForType, foreignKeyValue);

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

            new DbCommandTestBuilder("UPDATE ForeignKeys SET DataProviderIdentifier=@dataProviderIdentifier,ForeignKeyForIdentifier=@foreignKeyForIdentifier,ForeignKeyForTypes=@foreignKeyForTypes,ForeignKeyValue=@foreignKeyValue WHERE ForeignKeyIdentifier=@foreignKeyIdentifier")
            .AddCharDataParameter("@foreignKeyIdentifier", identifier)
            .AddCharDataParameter("@dataProviderIdentifier", dataProviderIdentifier)
            .AddCharDataParameter("@foreignKeyForIdentifier", foreignKeyForIdentifier)
            .AddVarCharDataParameter("@foreignKeyForTypes", string.Join(";", foreignKeyForType.GetInterfaces().Select(m => m.Name)), 128)
            .AddVarCharDataParameter("@foreignKeyValue", foreignKeyValue, 128)
            .Build()
            .Run(sut.CreateUpdateCommand());
        }
        /// <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();
        }