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 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));
            }
        }
        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);
        }