/// <summary>
        /// Build a mockup for a payment made by a stakeholder.
        /// </summary>
        /// <returns>Mockup for a payment made by a stakeholder</returns>
        public static IPayment BuildPaymentMock(IStakeholder stakeholder = null, bool hasPaymentReceipt = true)
        {
            IPayment paymentMock = MockRepository.GenerateMock <IPayment>();

            paymentMock.Stub(m => m.Identifier)
            .Return(Guid.NewGuid())
            .Repeat.Any();
            paymentMock.Stub(m => m.Stakeholder)
            .Return(stakeholder ?? BuildStakeholderMock())
            .Repeat.Any();
            paymentMock.Stub(m => m.DataProvider)
            .Return(BuildDataProviderMock(true))
            .Repeat.Any();
            paymentMock.Stub(m => m.PaymentTime)
            .Return(DateTime.Now.AddDays(Random.Next(1, 365) * -1).AddMinutes(Random.Next(120, 240)))
            .Repeat.Any();
            paymentMock.Stub(m => m.PaymentReference)
            .Return(Fixture.Create <string>())
            .Repeat.Any();
            paymentMock.Stub(m => m.PaymentReceipt)
            .Return(hasPaymentReceipt ? Fixture.CreateMany <byte>(Random.Next(1024, 4096)).ToArray() : null)
            .Repeat.Any();
            paymentMock.Stub(m => m.CreationTime)
            .Return(DateTime.Now)
            .Repeat.Any();
            return(paymentMock);
        }
Пример #2
0
 public StakeholderAction(IDecision decision, string action, IStakeholder stakeholder)
 {
     Stakeholder      = stakeholder;
     Decision         = decision;
     Action           = action;
     PropertyChanged += OnPropertyChanged;
 }
Пример #3
0
 /// <summary>
 /// Creates an instance of a data proxy to a payment from a stakeholder.
 /// </summary>
 /// <returns>Instance of a data proxy to a payment from a stakeholder.</returns>
 private IPaymentProxy CreateSut(Guid identifier, IStakeholder stakeholder, IDataProvider dataProvider, DateTime paymentTime, string paymentReference, IEnumerable <byte> paymentReceipt, DateTime creationTime)
 {
     return(new PaymentProxy(stakeholder, dataProvider, paymentTime, paymentReference, paymentReceipt, creationTime)
     {
         Identifier = identifier
     });
 }
Пример #4
0
        public void TestThatCreateUpdateCommandReturnsSqlCommandForUpdate(StakeholderType stakeholderType, bool hasPaymentReceipt)
        {
            Guid          identifier       = Guid.NewGuid();
            IStakeholder  stakeholder      = DomainObjectMockBuilder.BuildStakeholderMock(stakeholderType);
            IDataProvider dataProvider     = DomainObjectMockBuilder.BuildDataProviderMock(true);
            DateTime      paymentTime      = DateTime.Now.AddDays(_random.Next(1, 7) * -1).AddMinutes(_random.Next(120, 240));
            string        paymentReference = _fixture.Create <string>();

            byte[]        paymentReceipt = hasPaymentReceipt ? _fixture.CreateMany <byte>(_random.Next(1024, 4096)).ToArray() : null;
            DateTime      creationTime   = DateTime.Now;
            IPaymentProxy sut            = CreateSut(identifier, stakeholder, dataProvider, paymentTime, paymentReference, paymentReceipt, creationTime);

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

            new DbCommandTestBuilder("UPDATE Payments SET StakeholderIdentifier=@stakeholderIdentifier,StakeholderType=@stakeholderType,DataProviderIdentifier=@dataProviderIdentifier,PaymentTime=@paymentTime,PaymentReference=@paymentReference,PaymentReceipt=@paymentReceipt,CreationTime=@creationTime WHERE PaymentIdentifier=@paymentIdentifier")
            .AddCharDataParameter("@paymentIdentifier", identifier)
            .AddCharDataParameter("@stakeholderIdentifier", stakeholder.Identifier)
            .AddTinyIntDataParameter("@stakeholderType", (int)stakeholderType, 4)
            .AddCharDataParameter("@dataProviderIdentifier", dataProvider.Identifier)
            .AddDateTimeDataParameter("@paymentTime", paymentTime.ToUniversalTime())
            .AddVarCharDataParameter("@paymentReference", paymentReference, 128)
            .AddLongTextDataParameter("@paymentReceipt", paymentReceipt, true)
            .AddDateTimeDataParameter("@creationTime", creationTime.ToUniversalTime())
            .Build()
            .Run(sut.CreateUpdateCommand());
        }
            /// <summary>
            /// Handles the communication so data will be dispatched to the stakeholder.
            /// </summary>
            /// <param name="stakeholder">Stakeholder which data should be dispatched to.</param>
            /// <param name="domainObject">Domain object which provides data to dispatch.</param>
            /// <param name="translationInfo">Translation informations used to translate the data to dispatch.</param>
            protected override void HandleCommunication(IStakeholder stakeholder, TDomainObject domainObject, ITranslationInfo translationInfo)
            {
                Assert.That(stakeholder, Is.Not.Null);
                Assert.That(domainObject, Is.Not.Null);
                Assert.That(translationInfo, Is.Not.Null);

                HandleCommunicationHasBeenCalled = true;
            }
 /// <summary>
 /// Build a collection of mockups for some payments made by a stakeholder.
 /// </summary>
 /// <returns>Collection of mockups for some payments made by a stakeholder.</returns>
 public static IEnumerable <IPayment> BuildPaymentMockCollection(IStakeholder stakeholder = null, bool hasPaymentReceipt = true)
 {
     return(new List <IPayment>
     {
         BuildPaymentMock(stakeholder, hasPaymentReceipt),
         BuildPaymentMock(stakeholder, hasPaymentReceipt),
         BuildPaymentMock(stakeholder, hasPaymentReceipt)
     });
 }
