public async Task CalculateAsync_WhenCalled_AssertMonthWasCalledOnEachCreditInfoInCreditInfoCollection()
        {
            ICreditInfoCollection sut = CreateSut();

            DateTime creditInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <Mock <ICreditInfo> > creditInfoMockCollection = new List <Mock <ICreditInfo> >
            {
                _fixture.BuildCreditInfoMock(creditInfoOffset, isLastYearOfStatusDate: true),
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1), isLastYearOfStatusDate: true),
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2))
            };

            sut.Add(creditInfoMockCollection.Select(creditInfoMock => creditInfoMock.Object).ToArray());

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

            foreach (Mock <ICreditInfo> creditInfoMock in creditInfoMockCollection)
            {
                if (creditInfoMock.Object.IsLastYearOfStatusDate)
                {
                    creditInfoMock.Verify(m => m.Month, Times.Once);
                    continue;
                }

                creditInfoMock.Verify(m => m.Month, Times.Never);
            }
        }
        public async Task CalculateAsync_WhenCalled_ReturnsCreditInfoCollection()
        {
            ICreditInfoCollection sut = CreateSut();

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

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

            DateTime creditInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            IEnumerable <ICreditInfo> creditInfoCollection = new List <ICreditInfo>
            {
                _fixture.BuildCreditInfoMock(creditInfoOffset).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1)).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(creditInfoCollection);

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

            Assert.That(result.ValuesAtEndOfLastYearFromStatusDate.Balance, Is.EqualTo(0M));
        }
        public async Task CalculateAsync_WhenCreditInfoCollectionContainsCreditInfoForEndOfLastYearFromStatusDate_ReturnsCreditInfoCollectionWhereCreditInValuesAtEndOfLastYearFromStatusDateIsEqualToCreditInCreditInfoForEndOfLastYearFromStatusDate()
        {
            ICreditInfoCollection sut = CreateSut();

            DateTime    creditInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            ICreditInfo creditInfoForEndOfLastYearFromStatusDate = _fixture.BuildCreditInfoMock(creditInfoOffset, isLastYearOfStatusDate: true).Object;
            IEnumerable <ICreditInfo> creditInfoCollection       = new List <ICreditInfo>
            {
                creditInfoForEndOfLastYearFromStatusDate,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1), isLastYearOfStatusDate: true).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2), isLastYearOfStatusDate: true).Object
            };

            sut.Add(creditInfoCollection);

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

            Assert.That(result.ValuesAtEndOfLastYearFromStatusDate.Credit, Is.EqualTo(creditInfoForEndOfLastYearFromStatusDate.Credit));
        }
        public async Task CalculateAsync_WhenCreditInfoCollectionContainsCreditInfoForStatusDate_ReturnsCreditInfoCollectionWhereValuesAtStatusDateIsNotNull()
        {
            ICreditInfoCollection sut = CreateSut();

            DateTime    creditInfoOffset                   = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            ICreditInfo creditInfoForStatusDate            = _fixture.BuildCreditInfoMock(creditInfoOffset, true).Object;
            IEnumerable <ICreditInfo> creditInfoCollection = new List <ICreditInfo>
            {
                creditInfoForStatusDate,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1)).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(creditInfoCollection);

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

            Assert.That(result.ValuesAtStatusDate, Is.Not.Null);
        }