public async Task CalculateAsync_WhenCalledOnPostingLineWithAccountWhereStatusDateMatchesStatusDateFromArgument_AssertCalculateAsyncWasNotCalledOnAccount()
        {
            DateTime        statusDate  = DateTime.Now.AddDays(_random.Next(1, 365) * -1);
            Mock <IAccount> accountMock = _fixture.BuildAccountMock(statusDate: statusDate);
            IPostingLine    sut         = CreateSut(account: accountMock.Object);

            await sut.CalculateAsync(statusDate);

            accountMock.Verify(m => m.CalculateAsync(It.IsAny <DateTime>()), Times.Never);
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithAccounting_AssertCalculateAsyncWasNotCalledOnAccounting()
        {
            Mock <IAccounting> accountingMock = _fixture.BuildAccountingMock();
            IAccount           account        = _fixture.BuildAccountMock(accountingMock.Object).Object;
            IPostingLine       sut            = CreateSut(account: account);

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

            accountingMock.Verify(m => m.CalculateAsync(It.IsAny <DateTime>()), Times.Never);
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithAccountWhereStatusDateDoesNotMatchStatusDateFromArgument_AssertCalculateAsyncWasCalledOnAccount()
        {
            Mock <IAccount> accountMock = _fixture.BuildAccountMock(statusDate: DateTime.MinValue);
            IPostingLine    sut         = CreateSut(account: accountMock.Object);

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

            accountMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once);
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithAccount_ReturnsSamePostingLineWhereAccountValuesAtPostingDateHasNotBeenChanged()
        {
            IAccount     account = _fixture.BuildAccountMock(statusDate: DateTime.MinValue).Object;
            IPostingLine sut     = CreateSut(account: account);

            ICreditInfoValues accountValuesAtPostingDate = sut.AccountValuesAtPostingDate;
            IPostingLine      result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            Assert.That(result.AccountValuesAtPostingDate, Is.SameAs(accountValuesAtPostingDate));
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithAccounting_ReturnsSamePostingLineWhereAccountingIsNotNull()
        {
            IAccounting  accounting = _fixture.BuildAccountingMock(statusDate: DateTime.MinValue).Object;
            IAccount     account    = _fixture.BuildAccountMock(accounting).Object;
            IPostingLine sut        = CreateSut(account: account);

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

            Assert.That(result.Accounting, Is.Not.Null);
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithBudgetAccount_AssertStatusDateWasCalledOnBudgetAccount()
        {
            IAccounting           accounting        = _fixture.BuildAccountingMock().Object;
            IAccount              account           = _fixture.BuildAccountMock(accounting).Object;
            Mock <IBudgetAccount> budgetAccountMock = _fixture.BuildBudgetAccountMock(accounting);
            IPostingLine          sut = CreateSut(account: account, budgetAccount: budgetAccountMock.Object);

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

            budgetAccountMock.Verify(m => m.StatusDate, Times.Once);
        }
        public async Task CalculateAsync_WhenCalledMultipleTimesOnPostingLineWithAccount_AssertStatusDateWasCalledOnlyOnceOnAccount()
        {
            Mock <IAccount> accountMock = _fixture.BuildAccountMock();
            IPostingLine    sut         = CreateSut(account: accountMock.Object);

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);

            await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate);

            accountMock.Verify(m => m.StatusDate, Times.Once);
        }
        public async Task CalculateAsync_WhenCalledOnPostingLineWithContactAccount_ReturnsSamePostingLineWhereContactAccountHasNotBeenChanged()
        {
            IAccounting     accounting = _fixture.BuildAccountingMock().Object;
            IAccount        account    = _fixture.BuildAccountMock(accounting).Object;
            IContactAccount calculatedContactAccount = _fixture.BuildContactAccountMock().Object;
            IContactAccount contactAccount           = _fixture.BuildContactAccountMock(accounting, statusDate: DateTime.MinValue, calculatedContactAccount: calculatedContactAccount).Object;
            IPostingLine    sut = CreateSut(account: account, contactAccount: contactAccount);

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

            Assert.That(result.ContactAccount, Is.SameAs(contactAccount));
        }
        public async Task CalculateAsync_WhenCalledMultipleTimesOnPostingLineWithContactAccountWhereStatusDateDoesNotMatchStatusDateFromArgument_AssertCalculateAsyncWasCalledOnlyOnceOnContactAccount()
        {
            IAccounting            accounting         = _fixture.BuildAccountingMock().Object;
            IAccount               account            = _fixture.BuildAccountMock(accounting).Object;
            Mock <IContactAccount> contactAccountMock = _fixture.BuildContactAccountMock(accounting, statusDate: DateTime.MinValue);
            IPostingLine           sut = CreateSut(account: account, contactAccount: contactAccountMock.Object);

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);

            await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate);

            contactAccountMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once);
        }