public void Validate_WhenAccountingWasReturnedFromAccountingRepository_AssertValidateWasCalledOnEachApplyPostingLineCommand() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IEnumerable <Mock <IApplyPostingLineCommand> > applyPostingLineCommandMockCollection = new[] { CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock() }; IApplyPostingJournalCommand sut = CreateSut(accounting: accounting, applyPostingLineCommandCollection: applyPostingLineCommandMockCollection.Select(applyPostingLineCommandMock => applyPostingLineCommandMock.Object).ToArray()); sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); foreach (Mock <IApplyPostingLineCommand> applyPostingLineCommandMock in applyPostingLineCommandMockCollection) { applyPostingLineCommandMock.Verify(m => m.Validate( It.Is <IValidator>(value => value == _validatorMockContext.ValidatorMock.Object), It.Is <IAccounting>(value => value == accounting)), Times.Once); } }
public void ToDomain_WhenCalled_ReturnsNotNull() { IApplyPostingJournalCommand sut = CreateSut(); IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(result, Is.Not.Null); }
public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionNotEmpty() { IApplyPostingJournalCommand sut = CreateSut(); IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(result.PostingLineCollection, Is.Not.Empty); }
public void Validate_WhenCalled_ReturnsValidator() { IApplyPostingJournalCommand sut = CreateSut(); IValidator result = sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object)); }
public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_AssertCalculateAsyncWasCalledOnPostingWarningCalculatorWithEmptyPostingLineCollection() { CommandHandler sut = CreateSut(false); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); await sut.ExecuteAsync(applyPostingJournalCommand); _postingWarningCalculatorMock.Verify(m => m.CalculateAsync(It.Is <IPostingLineCollection>(value => value != null && value.Any() == false)), Times.Once); }
public async Task ExecuteAsync_WhenPostingJournalResultWasReturnedFromAccountingRepository_ReturnsNotNull() { CommandHandler sut = CreateSut(); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result, Is.Not.Null); }
public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_ReturnsCalculatedPostingJournalResult() { CommandHandler sut = CreateSut(false); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result.StatusDate, Is.EqualTo(DateTime.Today)); }
public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_ReturnsPostingJournalResultWherePostingWarningCollectionIsNotNull() { CommandHandler sut = CreateSut(false); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result.PostingWarningCollection, Is.Not.Null); }
public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_ReturnsPostingJournalResult() { CommandHandler sut = CreateSut(false); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result, Is.TypeOf <PostingJournalResult>()); }
public async Task ExecuteAsync_WhenPostingJournalResultWasReturnedFromAccountingRepository_AssertCalculateAsyncWasCalledOnPostingJournalResultFromAccountingRepository() { Mock <IPostingJournalResult> postingJournalResultMock = _fixture.BuildPostingJournalResultMock(); CommandHandler sut = CreateSut(postingJournalResult: postingJournalResultMock.Object); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); await sut.ExecuteAsync(applyPostingJournalCommand); postingJournalResultMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == DateTime.Today)), Times.Once); }
public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_ReturnsPostingJournalResultWherePostingWarningCollectionEqualToPostingWarningCollectionFromPostingWarningCalculator() { IPostingWarningCollection postingWarningCollection = _fixture.BuildPostingWarningCollectionMock(isEmpty: true).Object; CommandHandler sut = CreateSut(false, postingWarningCollection: postingWarningCollection); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result.PostingWarningCollection, Is.EqualTo(postingWarningCollection)); }
public void ToDomain_WhenAccountingRepositoryIsNull_ThrowsArgumentNullException() { IApplyPostingJournalCommand sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ToDomain(null)); // ReSharper disable PossibleNullReferenceException Assert.That(result.ParamName, Is.EqualTo("accountingRepository")); // ReSharper restore PossibleNullReferenceException }
public void Validate_WhenCommonRepositoryIsNull_ThrowsArgumentNullException() { IApplyPostingJournalCommand sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, null)); // ReSharper disable PossibleNullReferenceException Assert.That(result.ParamName, Is.EqualTo("commonRepository")); // ReSharper restore PossibleNullReferenceException }
public async Task ExecuteAsync_WhenPostingJournalResultWasReturnedFromAccountingRepository_ReturnsCalculatedPostingJournalResult() { IPostingJournalResult calculatedPostingJournalResult = _fixture.BuildPostingJournalResultMock().Object; IPostingJournalResult postingJournalResult = _fixture.BuildPostingJournalResultMock(calculatedPostingJournalResult: calculatedPostingJournalResult).Object; CommandHandler sut = CreateSut(postingJournalResult: postingJournalResult); IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(); IPostingJournalResult result = await sut.ExecuteAsync(applyPostingJournalCommand); Assert.That(result, Is.EqualTo(calculatedPostingJournalResult)); }
public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionContainingSameAmountOfPostingLinesAsApplyPostingLineCommands() { int numberOfApplyPostingLineCommands = _random.Next(10, 25); IApplyPostingLineCommand[] applyPostingLineCommandCollection = _fixture.CreateMany <IApplyPostingLineCommand>(numberOfApplyPostingLineCommands).ToArray(); IApplyPostingJournalCommand sut = CreateSut(applyPostingLineCommandCollection: applyPostingLineCommandCollection); IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(result.PostingLineCollection.Count(), Is.EqualTo(numberOfApplyPostingLineCommands)); }
public void Validate_WhenCalled_AssertGetAccountingAsyncWasCalledOnAccountingRepository() { int accountingNumber = _fixture.Create <int>(); IApplyPostingJournalCommand sut = CreateSut(accountingNumber); sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); _accountingRepositoryMock.Verify(m => m.GetAccountingAsync( It.Is <int>(value => value == accountingNumber), It.Is <DateTime>(value => value == DateTime.Today)), Times.Once); }
public async Task ExecuteAsync_WhenCalled_AssertApplyPostingJournalAsyncWasCalledOnAccountingRepository() { CommandHandler sut = CreateSut(); IPostingJournal postingJournal = _fixture.BuildPostingJournalMock().Object; IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(postingJournal); await sut.ExecuteAsync(applyPostingJournalCommand); _accountingRepositoryMock.Verify(m => m.ApplyPostingJournalAsync( It.Is <IPostingJournal>(value => value == postingJournal), It.Is <IPostingWarningCalculator>(value => value == _postingWarningCalculatorMock.Object)), Times.Once); }
public void Validate_WhenCalled_AssertShouldNotBeNullWasCalledOnObjectValidatorWithPostingLineCollection() { IEnumerable <IApplyPostingLineCommand> applyPostingLineCommandCollection = _fixture.CreateMany <IApplyPostingLineCommand>(_random.Next(10, 25)).ToArray(); IApplyPostingJournalCommand sut = CreateSut(applyPostingLineCommandCollection: applyPostingLineCommandCollection); sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldNotBeNull( It.Is <IEnumerable <IApplyPostingLineCommand> >(value => value.Equals(applyPostingLineCommandCollection)), It.Is <Type>(type => type == sut.GetType()), It.Is <string>(field => string.CompareOrdinal(field, "PostingLineCollection") == 0)), Times.Once); }
public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidatorWithAccountingNumber() { int accountingNumber = _fixture.Create <int>(); IApplyPostingJournalCommand sut = CreateSut(accountingNumber); sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeKnownValue( It.Is <int>(value => value == accountingNumber), It.IsNotNull <Func <int, Task <bool> > >(), It.Is <Type>(type => type == sut.GetType()), It.Is <string>(field => string.CompareOrdinal(field, "AccountingNumber") == 0), It.Is <bool>(allowNull => allowNull == false)), Times.Once); }
public Task <ActionResult <ApplyPostingJournalResultModel> > ApplyPostingJournalAsync([FromBody] ApplyPostingJournalModel applyPostingJournal) { if (applyPostingJournal == null) { throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNull, nameof(applyPostingJournal)) .WithValidatingType(typeof(ApplyPostingJournalModel)) .WithValidatingField(nameof(applyPostingJournal)) .Build(); } SchemaValidator.Validate(ModelState); IApplyPostingJournalCommand applyPostingJournalCommand = _accountingModelConverter.Convert <ApplyPostingJournalModel, ApplyPostingJournalCommand>(applyPostingJournal); return(ApplyPostingJournalAsync(applyPostingJournalCommand)); }
public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionContainingPostingLinesFromToDomainOnEachApplyPostingLineCommands() { IPostingLine[] postingLineCollection = new[] { _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object, _fixture.BuildPostingLineMock().Object }; IApplyPostingJournalCommand sut = CreateSut(applyPostingLineCommandCollection: postingLineCollection.Select(CreateApplyPostingLineCommand).ToArray()); IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object); foreach (IPostingLine postingLine in postingLineCollection) { Assert.That(result.PostingLineCollection.Contains(postingLine), Is.True); } }
public void ToDomain_WhenCalled_AssertToDomainWasCalledOnEachApplyPostingLineCommand() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IEnumerable <Mock <IApplyPostingLineCommand> > applyPostingLineCommandMockCollection = new[] { CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock() }; IApplyPostingJournalCommand sut = CreateSut(accounting: accounting, applyPostingLineCommandCollection: applyPostingLineCommandMockCollection.Select(applyPostingLineCommandMock => applyPostingLineCommandMock.Object).ToArray()); sut.ToDomain(_accountingRepositoryMock.Object); foreach (Mock <IApplyPostingLineCommand> applyPostingLineCommandMock in applyPostingLineCommandMockCollection) { applyPostingLineCommandMock.Verify(m => m.ToDomain(It.Is <IAccounting>(value => value == accounting)), Times.Once); } }
public void Validate_WhenAccountingWasNotReturnedFromAccountingRepository_AssertValidateWasNotCalledOnAnyApplyPostingLineCommand() { IEnumerable <Mock <IApplyPostingLineCommand> > applyPostingLineCommandMockCollection = new[] { CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock(), CreateApplyPostingLineCommandMock() }; IApplyPostingJournalCommand sut = CreateSut(hasAccounting: false, applyPostingLineCommandCollection: applyPostingLineCommandMockCollection.Select(applyPostingLineCommandMock => applyPostingLineCommandMock.Object).ToArray()); sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object); foreach (Mock <IApplyPostingLineCommand> applyPostingLineCommandMock in applyPostingLineCommandMockCollection) { applyPostingLineCommandMock.Verify(m => m.Validate( It.IsAny <IValidator>(), It.IsAny <IAccounting>()), Times.Never); } }
private async Task <ActionResult <ApplyPostingJournalResultModel> > ApplyPostingJournalAsync(IApplyPostingJournalCommand applyPostingJournalCommand) { NullGuard.NotNull(applyPostingJournalCommand, nameof(applyPostingJournalCommand)); IPostingJournalResult postingJournalResult = await _commandBus.PublishAsync <IApplyPostingJournalCommand, IPostingJournalResult>(applyPostingJournalCommand); ApplyPostingJournalResultModel applyPostingJournalResultModel = postingJournalResult == null ? BuildEmptyApplyPostingJournalResultModel() : _accountingModelConverter.Convert <IPostingJournalResult, ApplyPostingJournalResultModel>(postingJournalResult); return(Ok(applyPostingJournalResultModel)); }