Exemple #1
0
        private Controller CreateSut(IBudgetAccountCollection budgetAccountCollection = null)
        {
            _queryBusMock.Setup(m => m.QueryAsync <IGetBudgetAccountCollectionQuery, IBudgetAccountCollection>(It.IsAny <IGetBudgetAccountCollectionQuery>()))
            .Returns(Task.FromResult(budgetAccountCollection ?? _fixture.BuildBudgetAccountCollectionMock().Object));

            return(new Controller(_commandBusMock.Object, _queryBusMock.Object));
        }
        private QueryHandler CreateSut(bool hasBudgetAccountCollection = true, IBudgetAccountCollection budgetAccountCollection = null)
        {
            _accountingRepositoryMock.Setup(m => m.GetBudgetAccountsAsync(It.IsAny<int>(), It.IsAny<DateTime>()))
                .Returns(Task.FromResult(hasBudgetAccountCollection ? budgetAccountCollection ?? _fixture.BuildBudgetAccountCollectionMock().Object : null));

            return new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object);
        }
Exemple #3
0
        public async Task GetBudgetAccountsAsync_WhenAccountingNumberDoesNotExist_ReturnsEmptyBudgetAccountCollection()
        {
            IAccountingRepository sut = CreateSut();

            IBudgetAccountCollection result = await sut.GetBudgetAccountsAsync(WithNonExistingAccountingNumber(), DateTime.Today);

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

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

            Assert.That(result, Is.SameAs(sut));
        }
        public async Task QueryAsync_WhenNoBudgetAccountCollectionWasReturnedFromAccountingRepository_ReturnsNotNull()
        {
            QueryHandler sut = CreateSut(false);

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

            Assert.That(result, Is.Not.Null);
        }
        public async Task QueryAsync_WhenNoBudgetAccountCollectionWasReturnedFromAccountingRepository_ReturnsEmptyBudgetAccountCollection()
        {
            QueryHandler sut = CreateSut(false);

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

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

            sut.Add(CreateBudgetAccountCollection());

            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await sut.GroupByBudgetAccountGroupAsync();

            Assert.That(result.All(item => item.Value.All(budgetAccount => budgetAccount.BudgetAccountGroup.Number == item.Key.Number)), Is.True);
        }
        public async Task QueryAsync_WhenNoBudgetAccountCollectionWasReturnedFromAccountingRepository_ReturnsBudgetAccountCollectionWhereStatusDateIsEqualToStatusDateFromGetBudgetAccountCollectionQuery()
        {
            QueryHandler sut = CreateSut(false);

            DateTime statusDate = _fixture.Create<DateTime>().Date;
            IGetBudgetAccountCollectionQuery query = CreateQuery(statusDate: statusDate);
            IBudgetAccountCollection result = await sut.QueryAsync(query);

            Assert.That(result.StatusDate, Is.EqualTo(statusDate));
        }
        public void ValuesForMonthOfStatusDate_WhenCalculateAsyncHasNotBeenCalled_ReturnsBudgetInfoValuesWherePostedIsEqualToZero()
        {
            IBudgetAccountCollection sut = CreateSut();

            sut.Add(_fixture.CreateMany <IBudgetAccount>(_random.Next(5, 10)).ToArray());

            IBudgetInfoValues result = sut.ValuesForMonthOfStatusDate;

            Assert.That(result.Posted, Is.EqualTo(0M));
        }
