예제 #1
0
        public async Task CaptureResponse()
        {
            // store the rest response in a subfolder of the solution directory for future use
            var captureFolder = Path.Combine(TestContext.TestRunDirectory, @"..\..\FakeResponses\");
            var handler = new CapturingHttpClientHandler(new FileSystemResponseStore(TestContext.DeploymentDirectory, captureFolder));

            using (var client = new HttpClient(handler, true))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/");
                var response = await client.GetAsync("storage/v1/b/uspto-pair");
                response.EnsureSuccessStatusCode();

                dynamic metaData = await response.Content.Deserialize<dynamic>();

                // we got a response and it looks like the one we want
                Assert.IsNotNull(metaData);
                Assert.AreEqual("https://www.googleapis.com/storage/v1/b/uspto-pair", metaData.selfLink);

                // assert we stored it where we want it to go
                var formatter = new DesktopMessagetFormatter();
                var folderPath = Path.Combine(captureFolder, formatter.ToFolderPath(response.RequestMessage.RequestUri), response.RequestMessage.Method.Method);
                Assert.IsTrue(File.Exists(folderPath + ".response.json"));
                Assert.IsTrue(File.Exists(folderPath + ".content.json"));
            }
        }
예제 #2
0
        public async Task ResponseInfoPackedCorrectly()
        {
            using (var client = new HttpClient(new HttpClientHandler(), true))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/");
                var response = await client.GetAsync("storage/v1/b/uspto-pair");
                response.EnsureSuccessStatusCode();

                var formatter = new DesktopMessagetFormatter();

                // this is the object that is serialized (response, normalized request query and pointer to the content file)
                var info = formatter.PackageResponse(response);

                Assert.IsNotNull(info);
                Assert.IsTrue(info.ContentFileName.EndsWith("json"));
            }
        }
예제 #3
0
        public async Task CreateContentFromSerializedResponse()
        {
            using (var client = new HttpClient(new HttpClientHandler(), true))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/");
                var response = await client.GetAsync("storage/v1/b/uspto-pair");
                response.EnsureSuccessStatusCode();

                var formatter = new DesktopMessagetFormatter();

                // this is the object that is serialized (response, normalized request query and pointer to the content file)
                var info = formatter.PackageResponse(response);
                var json = JsonConvert.SerializeObject(info, Formatting.Indented);

                var newInfo = JsonConvert.DeserializeObject<ResponseInfo>(json);
                var content = newInfo.CreateContent(new MemoryStream());

                Assert.AreEqual("UTF-8", content.Headers.ContentType.CharSet);
                Assert.AreEqual("application/json", content.Headers.ContentType.MediaType);
            }
        }
예제 #4
0
        public async Task RoundTripResponseInfo()
        {
            using (var client = new HttpClient(new HttpClientHandler(), true))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/");
                var response = await client.GetAsync("storage/v1/b/uspto-pair");
                response.EnsureSuccessStatusCode();

                var formatter = new DesktopMessagetFormatter();

                // this is the object that is serialized (response, normalized request query and pointer to the content file)
                var info = formatter.PackageResponse(response);

                var json = JsonConvert.SerializeObject(info, Formatting.Indented);
                var newInfo = JsonConvert.DeserializeObject<ResponseInfo>(json);

                Assert.AreEqual(info.StatusCode, newInfo.StatusCode);
                Assert.AreEqual(info.Query, newInfo.Query);
                Assert.AreEqual(info.ContentFileName, newInfo.ContentFileName);
            }
        }