Beispiel #1
0
        /// <summary>
        /// This method creates a stub server (<code>server</code>).
        /// It will then create the proxy (<code>proxy</code>).
        /// Finally it issues a web request to the proxy.
        /// </summary>
        /// <param name="serverOptions">The options for the running HTTP server.</param>
        /// <param name="proxyOptions">The options for the running proxy server.</param>
        /// <param name="serverAssertion">The configuration/assertion code to run in the context of the server.</param>
        /// <param name="clientAssertion">The configuration/assertion code to run in the context of the client.</param>
        private static void ExecuteTestInContext(
            SimpleHttpServerOptions serverOptions,
            SimpleHttpServerOptions proxyOptions,
            Action <HttpListenerContext> serverAssertion,
            Action <NtlmProxy> clientAssertion)
        {
            using (var server = new SimpleHttpServer(context =>
            {
                return(new Task <HttpResponseMessage>(() =>
                {
                    var response = new HttpResponseMessage
                    {
                        Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(ExpectedResultText)))
                    };

                    if (serverAssertion != null)
                    {
                        serverAssertion(context);
                    }

                    return response;
                }));
            }, serverOptions))
            {
                var serverUri = new Uri(string.Format("http://localhost:{0}/", server.Port));
                using (var proxy = new NtlmProxy(serverUri, proxyOptions))
                {
                    clientAssertion(proxy);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method creates a stub server (<code>server</code>).
        /// It will then create the proxy (<code>proxy</code>).
        /// Finally it issues a web request to the proxy.
        /// </summary>
        /// <param name="serverOptions">The options for the running HTTP server.</param>
        /// <param name="proxyOptions">The options for the running proxy server.</param>
        /// <param name="serverAssertion">The configuration/assertion code to run in the context of the server.</param>
        /// <param name="clientAssertion">The configuration/assertion code to run in the context of the client.</param>
        private static void ExecuteTestInContext(
            SimpleHttpServerOptions serverOptions,
            SimpleHttpServerOptions proxyOptions,
            Action <HttpListenerContext> serverAssertion,
            Action <NtlmProxy> clientAssertion)
        {
            // Unfortunately I'm not familiar enough with await/async to correct the following:
            #pragma warning disable 1998
            using (var server = new SimpleHttpServer(async context =>
            #pragma warning restore 1998
            {
                var response = new HttpResponseMessage
                {
                    Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(ExpectedResultText)))
                };

                if (serverAssertion != null)
                {
                    serverAssertion(context);
                }

                return(response);
            }, serverOptions))
            {
                var serverUri = new Uri(string.Format("http://localhost:{0}/", server.Port));
                using (var proxy = new NtlmProxy(serverUri, proxyOptions))
                {
                    clientAssertion(proxy);
                }
            }
        }