Esempio n. 1
0
        public async Task Method()
        {
            var httpHandler     = new MockHttpHandler();
            var responseHandler = new MockResponseHandler <object>();

            var endpoint = new HttpApiEndpoint(null, "path/to/api", HttpMethod.Get, new Dictionary <string, IHttpArgumentHandler>(), responseHandler, Enumerable.Empty <HttpHeader>());
            await endpoint.Call(httpHandler, "http://localhost", new Dictionary <string, object>());

            Assert.AreEqual(HttpMethod.Get, httpHandler.Request.Method);
        }
Esempio n. 2
0
        public async Task HeadersProvider()
        {
            var httpHandler     = new MockHttpHandler();
            var responseHandler = new MockResponseHandler <object>();

            var headersProvider = new MockApiInstrumenter();

            headersProvider.Headers.Add(new HttpHeader("key", "value"));

            var endpoint = new HttpApiEndpoint(null, "path/to/api", HttpMethod.Get, new Dictionary <string, IHttpArgumentHandler>(), responseHandler, Enumerable.Empty <HttpHeader>());
            await endpoint.Call(httpHandler, "http://localhost", new Dictionary <string, object>(), headersProvider.InstrumentCall);

            var header = httpHandler.Request.Headers.Single();

            Assert.AreEqual("key", header.Name);
            Assert.AreEqual("value", header.Values.Single());
        }
Esempio n. 3
0
        public async Task ArgumentProvider()
        {
            var httpHandler     = new MockHttpHandler();
            var responseHandler = new MockResponseHandler <string>(x => x.Headers.Single(y => y.Name == "name").Values.Single());

            var endpoint = new HttpApiEndpoint(
                null,
                "path/to/api",
                HttpMethod.Get,
                new Dictionary <string, IHttpArgumentHandler>
            {
                { "name", new HttpHeaderArgumentHandler(DefaultTypeConverter.Create()) }
            },
                responseHandler,
                Enumerable.Empty <HttpHeader>());
            var response = await endpoint.Call(httpHandler, "http://localhost", new Dictionary <string, object> {
                ["name"] = "value"
            });

            Assert.AreEqual("value", response);
        }