public async Task QueryAsync_WhenContactAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedDebtorAccountCollection()
        {
            IContactAccountCollection calculatedDebtorAccountCollection  = _fixture.BuildContactAccountCollectionMock().Object;
            IContactAccountCollection debtorAccountCollection            = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedDebtorAccountCollection).Object;
            IContactAccountCollection calculatedContactAccountCollection = _fixture.BuildContactAccountCollectionMock(findDebtorsContactAccountCollection: debtorAccountCollection).Object;
            IContactAccountCollection contactAccountCollection           = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedContactAccountCollection).Object;
            QueryHandler sut = CreateSut(contactAccountCollection: contactAccountCollection);

            IGetDebtorAccountCollectionQuery query  = CreateQuery();
            IContactAccountCollection        result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(calculatedDebtorAccountCollection));
        }
        public async Task <ActionResult <ContactAccountCollectionModel> > DebtorsAsync(int accountingNumber, DateTimeOffset?statusDate = null)
        {
            IGetDebtorAccountCollectionQuery query = new GetDebtorAccountCollectionQuery
            {
                AccountingNumber = accountingNumber,
                StatusDate       = statusDate?.LocalDateTime.Date ?? DateTime.Today
            };
            IContactAccountCollection debtorAccountCollection = await _queryBus.QueryAsync <IGetDebtorAccountCollectionQuery, IContactAccountCollection>(query);

            ContactAccountCollectionModel debtorAccountCollectionModel = _accountingModelConverter.Convert <IContactAccountCollection, ContactAccountCollectionModel>(debtorAccountCollection);

            return(new OkObjectResult(debtorAccountCollectionModel));
        }
        public async Task ContactAccountsAsync_WhenCalled_ReturnsOkObjectResultWhereValueIsContactAccountCollectionModelContainingAllContactAccounts()
        {
            IList <IContactAccount>   contactAccounts          = _fixture.CreateMany <IContactAccount>(_random.Next(5, 10)).ToList();
            IContactAccountCollection contactAccountCollection = _fixture.BuildContactAccountCollectionMock(contactAccountCollection: contactAccounts).Object;
            Controller sut = CreateSut(contactAccountCollection);

            OkObjectResult result = (OkObjectResult)(await sut.ContactAccountsAsync(_fixture.Create <int>())).Result;

            ContactAccountCollectionModel contactAccountCollectionModel = (ContactAccountCollectionModel)result.Value;

            Assert.That(contactAccountCollectionModel, Is.Not.Null);
            Assert.That(contactAccountCollectionModel.Count, Is.EqualTo(contactAccounts.Count));
            Assert.That(contactAccountCollectionModel.All(contactAccountModel => contactAccounts.SingleOrDefault(contactAccount => string.CompareOrdinal(contactAccountModel.AccountNumber, contactAccount.AccountNumber) == 0) != null), Is.True);
        }
        public Accounting(int number, string name, ILetterHead letterHead, BalanceBelowZeroType balanceBelowZero, int backDating, IAccountCollection accountCollection, IBudgetAccountCollection budgetAccountCollection, IContactAccountCollection contactAccountCollection)
        {
            NullGuard.NotNullOrWhiteSpace(name, nameof(name))
            .NotNull(letterHead, nameof(letterHead))
            .NotNull(accountCollection, nameof(accountCollection))
            .NotNull(budgetAccountCollection, nameof(budgetAccountCollection))
            .NotNull(contactAccountCollection, nameof(contactAccountCollection));

            Number                   = number;
            Name                     = name.Trim();
            LetterHead               = letterHead;
            BalanceBelowZero         = balanceBelowZero;
            BackDating               = backDating;
            AccountCollection        = accountCollection;
            BudgetAccountCollection  = budgetAccountCollection;
            ContactAccountCollection = contactAccountCollection;
        }
        public async Task FindDebtorsAsync_WhenContactAccountCollectionContainsOnlyNonDebtorContactAccounts_ReturnsEmptyAccountCollection()
        {
            IContactAccountCollection sut = CreateSut();

            IEnumerable <IContactAccount> nonDebtorContactAccountCollection = new List <IContactAccount>
            {
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.None).Object,
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.None).Object,
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.None).Object,
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: ContactAccountType.Creditor).Object
            };

            sut.Add(nonDebtorContactAccountCollection);

            IContactAccountCollection result = await sut.FindDebtorsAsync();

            Assert.That(result.Count(), Is.EqualTo(0));
        }
        public async Task FindDebtorsAsync_WhenContactAccountCollectionContainsContactAccounts_ReturnsNotNull()
        {
            IContactAccountCollection sut = CreateSut();

            IEnumerable <IContactAccount> contactAccountCollection = new List <IContactAccount>
            {
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object
            };

            sut.Add(contactAccountCollection);

            IContactAccountCollection result = await sut.FindDebtorsAsync();

            Assert.That(result, Is.Not.Null);
        }
        public async Task FindDebtorsAsync_WhenContactAccountCollectionContainsContactAccounts_ReturnsCalculatedAccountCollection()
        {
            IContactAccountCollection sut = CreateSut();

            IEnumerable <IContactAccount> contactAccountCollection = new List <IContactAccount>
            {
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object,
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor).Object
            };

            sut.Add(contactAccountCollection);

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);
            IContactAccountCollection result = await(await sut.CalculateAsync(statusDate)).FindDebtorsAsync();

            Assert.That(result.StatusDate, Is.EqualTo(statusDate.Date));
        }
        public async Task FindDebtorsAsync_WhenCalled_AssertContactAccountTypeWasCalledOnEachContactAccountInContactAccountCollection()
        {
            IContactAccountCollection sut = CreateSut();

            IEnumerable <Mock <IContactAccount> > contactAccountMockCollection = new List <Mock <IContactAccount> >
            {
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor),
                _fixture.BuildContactAccountMock(contactAccountType: _random.Next(100) > 50 ? ContactAccountType.Debtor : ContactAccountType.Creditor)
            };

            sut.Add(contactAccountMockCollection.Select(contactAccountMock => contactAccountMock.Object).ToArray());

            await sut.FindDebtorsAsync();

            foreach (Mock <IContactAccount> contactAccountMock in contactAccountMockCollection)
            {
                contactAccountMock.Verify(m => m.ContactAccountType, Times.Once);
            }
        }
示例#9
0
 private ICalculable <IAccounting> CreateSut(IAccountCollection accountCollection = null, IBudgetAccountCollection budgetAccountCollection = null, IContactAccountCollection contactAccountCollection = null)
 {
     return(new Domain.Accounting.Accounting(_fixture.Create <int>(), _fixture.Create <string>(), _fixture.BuildLetterHeadMock().Object, _fixture.Create <BalanceBelowZeroType>(), _fixture.Create <int>(), accountCollection ?? _fixture.BuildAccountCollectionMock().Object, budgetAccountCollection ?? _fixture.BuildBudgetAccountCollectionMock().Object, contactAccountCollection ?? _fixture.BuildContactAccountCollectionMock().Object));
 }