Exemplo n.º 1
0
        public async Task <object> Any(ServerCacheOnlyAsync request)
        {
            await Task.Yield();

            Interlocked.Increment(ref ServerCacheOnlyAsync.Count);
            return(request);
        }
Exemplo n.º 2
0
        public async Task Does_cache_duplicate_requests_async()
        {
            ServerCacheOnlyAsync.Count = 0;
            var request = new ServerCacheOnlyAsync {
                Id = 1, Value = "foo"
            };

            var response = (await Config.ListeningOn.CombineWith(request.ToGetUrl())
                            .GetJsonFromUrlAsync(responseFilter: res =>
            {
                Assert.That(res.GetHeader(HttpHeaders.ContentType), Does.StartWith(MimeTypes.Json));
                Assert.That(res.GetHeader(HttpHeaders.CacheControl), Is.Null);
            }))
                           .FromJson <ServerCacheOnlyAsync>();

            Assert.That(ServerCacheOnlyAsync.Count, Is.EqualTo(1));
            AssertEquals(response, request);

            response = (await Config.ListeningOn.CombineWith(request.ToGetUrl())
                        .GetJsonFromUrlAsync(responseFilter: res =>
            {
                Assert.That(res.GetHeader(HttpHeaders.ContentType), Does.StartWith(MimeTypes.Json));
                Assert.That(res.GetHeader(HttpHeaders.CacheControl), Is.Null);
            }))
                       .FromJson <ServerCacheOnlyAsync>();

            Assert.That(ServerCacheOnlyAsync.Count, Is.EqualTo(1));
            AssertEquals(response, request);

            var client = CreateClient();

            response = await client.GetAsync <ServerCacheOnlyAsync>(request);

            Assert.That(ServerCacheOnlyAsync.Count, Is.EqualTo(1));
            AssertEquals(response, request);
        }