コード例 #1
0
        public async Task TestCanSearchAssetsAsync()
        {
            const string endpointUrl = "https://cdn.contentful.com/spaces/spaceId/assets/?skip=0&limit=10",
                         assetId     = "123456789";
            const int skip           = 0,
                      limit          = 10;
            var cancellationToken    = new CancellationToken();
            var mockHttpWrapper      = new Mock <IHttpClientWrapper>();

            mockHttpWrapper.Setup(m => m.GetAsync(endpointUrl, cancellationToken))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{ skip: 0, limit: 10, items: [ { sys: { \"id\": \"123456789\" } } ] }")
            });
            var client  = new ContentfulClient("spaceId", mockHttpWrapper.Object);
            var results = await client.SearchAsync <Asset>(cancellationToken, new ISearchFilter[]
            {
                new SkipSearchFilter(skip),
                new LimitSearchFilter(limit)
            });

            Assert.IsNotNull(results);
            Assert.AreEqual(skip, results.Skip);
            Assert.AreEqual(limit, results.Limit);
            Assert.IsTrue(results.Items.Any());
            var asset = results.Items.First();

            Assert.AreEqual(assetId, asset.SystemProperties.Id);
        }
コード例 #2
0
 public async Task TestCanSearchAssetsAsync()
 {
     const string endpointUrl = "https://cdn.contentful.com/spaces/spaceId/assets/?skip=0&limit=10",
         assetId = "123456789";
     const int skip = 0,
         limit = 10;
     var cancellationToken = new CancellationToken();
     var mockHttpWrapper = new Mock<IHttpClientWrapper>();
     mockHttpWrapper.Setup(m => m.GetAsync(endpointUrl, cancellationToken))
         .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
         {
             Content = new StringContent("{ skip: 0, limit: 10, items: [ { sys: { \"id\": \"123456789\" } } ] }")
         });
     var client = new ContentfulClient("spaceId", mockHttpWrapper.Object);
     var results = await client.SearchAsync<Asset>(cancellationToken, new ISearchFilter[]
     {
         new SkipSearchFilter(skip), 
         new LimitSearchFilter(limit)
     });
     Assert.IsNotNull(results);
     Assert.AreEqual(skip, results.Skip);
     Assert.AreEqual(limit, results.Limit);
     Assert.IsTrue(results.Items.Any());
     var asset = results.Items.First();
     Assert.AreEqual(assetId, asset.SystemProperties.Id);
 }