Example #1
0
        public void Does_cache_MemoryStream_HttpResult_Responses_preserving_ContentType()
        {
            CacheStream.Count = 0;
            var request = new CacheStream {
                Id = 1, Value = "foo"
            };

            var response = Config.ListeningOn.CombineWith(request.ToGetUrl())
                           .GetStringFromUrl(responseFilter: res =>
            {
                Assert.That(res.ContentType, Does.StartWith(MimeTypes.Jsv));
                Assert.That(res.Headers[HttpHeaders.CacheControl], Is.Null);
            })
                           .FromJsv <CacheStream>();

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

            response = Config.ListeningOn.CombineWith(request.ToGetUrl())
                       .GetStringFromUrl(responseFilter: res =>
            {
                Assert.That(res.ContentType, Does.StartWith(MimeTypes.Jsv));
                Assert.That(res.Headers[HttpHeaders.CacheControl], Is.Null);
            })
                       .FromJsv <CacheStream>();

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

            var client = new JsvServiceClient(Config.ListeningOn);

            response = client.Get <CacheStream>(request);
            Assert.That(CacheStream.Count, Is.EqualTo(1));
            AssertEquals(response, request);
        }
Example #2
0
        public object Any(CacheStream request)
        {
            Interlocked.Increment(ref CacheStream.Count);

            var jsv   = request.ToJsv();
            var bytes = jsv.ToUtf8Bytes();
            var ms    = bytes.InMemoryStream();

            return(ms);
        }