Esempio n. 1
0
        public static void AssemblyInitialize(TestContext context)
        {
            // set the http message handler factory to the mode we want for the entire assmebly test execution
            MessageHandlerFactory.Mode = MessageHandlerMode.Fake;

            // setup IOC so test classes can get the shared message handler
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            // responses are in a ziparchive that is also referenced by the DeploymentItem attributes
            var resources = new ZipResources(Path.Combine(context.DeploymentDirectory, "FakeResponses.zip"));

            SimpleIoc.Default.Register(() => MessageHandlerFactory.CreateMessageHandler(resources));
        }
Esempio n. 2
0
        public async Task ZipMinimalExampleTest()
        {
            using (var resources = new ZipResources(Path.Combine(TestContext.DeploymentDirectory, "FakeResponses.zip")))
            {
                var handler = new FakeHttpMessageHandler(resources);
                using (var client = new HttpClient(handler, true))
                {
                    client.BaseAddress = new Uri("https://www.example.com/");
                    var response = await client.GetAsync("HelloWorldService");

                    response.EnsureSuccessStatusCode();

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

                    Assert.IsNotNull(content);
                    Assert.AreEqual("Hello World", content.Message);
                }
            }
        }
Esempio n. 3
0
        public async Task ZipCanGetSimpleJsonResult()
        {
            using (var resources = new ZipResources(Path.Combine(TestContext.DeploymentDirectory, "FakeResponses.zip")))
            {
                var handler = new FakeHttpMessageHandler(resources);
                using (var client = new HttpClient(handler, true))
                {
                    client.BaseAddress = new Uri("http://openstates.org/api/v1/");
                    string key = CredentialStore.RetrieveObject("sunlight.key.json").Key;
                    client.DefaultRequestHeaders.Add("X-APIKEY", key);

                    var response = await client.GetAsync("metadata/mn");

                    response.EnsureSuccessStatusCode();

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

                    Assert.IsNotNull(result);
                    Assert.AreEqual("Minnesota", result.name);
                }
            }
        }