public async Task Should_upsert_content_with_random_id_if_query_returns_no_result() { var(_, data, query) = CreateTestData(false); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Upsert, Data = data, Query = query } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId != default && x.Exception == null)); A.CallTo(() => commandBus.PublishAsync( A <UpsertContent> .That.Matches(x => x.Data == data && x.ContentId.ToString().Length == 36))) .MustHaveHappenedOnceExactly(); }
public async Task Should_delete_content() { var(id, _, _) = CreateTestData(false); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Delete, Id = id } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId == id)); A.CallTo(() => commandBus.PublishAsync( A <DeleteContent> .That.Matches(x => x.ContentId == id))) .MustHaveHappened(); }
public async Task Should_throw_exception_when_content_id_to_delete_cannot_be_resolved() { var(_, _, query) = CreateTestData(true); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Delete, Query = query } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId == null && x.Exception is DomainObjectNotFoundException)); A.CallTo(() => commandBus.PublishAsync(A <ICommand> ._)) .MustNotHaveHappened(); }
public async Task Should_throw_exception_when_query_resolves_multiple_contents() { var(id, data, query) = CreateTestData(true); A.CallTo(() => contentQuery.QueryAsync(requestContext, A <string> ._, A <Q> .That.Matches(x => x.JsonQuery == query))) .Returns(ResultList.CreateFrom(2, CreateContent(id), CreateContent(id))); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Upsert, Data = data, Query = query } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId == null && x.Exception is DomainException)); A.CallTo(() => commandBus.PublishAsync(A <ICommand> ._)) .MustNotHaveHappened(); }
public async Task Should_upsert_content_with_custom_id() { var(id, data, query) = CreateTestData(true); A.CallTo(() => contentQuery.QueryAsync(requestContext, A <string> ._, A <Q> .That.Matches(x => x.JsonQuery == query))) .Returns(ResultList.CreateFrom(1, CreateContent(id))); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Upsert, Data = data, Query = query } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId != default && x.Exception == null)); A.CallTo(() => commandBus.PublishAsync( A <UpsertContent> .That.Matches(x => x.Data == data && x.ContentId == id))) .MustHaveHappenedOnceExactly(); }
public async Task Should_upsert_content_when_id_defined() { var(id, data, _) = CreateTestData(false); var command = new BulkUpdateContents { Jobs = new[] { new BulkUpdateJob { Type = BulkUpdateType.Upsert, Data = data, Id = id } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId != default && x.Exception == null)); A.CallTo(() => commandBus.PublishAsync( A <UpsertContent> .That.Matches(x => x.Data == data && x.ContentId == id))) .MustHaveHappenedOnceExactly(); }
public async Task Should_do_nothing_if_jobs_is_null() { var command = new BulkUpdateContents(); var result = await PublishAsync(command); Assert.Empty(result); }
private sealed record BulkTask( ICommandBus Bus, string Schema, int JobIndex, BulkUpdateJob CommandJob, BulkUpdateContents Command, ConcurrentBag <BulkUpdateResultItem> Results ) { }
public async Task Should_do_nothing_if_jobs_is_empty() { var command = new BulkUpdateContents { Jobs = Array.Empty <BulkUpdateJob>() }; var result = await PublishAsync(command); Assert.Empty(result); }
public async Task Should_do_nothing_if_jobs_is_null() { var command = new BulkUpdateContents(); var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); Assert.True(context.PlainResult is BulkUpdateResult); }
public async Task Should_do_nothing_if_jobs_is_empty() { var command = new BulkUpdateContents { Jobs = Array.Empty <BulkUpdateJob>() }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); Assert.True(context.PlainResult is BulkUpdateResult); }
public async Task Should_do_nothing_if_jobs_is_null() { var command = new BulkUpdateContents(); var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); Assert.True(context.PlainResult is BulkUpdateResult); A.CallTo(() => serviceProvider.GetService(A <Type> ._)) .MustNotHaveHappened(); }
public async Task Should_import_contents_when_query_returns_no_result() { var(_, data, query) = CreateTestData(false); var domainObject = A.Fake <ContentDomainObject>(); A.CallTo(() => serviceProvider.GetService(typeof(ContentDomainObject))) .Returns(domainObject); var command = new BulkUpdateContents { Jobs = new List <BulkUpdateJob> { new BulkUpdateJob { Type = BulkUpdateType.Upsert, Data = data, Query = query } }, SchemaId = schemaId }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); var result = context.Result <BulkUpdateResult>(); Assert.Single(result); Assert.Equal(1, result.Count(x => x.ContentId != default && x.Exception == null)); A.CallTo(() => domainObject.ExecuteAsync(A <CreateContent> .That.Matches(x => x.Data == data))) .MustHaveHappenedOnceExactly(); A.CallTo(() => domainObject.Setup(A <Guid> ._)) .MustHaveHappenedOnceExactly(); }