Exemplo n.º 1
0
        public async Task Should_return_single_content_if_finding_content_with_version()
        {
            var contentId = DomainId.NewGuid();
            var content   = TestContent.Create(contentId);

            var query = CreateQuery(@"
                query {
                  findMySchemaContent(id: '<ID>', version: 3) {
                    <FIELDS_CONTENT>
                  }
                }", contentId);

            A.CallTo(() => contentQuery.FindAsync(MatchsContentContext(), TestSchemas.Default.Id.ToString(), contentId, 3, A <CancellationToken> ._))
            .Returns(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query });

            var expected = new
            {
                data = new
                {
                    findMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 2
0
        public async Task Should_return_single_content_if_changing_status_with_null_due_time()
        {
            var query = CreateQuery(@"
                mutation {
                  changeMySchemaContent(id: '<ID>', status: 'Published', dueTime: null, expectedVersion: 10) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query }, Permissions.AppContentsChangeStatusOwn);

            var expected = new
            {
                data = new
                {
                    changeMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <ChangeContentStatus> .That.Matches(x =>
                                                               x.ContentId == contentId &&
                                                               x.DueTime == null &&
                                                               x.ExpectedVersion == 10 &&
                                                               x.SchemaId.Equals(TestSchemas.DefaultId) &&
                                                               x.Status == Status.Published)))
            .MustHaveHappened();
        }
Exemplo n.º 3
0
        public async Task Should_return_multiple_contents_if_querying_contents()
        {
            var query = CreateQuery(@"
                query {
                  queryMySchemaContents(top: 30, skip: 5) {
                    <FIELDS_CONTENT>
                  }
                }");

            var contentId = DomainId.NewGuid();
            var content   = TestContent.Create(contentId);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), TestSchemas.Default.Id.ToString(),
                                                   A <Q> .That.Matches(x => x.QueryAsOdata == "?$top=30&$skip=5" && x.NoTotal), A <CancellationToken> ._))
            .Returns(ResultList.CreateFrom(0, content));

            var result = await ExecuteAsync(new ExecutionOptions { Query = query });

            var expected = new
            {
                data = new
                {
                    queryMySchemaContents = new[]
                    {
                        TestContent.Response(content)
                    }
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 4
0
        public async Task Should_return_single_content_if_finding_content()
        {
            var contentId = DomainId.NewGuid();
            var content   = TestContent.Create(contentId);

            var query = CreateQuery(@"
                query {
                  findMySchemaContent(id: '<ID>') {
                    <FIELDS_CONTENT>
                  }
                }", contentId);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(),
                                                   A <Q> .That.HasIdsWithoutTotal(contentId), A <CancellationToken> ._))
            .Returns(ResultList.CreateFrom(1, content));

            var result = await ExecuteAsync(new ExecutionOptions { Query = query });

            var expected = new
            {
                data = new
                {
                    findMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 5
0
        public async Task Should_publish_command_for_status_change_without_due_time()
        {
            var query = @"
                mutation {
                  changeMySchemaContent(id: ""<ID>"", status: ""Published"", expectedVersion: 10) {
                    <FIELDS>
                  }
                }".Replace("<ID>", contentId.ToString()).Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query });

            var expected = new
            {
                data = new
                {
                    changeMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <ChangeContentStatus> .That.Matches(x =>
                                                               x.ContentId == contentId &&
                                                               x.DueTime == null &&
                                                               x.ExpectedVersion == 10 &&
                                                               x.Status == Status.Published)))
            .MustHaveHappened();
        }
Exemplo n.º 6
0
        public async Task Should_return_single_content_when_creating_content()
        {
            var query = @"
                mutation {
                  createMySchemaContent(data: <DATA>, publish: true) {
                    <FIELDS>
                  }
                }".Replace("<DATA>", GetDataString()).Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await ExecuteAsync(new GraphQLQuery { Query = query }, Permissions.AppContentsCreate);

            var expected = new
            {
                data = new
                {
                    createMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <CreateContent> .That.Matches(x =>
                                                         x.SchemaId.Equals(schemaId) &&
                                                         x.ExpectedVersion == EtagVersion.Any &&
                                                         x.Publish &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 7
0
        public async Task Should_return_single_content_when_upserting_content()
        {
            var query = @"
                mutation {
                  upsertMySchemaContent(id: ""<ID>"", data: <DATA>, publish: true, expectedVersion: 10) {
                    <FIELDS>
                  }
                }".Replace("<ID>", contentId.ToString()).Replace("<DATA>", GetDataString()).Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await ExecuteAsync(new GraphQLQuery { Query = query }, Permissions.AppContentsUpsert);

            var expected = new
            {
                data = new
                {
                    upsertMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <UpsertContent> .That.Matches(x =>
                                                         x.ContentId == content.Id &&
                                                         x.ExpectedVersion == 10 &&
                                                         x.Publish &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 8
0
        public async Task Should_return_single_content_if_upserting_content()
        {
            var query = CreateQuery(@"
                mutation {
                  upsertMySchemaContent(id: '<ID>', data: <DATA>, publish: true, expectedVersion: 10) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query }, Permissions.AppContentsUpsert);

            var expected = new
            {
                data = new
                {
                    upsertMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <UpsertContent> .That.Matches(x =>
                                                         x.ContentId == content.Id &&
                                                         x.ExpectedVersion == 10 &&
                                                         x.SchemaId.Equals(TestSchemas.DefaultId) &&
                                                         x.Status == Status.Published &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 9
0
        public async Task Should_return_single_content_when_finding_content()
        {
            var contentId = DomainId.NewGuid();
            var content   = TestContent.Create(appId, schemaId, contentId, DomainId.Empty, DomainId.Empty);

            var query = @"
                query {
                  findMySchemaContent(id: ""<ID>"") {
                    <FIELDS>
                  }
                }".Replace("<FIELDS>", TestContent.AllFields).Replace("<ID>", contentId.ToString());

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIds(contentId)))
            .Returns(ResultList.CreateFrom(1, content));

            var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query });

            var expected = new
            {
                data = new
                {
                    findMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 10
0
        public async Task Should_return_multiple_contents_when_querying_contents()
        {
            var query = CreateQuery(@"
                query {
                  queryMySchemaContents(top: 30, skip: 5) {
                    <FIELDS_CONTENT>
                  }
                }");

            var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(),
                                                   A <Q> .That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == true)))
            .Returns(ResultList.CreateFrom(0, content));

            var result = await ExecuteAsync(new ExecutionOptions { Query = query });

            var expected = new
            {
                data = new
                {
                    queryMySchemaContents = new dynamic[]
                    {
                        TestContent.Response(content)
                    }
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 11
0
        public async Task Should_return_multiple_contents_when_querying_contents()
        {
            var query = @"
                query {
                  queryMySchemaContents(top: 30, skip: 5) {
                    <FIELDS>
                  }
                }".Replace("<FIELDS>", TestContent.AllFields);

            var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(), A <Q> .That.HasOData("?$top=30&$skip=5")))
            .Returns(ResultList.CreateFrom(0, content));

            var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query });

            var expected = new
            {
                data = new
                {
                    queryMySchemaContents = new dynamic[]
                    {
                        TestContent.Response(content)
                    }
                }
            };

            AssertResult(expected, result);
        }
Exemplo n.º 12
0
        public async Task Should_return_single_content_when_changing_status()
        {
            var dueTime = InstantPattern.General.Parse("2021-12-12T11:10:09Z").Value;

            var query = CreateQuery(@"
                mutation {
                  changeMySchemaContent(id: '<ID>', status: 'Published', dueTime: '2021-12-12T11:10:09Z', expectedVersion: 10) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query }, Permissions.AppContentsChangeStatusOwn);

            var expected = new
            {
                data = new
                {
                    changeMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <ChangeContentStatus> .That.Matches(x =>
                                                               x.ContentId == contentId &&
                                                               x.DueTime == dueTime &&
                                                               x.ExpectedVersion == 10 &&
                                                               x.SchemaId.Equals(schemaId) &&
                                                               x.Status == Status.Published)))
            .MustHaveHappened();
        }
Exemplo n.º 13
0
        public async Task Should_return_single_content_when_creating_content_with_variable()
        {
            var query = CreateQuery(@"
                mutation OP($data: MySchemaDataInputDto!) {
                  createMySchemaContent(data: $data, publish: true) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query, Inputs = GetInput() }, Permissions.AppContentsCreate);

            var expected = new
            {
                data = new
                {
                    createMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <CreateContent> .That.Matches(x =>
                                                         x.ExpectedVersion == EtagVersion.Any &&
                                                         x.SchemaId.Equals(schemaId) &&
                                                         x.Status == Status.Published &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 14
0
        public async Task Should_return_single_content_if_creating_content_with_custom_id()
        {
            var query = CreateQuery(@"
                mutation {
                  createMySchemaContent(data: <DATA>, id: '123', publish: true) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query }, Permissions.AppContentsCreate);

            var expected = new
            {
                data = new
                {
                    createMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <CreateContent> .That.Matches(x =>
                                                         x.ExpectedVersion == EtagVersion.Any &&
                                                         x.ContentId == DomainId.Create("123") &&
                                                         x.SchemaId.Equals(TestSchemas.DefaultId) &&
                                                         x.Status == Status.Published &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 15
0
        public async Task Should_return_single_content_when_patching_content_with_variable()
        {
            var query = @"
                mutation OP($data: MySchemaDataInputDto!) {
                  patchMySchemaContent(id: ""<ID>"", data: $data, expectedVersion: 10) {
                    <FIELDS>
                  }
                }".Replace("<ID>", contentId.ToString()).Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await ExecuteAsync(new GraphQLQuery { Query = query, Inputs = GetInput() }, Permissions.AppContentsUpdateOwn);

            var expected = new
            {
                data = new
                {
                    patchMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <PatchContent> .That.Matches(x =>
                                                        x.ContentId == content.Id &&
                                                        x.ExpectedVersion == 10 &&
                                                        x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 16
0
        public async Task Should_return_single_content_if_updating_content_with_variable()
        {
            var query = CreateQuery(@"
                mutation OP($data: MySchemaDataInputDto!) {
                  updateMySchemaContent(id: '<ID>', data: $data, expectedVersion: 10) {
                    <FIELDS>
                  }
                }");

            commandContext.Complete(content);

            var result = await ExecuteAsync(new ExecutionOptions { Query = query, Inputs = GetInput() }, Permissions.AppContentsUpdateOwn);

            var expected = new
            {
                data = new
                {
                    updateMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <UpdateContent> .That.Matches(x =>
                                                         x.ContentId == content.Id &&
                                                         x.ExpectedVersion == 10 &&
                                                         x.SchemaId.Equals(TestSchemas.DefaultId) &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 17
0
        public async Task Should_return_single_content_when_changing_status_with_null_due_time()
        {
            var query = @"
                mutation {
                  changeMySchemaContent(id: ""<ID>"", status: ""Published"", dueTime: null, expectedVersion: 10) {
                    <FIELDS>
                  }
                }".Replace("<ID>", contentId.ToString()).Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await ExecuteAsync(new GraphQLQuery { Query = query }, Permissions.AppContentsChangeStatusOwn);

            var expected = new
            {
                data = new
                {
                    changeMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <ChangeContentStatus> .That.Matches(x =>
                                                               x.ContentId == contentId &&
                                                               x.DueTime == null &&
                                                               x.ExpectedVersion == 10 &&
                                                               x.Status == Status.Published)))
            .MustHaveHappened();
        }
Exemplo n.º 18
0
        public async Task Should_return_single_content_when_creating_content_with_variable()
        {
            var query = @"
                mutation OP($data: MySchemaDataInputDto!) {
                  createMySchemaContent(data: $data, publish: true) {
                    <FIELDS>
                  }
                }".Replace("<FIELDS>", TestContent.AllFields);

            commandContext.Complete(content);

            var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query, Inputs = GetInput() });

            var expected = new
            {
                data = new
                {
                    createMySchemaContent = TestContent.Response(content)
                }
            };

            AssertResult(expected, result);

            A.CallTo(() => commandBus.PublishAsync(
                         A <CreateContent> .That.Matches(x =>
                                                         x.SchemaId.Equals(schemaId) &&
                                                         x.ExpectedVersion == EtagVersion.Any &&
                                                         x.Publish &&
                                                         x.Data.Equals(content.Data))))
            .MustHaveHappened();
        }
Exemplo n.º 19
0
        public async Task Should_return_multiple_contents_with_total_when_querying_contents_with_total()
        {
            var query = @"
                query {
                  queryMySchemaContentsWithTotal(top: 30, skip: 5) {
                    total
                    items {
                      <FIELDS>
                    }
                  }
                }".Replace("<FIELDS>", TestContent.AllFields);

            var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(),
                                                   A <Q> .That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == false)))
            .Returns(ResultList.CreateFrom(10, content));

            var result = await ExecuteAsync(new ExecutionOptions { Query = query });

            var expected = new
            {
                data = new
                {
                    queryMySchemaContentsWithTotal = new
                    {
                        total = 10,
                        items = new dynamic[]
                        {
                            TestContent.Response(content)
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }