Beispiel #1
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertAccountingWasCalledOnEachPostingLine()
        {
            IPostingLineCollection sut = CreateSut();

            int            accountingNumber = _fixture.Create <int>();
            string         accountNumber    = _fixture.Create <string>();
            IAccounting    accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IBudgetAccount budgetAccount    = _fixture.BuildBudgetAccountMock(accounting, accountNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IBudgetAccount calculatedBudgetAccount = _fixture.BuildBudgetAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedBudgetAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.Accounting, Times.Once);
            }
        }
        public async Task ApplyCalculationAsync_WhenCalled_AssertApplyCalculationAsyncWasNotCalledOnAnyPostingLineNotMatchingCalculatedAccount()
        {
            IPostingLineCollection sut = CreateSut();

            int         accountingNumber = _fixture.Create <int>();
            string      accountNumber    = _fixture.Create <string>();
            IAccounting accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IAccount calculatedAccount = _fixture.BuildAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.ApplyCalculationAsync(It.IsAny <IAccount>()), Times.Never);
            }
        }
Beispiel #3
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertApplyCalculationAsyncWasCalledOnEachPostingLineMatchingCalculatedContactAccount()
        {
            IPostingLineCollection sut = CreateSut();

            int             accountingNumber = _fixture.Create <int>();
            string          accountNumber    = _fixture.Create <string>();
            IAccounting     accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IContactAccount contactAccount   = _fixture.BuildContactAccountMock(accounting, accountNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IContactAccount calculatedContactAccount = _fixture.BuildContactAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedContactAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.ApplyCalculationAsync(It.Is <IContactAccount>(value => value != null && value == calculatedContactAccount)), Times.Once);
            }
        }
Beispiel #4
0
        public async Task ApplyCalculationAsync_WhenCalled_ReturnsSamePostingLineCollection()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLineCollection result = await sut.ApplyCalculationAsync(_fixture.BuildBudgetAccountMock().Object);

            Assert.That(result, Is.SameAs(sut));
        }
Beispiel #5
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertAccountNumberWasCalledOnCalculatedBudgetAccount()
        {
            IPostingLineCollection sut = CreateSut();

            Mock <IBudgetAccount> calculatedBudgetAccountMock = _fixture.BuildBudgetAccountMock();
            await sut.ApplyCalculationAsync(calculatedBudgetAccountMock.Object);

            calculatedBudgetAccountMock.Verify(m => m.AccountNumber, Times.Once);
        }
Beispiel #6
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertAccountingWasCalledOnCalculatedContactAccount()
        {
            IPostingLineCollection sut = CreateSut();

            Mock <IContactAccount> calculatedContactAccountMock = _fixture.BuildContactAccountMock(isEmpty: true);
            await sut.ApplyCalculationAsync(calculatedContactAccountMock.Object);

            calculatedContactAccountMock.Verify(m => m.Accounting, Times.Once);
        }
Beispiel #7
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertNumberWasCalledOnAccountingFromCalculatedBudgetAccount()
        {
            IPostingLineCollection sut = CreateSut();

            Mock <IAccounting> accountingMock          = _fixture.BuildAccountingMock();
            IBudgetAccount     calculatedBudgetAccount = _fixture.BuildBudgetAccountMock(accountingMock.Object).Object;
            await sut.ApplyCalculationAsync(calculatedBudgetAccount);

            accountingMock.Verify(m => m.Number, Times.Once);
        }
Beispiel #8
0
        public void ApplyCalculationAsync_WhenCalculatedBudgetAccountIsNull_ThrowsArgumentNullException()
        {
            IPostingLineCollection sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.ApplyCalculationAsync((IBudgetAccount)null));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("calculatedBudgetAccount"));
            // ReSharper restore PossibleNullReferenceException
        }