Ejemplo n.º 1
0
        public async Task Should_return_multiple_assets_when_querying_assets()
        {
            var query = @"
                query {
                  queryAssets(filter: ""my-query"", top: 30, skip: 5) {
                    <FIELDS>
                  }
                }".Replace("<FIELDS>", TestAsset.AllFields);

            var asset = TestAsset.Create(appId, DomainId.NewGuid());

            A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A <Q> .That.HasOData("?$top=30&$skip=5&$filter=my-query")))
            .Returns(ResultList.CreateFrom(0, asset));

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

            var expected = new
            {
                data = new
                {
                    queryAssets = new dynamic[]
                    {
                        TestAsset.Response(asset)
                    }
                }
            };

            AssertResult(expected, result);
        }
Ejemplo n.º 2
0
        public async Task Should_return_single_asset_when_finding_asset()
        {
            var assetId = DomainId.NewGuid();
            var asset   = TestAsset.Create(appId, assetId);

            var query = @"
                query {
                  findAsset(id: ""<ID>"") {
                    <FIELDS>
                  }
                }".Replace("<ID>", assetId.ToString()).Replace("<FIELDS>", TestAsset.AllFields);

            A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A <Q> .That.HasIds(assetId)))
            .Returns(ResultList.CreateFrom(1, asset));

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

            var expected = new
            {
                data = new
                {
                    findAsset = TestAsset.Response(asset)
                }
            };

            AssertResult(expected, result);
        }
Ejemplo n.º 3
0
        public async Task Should_return_multiple_assets_if_querying_assets()
        {
            var query = CreateQuery(@"
                query {
                  queryAssets(filter: 'my-query', top: 30, skip: 5) {
                    <FIELDS_ASSET>
                  }
                }");

            var asset = TestAsset.Create(DomainId.NewGuid());

            A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null,
                                                 A <Q> .That.Matches(x => x.QueryAsOdata == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal), A <CancellationToken> ._))
            .Returns(ResultList.CreateFrom(0, asset));

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

            var expected = new
            {
                data = new
                {
                    queryAssets = new[]
                    {
                        TestAsset.Response(asset)
                    }
                }
            };

            AssertResult(expected, result);
        }
Ejemplo n.º 4
0
        public async Task Should_return_single_asset_if_finding_asset()
        {
            var assetId = DomainId.NewGuid();
            var asset   = TestAsset.Create(assetId);

            var query = CreateQuery(@"
                query {
                  findAsset(id: '<ID>') {
                    <FIELDS_ASSET>
                  }
                }", assetId);

            A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null,
                                                 A <Q> .That.HasIdsWithoutTotal(assetId), A <CancellationToken> ._))
            .Returns(ResultList.CreateFrom(1, asset));

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

            var expected = new
            {
                data = new
                {
                    findAsset = TestAsset.Response(asset)
                }
            };

            AssertResult(expected, result);
        }
Ejemplo n.º 5
0
        public async Task Should_return_multiple_assets_with_total_when_querying_assets_with_total()
        {
            var query = @"
                query {
                  queryAssetsWithTotal(filter: ""my-query"", top: 30, skip: 5) {
                    total
                    items {
                      <FIELDS>
                    }
                  }
                }".Replace("<FIELDS>", TestAsset.AllFields);

            var asset = TestAsset.Create(appId, DomainId.NewGuid());

            A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null,
                                                 A <Q> .That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal == false)))
            .Returns(ResultList.CreateFrom(10, asset));

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

            var expected = new
            {
                data = new
                {
                    queryAssetsWithTotal = new
                    {
                        total = 10,
                        items = new dynamic[]
                        {
                            TestAsset.Response(asset)
                        }
                    }
                }
            };

            AssertResult(expected, result);
        }