public async Task CalculateAsync_WhenCalled_ReturnsBudgetInfoCollection()
        {
            IBudgetInfoCollection sut = CreateSut();

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

            Assert.That(result, Is.SameAs(sut));
        }
        public async Task CalculateAsync_WhenBudgetInfoCollectionContainBudgetInfoForLastYearOfStatusDate_ReturnsBudgetInfoCollectionWherePostInValuesForLastYearOfStatusDateIsEqualToSumOfPostedFromBudgetInfoForLastYearOfStatusDate()
        {
            IBudgetInfoCollection sut = CreateSut();

            DateTime budgetInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <IBudgetInfo> budgetInfoCollection = new List <IBudgetInfo>
            {
                _fixture.BuildBudgetInfoMock(budgetInfoOffset, isLastYearOfStatusDate: true).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-1), isLastYearOfStatusDate: true).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(budgetInfoCollection);

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

            Assert.That(result.ValuesForLastYearOfStatusDate.Posted, Is.EqualTo(budgetInfoCollection.Where(budgetInfo => budgetInfo.IsLastYearOfStatusDate).Sum(budgetInfo => budgetInfo.Posted)));
        }
        public async Task CalculateAsync_WhenBudgetInfoCollectionDoesNotContainBudgetInfoForLastYearOfStatusDate_ReturnsBudgetInfoCollectionWhereBudgetInValuesForLastYearOfStatusDateIsEqualToZero()
        {
            IBudgetInfoCollection sut = CreateSut();

            DateTime budgetInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <IBudgetInfo> budgetInfoCollection = new List <IBudgetInfo>
            {
                _fixture.BuildBudgetInfoMock(budgetInfoOffset).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-1)).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(budgetInfoCollection);

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

            Assert.That(result.ValuesForLastYearOfStatusDate.Budget, Is.EqualTo(0M));
        }
        public async Task CalculateAsync_WhenBudgetInfoCollectionContainBudgetInfoForYearToDateOfStatusDate_ReturnsBudgetInfoCollectionWhereValuesForYearToDateOfStatusDateIsNotNull()
        {
            IBudgetInfoCollection sut = CreateSut();

            DateTime budgetInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <IBudgetInfo> budgetInfoCollection = new List <IBudgetInfo>
            {
                _fixture.BuildBudgetInfoMock(budgetInfoOffset, isYearToDateOfStatusDate: true).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-1), isYearToDateOfStatusDate: true).Object,
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(budgetInfoCollection);

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

            Assert.That(result.ValuesForYearToDateOfStatusDate, Is.Not.Null);
        }
        public async Task CalculateAsync_WhenCalled_AssertIsYearToDateOfStatusDateWasCalledOnEachBudgetInfoInBudgetInfoCollection()
        {
            IBudgetInfoCollection sut = CreateSut();

            DateTime budgetInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <Mock <IBudgetInfo> > budgetInfoMockCollection = new List <Mock <IBudgetInfo> >
            {
                _fixture.BuildBudgetInfoMock(budgetInfoOffset, isYearToDateOfStatusDate: true),
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-1), isYearToDateOfStatusDate: true),
                _fixture.BuildBudgetInfoMock(budgetInfoOffset.AddMonths(-2))
            };

            sut.Add(budgetInfoMockCollection.Select(budgetInfoMock => budgetInfoMock.Object).ToArray());

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

            foreach (Mock <IBudgetInfo> budgetInfoMock in budgetInfoMockCollection)
            {
                budgetInfoMock.Verify(m => m.IsYearToDateOfStatusDate, Times.Once);
            }
        }