public async Task CalculateAsync_WhenCalled_AssertCalculateAsyncWasNotCalledOnAnyPostingLineWhereStatusDateMatchesStatusDateFromArgument() { IPostingLineCollection sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> > { _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate), _fixture.BuildPostingLineMock(statusDate: statusDate) }; sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray()); await sut.CalculateAsync(statusDate); foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection) { postingLineMock.Verify(m => m.CalculateAsync(It.IsAny <DateTime>()), Times.Never); } }
public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_AssertCalculateAsyncWasCalledOnEachPostingLineWhereStatusDateDoesNotMatchStatusDateFromArgument() { IPostingLineCollection sut = CreateSut(); IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> > { _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue) }; sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray()); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate); foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection) { postingLineMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once); } }
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 PostingJournalResult(IPostingLineCollection postingLineCollection, IPostingWarningCalculator postingWarningCalculator) : base(postingLineCollection) { NullGuard.NotNull(postingWarningCalculator, nameof(postingWarningCalculator)); _postingWarningCalculator = postingWarningCalculator; }
public void Add_WhenPostingLineCollectionIsNotNullAndOnePostingLineDoesExistWithinCollection_ThrowsIntranetSystemException() { IPostingLineCollection sut = CreateSut(); IList <IPostingLine> postingLineCollection = new List <IPostingLine> { _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object }; IPostingLine existingPostingLine = postingLineCollection[_random.Next(0, postingLineCollection.Count - 1)]; sut.Add(existingPostingLine); IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(postingLineCollection)); // ReSharper disable PossibleNullReferenceException Assert.That(result.Message.Contains(existingPostingLine.GetType().Name), Is.True); // ReSharper restore PossibleNullReferenceException Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists)); Assert.That(result.InnerException, Is.Null); }
private QueryHandler CreateSut(bool hasPostingLineCollection = true, IPostingLineCollection postingLineCollection = null) { _accountingRepositoryMock.Setup(m => m.GetPostingLinesAsync(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>())) .Returns(Task.FromResult(hasPostingLineCollection ? postingLineCollection ?? _fixture.BuildPostingLineCollectionMock().Object : null)); return(new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object)); }
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); } }
public async Task GetPostingLinesAsync_WhenCalledOnAccountWithNonEmptyAccountCollection_ReturnsPostingLineCollectionWithPostingLinesUpToStatusDate() { DateTime statusDate = DateTime.Today.AddDays(_random.Next(1, 7) * -1); IPostingLine postingLine1BeforeStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7) * -1)).Object; IPostingLine postingLine2BeforeStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7) * -1)).Object; IPostingLine postingLine3BeforeStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7) * -1)).Object; IPostingLine postingLine1OnStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate).Object; IPostingLine postingLine2OnStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate).Object; IPostingLine postingLine3OnStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate).Object; IPostingLine postingLine1AfterStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7))).Object; IPostingLine postingLine2AfterStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7))).Object; IPostingLine postingLine3AfterStatusDate = _fixture.BuildPostingLineMock(postingDate: statusDate.AddDays(_random.Next(1, 7))).Object; IAccount[] accountCollection = { _fixture.BuildAccountMock(postingLineCollection: _fixture.BuildPostingLineCollectionMock(postingLineCollection: new[] { postingLine1BeforeStatusDate, postingLine1OnStatusDate, postingLine1AfterStatusDate }).Object).Object, _fixture.BuildAccountMock(postingLineCollection: _fixture.BuildPostingLineCollectionMock(postingLineCollection: new[] { postingLine2BeforeStatusDate, postingLine2OnStatusDate, postingLine2AfterStatusDate }).Object).Object, _fixture.BuildAccountMock(postingLineCollection: _fixture.BuildPostingLineCollectionMock(postingLineCollection: new[] { postingLine3BeforeStatusDate, postingLine3OnStatusDate, postingLine3AfterStatusDate }).Object).Object }; IAccounting sut = CreateSut(accountCollection); IPostingLineCollection result = await sut.GetPostingLinesAsync(statusDate); Assert.That(result.Contains(postingLine1BeforeStatusDate), Is.True); Assert.That(result.Contains(postingLine2BeforeStatusDate), Is.True); Assert.That(result.Contains(postingLine3BeforeStatusDate), Is.True); Assert.That(result.Contains(postingLine1OnStatusDate), Is.True); Assert.That(result.Contains(postingLine2OnStatusDate), Is.True); Assert.That(result.Contains(postingLine3OnStatusDate), Is.True); Assert.That(result.Contains(postingLine1AfterStatusDate), Is.False); Assert.That(result.Contains(postingLine2AfterStatusDate), Is.False); Assert.That(result.Contains(postingLine3AfterStatusDate), Is.False); }
private Controller CreateSut(IPostingLineCollection postingLineCollection = null) { _queryBusMock.Setup(m => m.QueryAsync <IGetPostingLineCollectionQuery, IPostingLineCollection>(It.IsAny <IGetPostingLineCollectionQuery>())) .Returns(Task.FromResult(postingLineCollection ?? _fixture.BuildPostingLineCollectionMock().Object)); return(new Controller(_commandBusMock.Object, _queryBusMock.Object)); }
public async Task CalculateAsync_WhenCalled_AssertStatusDateWasCalledTreeTimesOnEachPostingLine() { IPostingLineCollection sut = CreateSut(); IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> > { _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue), _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue) }; sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray()); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); await sut.CalculateAsync(statusDate); foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection) { postingLineMock.Verify(m => m.StatusDate, Times.Exactly(3)); } }
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); } }
public async Task CalculateAsync_WhenCalled_ReturnsSamePostingLineCollection() { IPostingLineCollection sut = CreateSut(); IPostingLineCollection result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result, Is.SameAs(sut)); }
public async Task GetPostingLinesAsync_WhenCalledOnAccountWithEmptyAccountCollection_EmptyPostingLineCollection() { IAccounting sut = CreateSut(new IAccount[0]); IPostingLineCollection result = await sut.GetPostingLinesAsync(DateTime.Today.AddDays(_random.Next(1, 7) * -1)); Assert.That(result, Is.Empty); }
public async Task GetPostingLinesAsync_WhenCalledOnAccountWithNonEmptyAccountCollection_ReturnsPostingLineCollection() { IAccounting sut = CreateSut(); IPostingLineCollection result = await sut.GetPostingLinesAsync(DateTime.Today.AddDays(_random.Next(1, 7) * -1)); Assert.That(result, Is.TypeOf <Domain.Accounting.PostingLineCollection>()); }
public void Top_WhenPostingLineCollectionIsEmpty_ReturnsEmptyPostingLineCollection() { IPostingLineCollection sut = CreateSut(); IPostingLineCollection result = sut.Top(_fixture.Create <int>()); Assert.That(result, Is.Empty); }
public async Task ApplyCalculationAsync_WhenCalled_ReturnsSamePostingLineCollection() { IPostingLineCollection sut = CreateSut(); IPostingLineCollection result = await sut.ApplyCalculationAsync(_fixture.BuildBudgetAccountMock().Object); Assert.That(result, Is.SameAs(sut)); }
public async Task GetPostingLinesAsync_WhenAccountingNumberDoesNotExist_ReturnsEmptyPostingLineCollection() { IAccountingRepository sut = CreateSut(); IPostingLineCollection result = await sut.GetPostingLinesAsync(WithNonExistingAccountingNumber(), DateTime.Today, 250); Assert.That(result.Count(), Is.EqualTo(0)); }
public void Ordered_WhenPostingLineCollectionIsEmpty_ReturnsEmptyPostingLineCollection() { IPostingLineCollection sut = CreateSut(); IPostingLineCollection result = sut.Ordered(); Assert.That(result, Is.Empty); }
public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_ReturnsSamePostingLineCollection() { IPostingLineCollection sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IPostingLineCollection result = await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate); Assert.That(result, Is.SameAs(sut)); }
public async Task QueryAsync_WhenNoPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsEmptyPostingLineCollection() { QueryHandler sut = CreateSut(false); IGetPostingLineCollectionQuery query = CreateQuery(); IPostingLineCollection result = await sut.QueryAsync(query); Assert.That(result.Count(), Is.EqualTo(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); }
public async Task CalculateAsync_WhenCalled_ReturnsSamePostingLineCollectionWhereStatusDateEqualDateFromCall() { IPostingLineCollection sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IPostingLineCollection result = await sut.CalculateAsync(statusDate); Assert.That(result.StatusDate, Is.EqualTo(statusDate.Date)); }
public async Task QueryAsync_WhenNoPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsNotNull() { QueryHandler sut = CreateSut(false); IGetPostingLineCollectionQuery query = CreateQuery(); IPostingLineCollection result = await sut.QueryAsync(query); Assert.That(result, Is.Not.Null); }
public async Task <IPostingWarningCollection> CalculateAsync(IPostingLineCollection postingLineCollection) { NullGuard.NotNull(postingLineCollection, nameof(postingLineCollection)); Task <IPostingWarningCollection>[] calculationTasks = postingLineCollection.Select(CalculateAsync).ToArray(); IPostingWarningCollection[] postingWarningCollections = await Task.WhenAll(calculationTasks); return(BuildPostingWarningCollection(postingWarningCollections.SelectMany(postingWarningCollection => postingWarningCollection))); }
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); }
public async Task CalculateAsync_WhenCalled_ReturnsSameContactAccountWherePostingLineCollectionIsEqualToCalculatedPostingLineCollection() { IPostingLineCollection calculatedPostingLineCollection = _fixture.BuildPostingLineCollectionMock().Object; IPostingLineCollection postingLineCollection = _fixture.BuildPostingLineCollectionMock(calculatedPostingLineCollection: calculatedPostingLineCollection).Object; IContactAccount sut = CreateSut(postingLineCollection: postingLineCollection); IContactAccount result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.PostingLineCollection, Is.EqualTo(calculatedPostingLineCollection)); }
public void Ordered_WhenCalled_ReturnsNotNull() { IPostingLineCollection sut = CreateSut(); sut.Add(_fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray()); IPostingLineCollection result = sut.Ordered(); Assert.That(result, Is.Not.Null); }
public void Ordered_WhenCalled_ReturnsPostingLineCollection() { IPostingLineCollection sut = CreateSut(); sut.Add(_fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray()); IPostingLineCollection result = sut.Ordered(); Assert.That(result, Is.TypeOf <Domain.Accounting.PostingLineCollection>()); }
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 }
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); }