Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }
Пример #4
0
        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();
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }
Пример #7
0
        public async Task Should_do_nothing_if_jobs_is_null()
        {
            var command = new BulkUpdateContents();

            var result = await PublishAsync(command);

            Assert.Empty(result);
        }
Пример #8
0
 private sealed record BulkTask(
     ICommandBus Bus,
     string Schema,
     int JobIndex,
     BulkUpdateJob CommandJob,
     BulkUpdateContents Command,
     ConcurrentBag <BulkUpdateResultItem> Results
     )
 {
 }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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();
        }
Пример #13
0
        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();
        }