Exemple #10
0
        public async Task CalculateAsync_WhenCalled_ReturnsSameCalculableWithCalculatedBudgetAccountCollection()
        {
            IBudgetAccountCollection  calculatedBudgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock().Object;
            IBudgetAccountCollection  budgetAccountCollection           = _fixture.BuildBudgetAccountCollectionMock(calculatedBudgetAccountCollection: calculatedBudgetAccountCollection).Object;
            ICalculable <IAccounting> sut = CreateSut(budgetAccountCollection: budgetAccountCollection);

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

            Assert.That(result.BudgetAccountCollection, Is.EqualTo(calculatedBudgetAccountCollection));
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_ReturnsNotNull()
        {
            IBudgetAccountCollection sut = CreateSut();

            sut.Add(CreateBudgetAccountCollection());

            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await sut.GroupByBudgetAccountGroupAsync();

            Assert.That(result, Is.Not.Null);
        }
        public void ValuesForMonthOfStatusDate_WhenCalculateAsyncHasNotBeenCalled_ReturnsNotNull()
        {
            IBudgetAccountCollection sut = CreateSut();

            sut.Add(_fixture.CreateMany <IBudgetAccount>(_random.Next(5, 10)).ToArray());

            IBudgetInfoValues result = sut.ValuesForMonthOfStatusDate;

            Assert.That(result, Is.Not.Null);
        }
        public async Task QueryAsync_WhenBudgetAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedBudgetAccountCollection()
        {
            IBudgetAccountCollection calculatedBudgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock().Object;
            IBudgetAccountCollection budgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock(calculatedBudgetAccountCollection: calculatedBudgetAccountCollection).Object;
            QueryHandler sut = CreateSut(budgetAccountCollection: budgetAccountCollection);

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(calculatedBudgetAccountCollection));
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_ReturnsReadOnlyDictionaryWhereAllBudgetAccountCollectionsIsCalculated()
        {
            IBudgetAccountCollection sut = CreateSut();

            sut.Add(CreateBudgetAccountCollection());

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);
            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await(await sut.CalculateAsync(statusDate)).GroupByBudgetAccountGroupAsync();

            Assert.That(result.Select(item => item.Value.StatusDate).All(value => value == statusDate.Date), Is.True);
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_ReturnsReadOnlyDictionaryWhichContainsAllBudgetAccountsInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            IBudgetAccount[] budgetAccountCollection = CreateBudgetAccountCollection();
            sut.Add(budgetAccountCollection);

            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await sut.GroupByBudgetAccountGroupAsync();

            Assert.That(budgetAccountCollection.All(budgetAccount => result.SelectMany(item => item.Value).Contains(budgetAccount)), Is.True);
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_ReturnsReadOnlyDictionaryWhichContainsEachBudgetAccountGroupFromBudgetAccountsInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            IBudgetAccountGroup[] budgetAccountGroupCollection = _fixture.CreateMany <IBudgetAccountGroup>(_random.Next(2, 5)).ToArray();
            sut.Add(CreateBudgetAccountCollection(budgetAccountGroupCollection));

            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await sut.GroupByBudgetAccountGroupAsync();

            Assert.That(budgetAccountGroupCollection.All(budgetAccountGroup => result.Keys.Single(key => key.Number == budgetAccountGroup.Number) != null), Is.True);
        }
        public async Task <ActionResult <BudgetAccountCollectionModel> > BudgetAccountsAsync(int accountingNumber, DateTimeOffset?statusDate = null)
        {
            IGetBudgetAccountCollectionQuery query = new GetBudgetAccountCollectionQuery
            {
                AccountingNumber = accountingNumber,
                StatusDate       = statusDate?.LocalDateTime.Date ?? DateTime.Today
            };
            IBudgetAccountCollection budgetAccountCollection = await _queryBus.QueryAsync <IGetBudgetAccountCollectionQuery, IBudgetAccountCollection>(query);

            BudgetAccountCollectionModel budgetAccountCollectionModel = _accountingModelConverter.Convert <IBudgetAccountCollection, BudgetAccountCollectionModel>(budgetAccountCollection);

            return(new OkObjectResult(budgetAccountCollectionModel));
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_AssertAccountNumberWasCalledOnEachBudgetAccountInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            Mock <IBudgetAccount>[] budgetAccountMockCollection = CreateBudgetAccountMockCollection();
            sut.Add(budgetAccountMockCollection.Select(budgetAccountMock => budgetAccountMock.Object).ToArray());

            await sut.GroupByBudgetAccountGroupAsync();

            foreach (Mock <IBudgetAccount> budgetAccountMock in budgetAccountMockCollection)
            {
                budgetAccountMock.Verify(m => m.AccountNumber, Times.Once);
            }
        }
