Esempio n. 1
0
        public async Task Should_return_multiple_flat_contents_when_querying_contents()
        {
            const string query = @"
                query {
                  queryMySchemaContents(top: 30, skip: 5) {
                    id
                    version
                    created
                    createdBy
                    lastModified
                    lastModifiedBy
                    status
                    statusColor
                    url
                    flatData {
                      myString
                      myNumber
                      myBoolean
                      myDatetime
                      myJsonValue: myJson(path: ""value"")
                      myJson
                      myGeolocation
                      myTags
                      myLocalized
                      myArray {
                        nestedNumber
                        nestedBoolean
                      }
                    }
                  }
                }";

            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[]
                    {
                        new
                        {
                            id             = content.Id,
                            version        = 1,
                            created        = content.Created,
                            createdBy      = "subject:user1",
                            lastModified   = content.LastModified,
                            lastModifiedBy = "subject:user2",
                            status         = "DRAFT",
                            statusColor    = "red",
                            url            = $"contents/my-schema/{content.Id}",
                            flatData       = new
                            {
                                myString    = "value",
                                myNumber    = 1,
                                myBoolean   = true,
                                myDatetime  = content.LastModified,
                                myJsonValue = 1,
                                myJson      = new
                                {
                                    value = 1
                                },
                                myGeolocation = new
                                {
                                    latitude  = 10,
                                    longitude = 20
                                },
                                myTags = new[]
                                {
                                    "tag1",
                                    "tag2"
                                },
                                myLocalized = "de-DE",
                                myArray     = new[]
                                {
                                    new
                                    {
                                        nestedNumber  = 10,
                                        nestedBoolean = true
                                    },
                                    new
                                    {
                                        nestedNumber  = 20,
                                        nestedBoolean = false
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }
Esempio n. 2
0
        public async Task Should_also_fetch_union_contents_when_field_is_included_in_query()
        {
            var contentRefId = DomainId.NewGuid();
            var contentRef   = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1");

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

            var query = CreateQuery(@"
                query {
                  findMySchemaContent(id: '<ID>') {
                    id
                    data {
                      myUnion {
                        iv {
                          ... on Content {
                            id
                          }
                          ... on MyRefSchema1 {
                            data {
                              ref1Field {
                                iv
                              }
                            }
                          }
                          __typename
                        }
                      }
                    }
                  }
                }", contentId);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId)))
            .Returns(ResultList.CreateFrom(0, contentRef));

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

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

            var expected = new
            {
                data = new
                {
                    findMySchemaContent = new
                    {
                        id   = content.Id,
                        data = new
                        {
                            myUnion = new
                            {
                                iv = new[]
                                {
                                    new
                                    {
                                        id   = contentRefId,
                                        data = new
                                        {
                                            ref1Field = new
                                            {
                                                iv = "ref1"
                                            }
                                        },
                                        __typename = "MyRefSchema1"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }
Esempio n. 3
0
        public async Task Should_also_fetch_referencing_contents_with_total_when_field_is_included_in_query()
        {
            var contentRefId = DomainId.NewGuid();
            var contentRef   = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1");

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

            var query = CreateQuery(@"
                query {
                  findMyRefSchema1Content(id: '<ID>') {
                    id
                    referencingMySchemaContentsWithTotal(top: 30, skip: 5) {
                      total
                      items {
                        id
                        data {
                          myString {
                            de
                          }
                        }
                      }
                    }
                  }
                }", contentRefId);

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId)))
            .Returns(ResultList.CreateFrom(1, contentRef));

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

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

            var expected = new
            {
                data = new
                {
                    findMyRefSchema1Content = new
                    {
                        id = contentRefId,
                        referencingMySchemaContentsWithTotal = new
                        {
                            total = 1,
                            items = new[]
                            {
                                new
                                {
                                    id   = contentId,
                                    data = new
                                    {
                                        myString = new
                                        {
                                            de = "value"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }
Esempio n. 4
0
        public async Task Should_also_fetch_union_contents_when_field_is_included_in_query()
        {
            var contentRefId = DomainId.NewGuid();
            var contentRef   = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1");

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

            var query = @"
                query {
                  findMySchemaContent(id: ""<ID>"") {
                    id
                    data {
                      myUnion {
                        iv {
                          ... on Content {
                            id
                          }
                          ... on MyRefSchema1 {
                            data {
                              ref1Field {
                                iv
                              }
                            }
                          }
                          __typename
                        }
                      }
                    }
                  }
                }".Replace("<ID>", contentId.ToString());

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <IReadOnlyList <DomainId> > ._))
            .Returns(ResultList.CreateFrom(0, contentRef));

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), MatchId(contentId)))
            .Returns(ResultList.CreateFrom(1, content));

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

            var expected = new
            {
                data = new
                {
                    findMySchemaContent = new
                    {
                        id   = content.Id,
                        data = new
                        {
                            myUnion = new
                            {
                                iv = new[]
                                {
                                    new
                                    {
                                        id   = contentRefId,
                                        data = new
                                        {
                                            ref1Field = new
                                            {
                                                iv = "ref1"
                                            }
                                        },
                                        __typename = "MyRefSchema1"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }
Esempio n. 5
0
        public async Task Should_also_fetch_referencing_contents_with_total_when_field_is_included_in_query()
        {
            var contentRefId = DomainId.NewGuid();
            var contentRef   = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1");

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

            var query = @"
                query {
                  findMyRefSchema1Content(id: ""<ID>"") {
                    id
                    referencingMySchemaContentsWithTotal(top: 30, skip: 5) {
                      total
                      items {
                        id
                        data {
                          myString {
                            de
                          }
                        }
                      }
                    }
                  }
                }".Replace("<ID>", contentRefId.ToString());

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

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

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

            var expected = new
            {
                data = new
                {
                    findMyRefSchema1Content = new
                    {
                        id = contentRefId,
                        referencingMySchemaContentsWithTotal = new
                        {
                            total = 1,
                            items = new[]
                            {
                                new
                                {
                                    id   = contentId,
                                    data = new
                                    {
                                        myString = new
                                        {
                                            de = "value"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }
Esempio n. 6
0
        public async Task Should_also_fetch_referenced_contents_when_field_is_included_in_query()
        {
            var contentRefId = DomainId.NewGuid();
            var contentRef   = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1");

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

            var query = @"
                query {
                  findMySchemaContent(id: ""<ID>"") {
                    id
                    data {
                      myReferences {
                        iv {
                          id
                          data {
                            ref1Field {
                              iv
                            }
                          }
                        }
                      }
                    }
                  }
                }".Replace("<ID>", contentId.ToString());

            A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> ._))
            .Returns(ResultList.CreateFrom(0, contentRef));

            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 = new
                    {
                        id   = content.Id,
                        data = new
                        {
                            myReferences = new
                            {
                                iv = new[]
                                {
                                    new
                                    {
                                        id   = contentRefId,
                                        data = new
                                        {
                                            ref1Field = new
                                            {
                                                iv = "ref1"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }