internal static IAccounting ToDomain(this AccountingModel accountingModel, MapperCache mapperCache, IConverter accountingModelConverter, IConverter commonModelConverter)
        {
            NullGuard.NotNull(accountingModel, nameof(accountingModel))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter))
            .NotNull(commonModelConverter, nameof(commonModelConverter));

            lock (mapperCache.SyncRoot)
            {
                if (mapperCache.AccountingDictionary.TryGetValue(accountingModel.AccountingIdentifier, out IAccounting accounting))
                {
                    return(accounting);
                }

                ILetterHead letterHead = commonModelConverter.Convert <LetterHeadModel, ILetterHead>(accountingModel.LetterHead);

                accounting = new Domain.Accounting.Accounting(accountingModel.AccountingIdentifier, accountingModel.Name, letterHead, accountingModel.BalanceBelowZero, accountingModel.BackDating);
                accounting.AddAuditInformation(accountingModel.CreatedUtcDateTime, accountingModel.CreatedByIdentifier, accountingModel.ModifiedUtcDateTime, accountingModel.ModifiedByIdentifier);
                accounting.SetDeletable(accountingModel.Deletable);

                mapperCache.AccountingDictionary.Add(accounting.Number, accounting);

                if (accountingModel.Accounts != null)
                {
                    accounting.AccountCollection.Add(accountingModel.Accounts
                                                     .Where(accountModel => accountModel.Convertible())
                                                     .Select(accountModel => accountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                     .Where(account => accounting.AccountCollection.Contains(account) == false)
                                                     .ToArray());
                }

                if (accountingModel.BudgetAccounts != null)
                {
                    accounting.BudgetAccountCollection.Add(accountingModel.BudgetAccounts
                                                           .Where(budgetAccountModel => budgetAccountModel.Convertible())
                                                           .Select(budgetAccountModel => budgetAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                           .Where(budgetAccount => accounting.BudgetAccountCollection.Contains(budgetAccount) == false)
                                                           .ToArray());
                }

                if (accountingModel.ContactAccounts != null)
                {
                    accounting.ContactAccountCollection.Add(accountingModel.ContactAccounts
                                                            .Where(contactAccountModel => contactAccountModel.Convertible())
                                                            .Select(contactAccountModel => contactAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                            .Where(contactAccount => accounting.ContactAccountCollection.Contains(contactAccount) == false)
                                                            .ToArray());
                }

                return(accounting);
            }
        }
        private IAccounting CreateSut(IEnumerable <IAccount> accountCollection = null)
        {
            IAccounting accounting = new Domain.Accounting.Accounting(_fixture.Create <int>(), _fixture.Create <string>(), _fixture.BuildLetterHeadMock().Object);

            accounting.AccountCollection.Add(accountCollection ?? new[]
            {
                _fixture.BuildAccountMock(accounting).Object,
                _fixture.BuildAccountMock(accounting).Object,
                _fixture.BuildAccountMock(accounting).Object
            });

            return(accounting);
        }