Exemple #19
0
        public async Task BudgetAccountsAsync_WhenCalled_ReturnsOkObjectResultWhereValueIsBudgetAccountCollectionModelContainingAllBudgetAccounts()
        {
            IList <IBudgetAccount>   budgetAccounts          = _fixture.CreateMany <IBudgetAccount>(_random.Next(5, 10)).ToList();
            IBudgetAccountCollection budgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock(budgetAccountCollection: budgetAccounts).Object;
            Controller sut = CreateSut(budgetAccountCollection);

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

            BudgetAccountCollectionModel budgetAccountCollectionModel = (BudgetAccountCollectionModel)result.Value;

            Assert.That(budgetAccountCollectionModel, Is.Not.Null);
            Assert.That(budgetAccountCollectionModel.Count, Is.EqualTo(budgetAccounts.Count));
            Assert.That(budgetAccountCollectionModel.All(budgetAccountModel => budgetAccounts.SingleOrDefault(budgetAccount => string.CompareOrdinal(budgetAccountModel.AccountNumber, budgetAccount.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 GroupByBudgetAccountGroupAsync_WhenCalled_AssertNumberWasCalledOnBudgetAccountGroupForEachBudgetAccountInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            Mock <IBudgetAccountGroup>[] budgetAccountGroupMockCollection =
            {
                _fixture.BuildBudgetAccountGroupMock(),
                _fixture.BuildBudgetAccountGroupMock(),
                _fixture.BuildBudgetAccountGroupMock()
            };
            sut.Add(CreateBudgetAccountCollection(budgetAccountGroupMockCollection.Select(budgetAccountGroupMock => budgetAccountGroupMock.Object).ToArray()));

            await sut.GroupByBudgetAccountGroupAsync();

            foreach (Mock <IBudgetAccountGroup> budgetAccountGroupMock in budgetAccountGroupMockCollection)
            {
                budgetAccountGroupMock.Verify(m => m.Number, Times.AtLeastOnce);
            }
        }
        public async Task CalculateAsync_WhenCalled_ReturnsBudgetAccountCollectionWherePostedInValuesForLastYearOfStatusDateIsEqualToSumOfPostedFromValuesForLastYearOfStatusDateOnBudgetAccounts()
        {
            IBudgetAccountCollection sut = CreateSut();

            IEnumerable <IBudgetAccount> budgetAccountCollection = new List <IBudgetAccount>
            {
                _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object
            };

            sut.Add(budgetAccountCollection);

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

            Assert.That(result.ValuesForLastYearOfStatusDate.Posted, Is.EqualTo(budgetAccountCollection.Sum(budgetAccount => budgetAccount.ValuesForLastYearOfStatusDate.Posted)));
        }
        public async Task CalculateAsync_WhenCalled_ReturnsBudgetAccountCollectionWhereValuesForValuesForLastYearOfStatusDateIsNotNull()
        {
            IBudgetAccountCollection sut = CreateSut();

            IEnumerable <IBudgetAccount> budgetAccountCollection = new List <IBudgetAccount>
            {
                _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object,
                                         _fixture.BuildBudgetAccountMock().Object
            };

            sut.Add(budgetAccountCollection);

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

            Assert.That(result.ValuesForLastYearOfStatusDate, Is.Not.Null);
        }
        public async Task CalculateAsync_WhenCalled_AssertPostedWasCalledOnValuesForMonthOfStatusDateForEachBudgetAccountInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            IEnumerable <Mock <IBudgetInfoValues> > budgetInfoValuesMockCollection = new List <Mock <IBudgetInfoValues> >
            {
                _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock(),
                                                    _fixture.BuildBudgetInfoValuesMock()
            };

            sut.Add(budgetInfoValuesMockCollection.Select(budgetInfoValuesMock => _fixture.BuildBudgetAccountMock(valuesForMonthOfStatusDate: budgetInfoValuesMock.Object).Object).ToArray());

            await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            foreach (Mock <IBudgetInfoValues> budgetInfoValuesMock in budgetInfoValuesMockCollection)
            {
                budgetInfoValuesMock.Verify(m => m.Posted, Times.Once);
            }
        }
        public async Task CalculateAsync_WhenCalled_AssertValuesForLastYearOfStatusDateWasCalledOnEachBudgetAccountInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            IEnumerable <Mock <IBudgetAccount> > budgetAccountMockCollection = new List <Mock <IBudgetAccount> >
            {
                _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock(),
                                                 _fixture.BuildBudgetAccountMock()
            };

            sut.Add(budgetAccountMockCollection.Select(budgetAccountMock => budgetAccountMock.Object).ToArray());

            await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            foreach (Mock <IBudgetAccount> budgetAccountMock in budgetAccountMockCollection)
            {
                budgetAccountMock.Verify(m => m.ValuesForLastYearOfStatusDate, Times.Exactly(2));
            }
        }
Exemple #26
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));
 }