public async Task ApplyPostingJournalAsync_WhenApplyPostingJournalModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithApplyPostingJournalCommandWherePostingLineCollectionContainsMappedApplyPostingLinesFromApplyPostingJournalModel() { Controller sut = CreateSut(); ApplyPostingLineModel[] applyPostingLineModels = _fixture.CreateMany <ApplyPostingLineModel>(_random.Next(10, 15)).ToArray(); ApplyPostingLineCollectionModel applyPostingLineCollectionModel = CreateApplyPostingLineCollectionModel(applyPostingLineModels); await sut.ApplyPostingJournalAsync(CreateApplyPostingJournalModel(applyPostingLineCollectionModel : applyPostingLineCollectionModel)); _commandBusMock.Verify(m => m.PublishAsync <IApplyPostingJournalCommand, IPostingJournalResult>(It.Is <IApplyPostingJournalCommand>(command => command.PostingLineCollection.All(applyPostingLineCommand => applyPostingLineModels.Any(applyPostingLineModel => IsMatch(applyPostingLineCommand, applyPostingLineModel))))), Times.Once); }
protected ApplyPostingLineCollectionModel CreateApplyPostingLineCollectionModel(IEnumerable <ApplyPostingLineModel> applyPostingLineModels = null) { ApplyPostingLineCollectionModel applyPostingLineCollection = new ApplyPostingLineCollectionModel(); foreach (ApplyPostingLineModel applyPostingLineModel in applyPostingLineModels ?? Fixture.CreateMany <ApplyPostingLineModel>(Random.Next(5, 10)).ToArray()) { applyPostingLineCollection.Add(applyPostingLineModel); } return(applyPostingLineCollection); }
public IEnumerable<IApplyPostingLineCommand> Convert(ApplyPostingLineCollectionModel applyPostingLineCollectionModel, ResolutionContext context) { NullGuard.NotNull(applyPostingLineCollectionModel, nameof(applyPostingLineCollectionModel)) .NotNull(context, nameof(context)); return applyPostingLineCollectionModel .OrderBy(applyPostingLineModel => applyPostingLineModel.PostingDate.LocalDateTime.Date) .ThenBy(applyPostingLineModel => applyPostingLineModel.SortOrder ?? 0) .Select(applyPostingLineModel => context.Mapper.Map<ApplyPostingLineModel, ApplyPostingLineCommand>(applyPostingLineModel)) .ToArray(); }
protected ApplyPostingJournalModel CreateApplyPostingJournalModel(int?accountingNumber = null, ApplyPostingLineCollectionModel applyPostingLineCollectionModel = null) { return(Fixture.Build <ApplyPostingJournalModel>() .With(m => m.AccountingNumber, accountingNumber ?? Fixture.Create <int>()) .With(m => m.ApplyPostingLines, applyPostingLineCollectionModel ?? CreateApplyPostingLineCollectionModel()) .Create()); }
public Task <ActionResult <ApplyPostingJournalResultModel> > ApplyPostingJournalAsync(int accountingNumber, [FromBody] ApplyPostingLineCollectionModel applyPostingLineCollection) { if (applyPostingLineCollection == null) { throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNull, nameof(applyPostingLineCollection)) .WithValidatingType(typeof(ApplyPostingLineCollectionModel)) .WithValidatingField(nameof(applyPostingLineCollection)) .Build(); } SchemaValidator.Validate(ModelState); ApplyPostingJournalModel applyPostingJournal = new ApplyPostingJournalModel { AccountingNumber = accountingNumber, ApplyPostingLines = applyPostingLineCollection }; IApplyPostingJournalCommand applyPostingJournalCommand = _accountingModelConverter.Convert <ApplyPostingJournalModel, ApplyPostingJournalCommand>(applyPostingJournal); return(ApplyPostingJournalAsync(applyPostingJournalCommand)); }