Пример #7
0
        public Stakeholder Convert(IStakeholder stakeholderBO)
        {
            var convertedStakeholder = new Stakeholder
            {
                Name            = stakeholderBO.Name,
                IsParticipating = stakeholderBO.IsParticipating
            };

            return(convertedStakeholder);
        }
Пример #8
0
        /// <summary>
        /// Handles the communication so welcome letter will be dispatched to the household member.
        /// </summary>
        /// <param name="stakeholder">Stakeholder which data should be dispatched to.</param>
        /// <param name="householdMember">Household member which should receive the welcome letter.</param>
        /// <param name="translationInfo">Translation informations used to translate the data to dispatch.</param>
        protected override void HandleCommunication(IStakeholder stakeholder, IHouseholdMember householdMember, ITranslationInfo translationInfo)
        {
            var welcomeLetterStaticText = _systemDataRepository.StaticTextGetByStaticTextType(StaticTextType.WelcomeLetter);

            welcomeLetterStaticText.Translate(translationInfo.CultureInfo);

            _staticTextFieldMerge.AddMergeFields(householdMember, translationInfo);
            _staticTextFieldMerge.Merge(welcomeLetterStaticText, translationInfo);

            CommunicationRepository.SendMail(stakeholder.MailAddress, welcomeLetterStaticText.SubjectTranslation.Value, welcomeLetterStaticText.BodyTranslation.Value);
        }
        /// <summary>
        /// Build a mockup for an internal or external stakeholder.
        /// </summary>
        /// <returns>Mockup for an internal or external stakeholder.</returns>
        public static IStakeholder BuildStakeholderMock(StakeholderType stakeholderType = StakeholderType.HouseholdMember)
        {
            Guid identifier = Guid.NewGuid();
            // ReSharper disable StringLiteralTypo
            string mailAddress = $"test.{identifier.ToString("D").ToLower()}@osdevgrp.dk";
            // ReSharper restore StringLiteralTypo
            IStakeholder stakeholderMock = MockRepository.GenerateMock <IStakeholder>();

            stakeholderMock.Stub(m => m.Identifier)
            .Return(identifier)
            .Repeat.Any();
            stakeholderMock.Stub(m => m.StakeholderType)
            .Return(stakeholderType)
            .Repeat.Any();
            stakeholderMock.Stub(m => m.MailAddress)
            .Return(mailAddress)
            .Repeat.Any();
            return(stakeholderMock);
        }
 /// <summary>
 /// Creates a payment from a stakeholder.
 /// </summary>
 /// <param name="stakeholder">Stakeholder who has made the payment.</param>
 /// <param name="dataProvider">Data provider who has handled the payment.</param>
 /// <param name="paymentTime">Date and time for the payment.</param>
 /// <param name="paymentReference">Payment reference from the data provider who has handled the payment.</param>
 /// <param name="paymentReceipt">Payment receipt from the data provider who has handled the payment.</param>
 /// <param name="creationTime">Creation date and time.</param>
 protected Payment(IStakeholder stakeholder, IDataProvider dataProvider, DateTime paymentTime, string paymentReference, IEnumerable <byte> paymentReceipt, DateTime creationTime)
 {
     if (stakeholder == null)
     {
         throw new ArgumentNullException("stakeholder");
     }
     if (dataProvider == null)
     {
         throw new ArgumentNullException("dataProvider");
     }
     if (string.IsNullOrWhiteSpace(paymentReference))
     {
         throw new ArgumentNullException("paymentReference");
     }
     _stakeholder      = stakeholder;
     _dataProvider     = dataProvider;
     _paymentTime      = paymentTime;
     _paymentReference = paymentReference;
     if (paymentReceipt != null)
     {
         _paymentReceipt = paymentReceipt.ToArray();
     }
     _creationTime = creationTime;
 }
        /// <summary>
        /// Dispatch data for a given domain object in the food waste domain.
        /// </summary>
        /// <param name="stakeholder">Stakeholder which data should be dispatched to.</param>
        /// <param name="domainObject">Domain object which provides data to dispatch.</param>
        /// <param name="translationInfo">Translation informations used to translate the data to dispatch.</param>
        public virtual void Dispatch(IStakeholder stakeholder, TDomainObject domainObject, ITranslationInfo translationInfo)
        {
            if (stakeholder == null)
            {
                throw new ArgumentNullException("stakeholder");
            }
            if (Equals(domainObject, null))
            {
                throw new ArgumentNullException("domainObject");
            }
            if (translationInfo == null)
            {
                throw new ArgumentNullException("translationInfo");
            }

            var translatableDomainObject = domainObject as ITranslatable;

            if (translatableDomainObject != null)
            {
                translatableDomainObject.Translate(translationInfo.CultureInfo);
            }

            HandleCommunication(stakeholder, domainObject, translationInfo);
        }
 /// <summary>
 /// Creates an instance of the private class for testing a payment from a stakeholder.
 /// </summary>
 /// <param name="stakeholder">Stakeholder who has made the payment.</param>
 /// <param name="dataProvider">Data provider who has handled the payment.</param>
 /// <param name="paymentTime">Date and time for the payment.</param>
 /// <param name="paymentReference">Payment reference from the data provider who has handled the payment.</param>
 /// <param name="paymentReceipt">Payment receipt from the data provider who has handled the payment.</param>
 public MyPayment(IStakeholder stakeholder, IDataProvider dataProvider, DateTime paymentTime, string paymentReference, IEnumerable <byte> paymentReceipt = null)
     : base(stakeholder, dataProvider, paymentTime, paymentReference, paymentReceipt)
 {
 }
 /// <summary>
 /// Creates a payment from a stakeholder.
 /// </summary>
 /// <param name="stakeholder">Stakeholder who has made the payment.</param>
 /// <param name="dataProvider">Data provider who has handled the payment.</param>
 /// <param name="paymentTime">Date and time for the payment.</param>
 /// <param name="paymentReference">Payment reference from the data provider who has handled the payment.</param>
 /// <param name="paymentReceipt">Payment receipt from the data provider who has handled the payment.</param>
 public Payment(IStakeholder stakeholder, IDataProvider dataProvider, DateTime paymentTime, string paymentReference, IEnumerable <byte> paymentReceipt = null)
     : this(stakeholder, dataProvider, paymentTime, paymentReference, paymentReceipt, DateTime.Now)
 {
 }
        /// <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();
        }
 /// <summary>
 /// Creates a data proxy to a payment from a stakeholder.
 /// </summary>
 /// <param name="stakeholder">Stakeholder who has made the payment.</param>
 /// <param name="dataProvider">Data provider who has handled the payment.</param>
 /// <param name="paymentTime">Date and time for the payment.</param>
 /// <param name="paymentReference">Payment reference from the data provider who has handled the payment.</param>
 /// <param name="paymentReceipt">Payment receipt from the data provider who has handled the payment.</param>
 /// <param name="creationTime">Creation date and time.</param>
 public PaymentProxy(IStakeholder stakeholder, IDataProvider dataProvider, DateTime paymentTime, string paymentReference, IEnumerable <byte> paymentReceipt, DateTime creationTime)
     : base(stakeholder, dataProvider, paymentTime, paymentReference, paymentReceipt, creationTime)
 {
 }
 /// <summary>
 /// Handles the communication so data will be dispatched to the stakeholder.
 /// </summary>
 /// <param name="stakeholder">Stakeholder which data should be dispatched to.</param>
 /// <param name="domainObject">Domain object which provides data to dispatch.</param>
 /// <param name="translationInfo">Translation informations used to translate the data to dispatch.</param>
 protected abstract void HandleCommunication(IStakeholder stakeholder, TDomainObject domainObject, ITranslationInfo translationInfo);