public void GetOwinEnvironment_ReturnsSetEnvironment()
        {
            var request = new HttpRequestMessage();
            var environment = new Dictionary<string, object>();
            request.SetOwinEnvironment(environment);

            Assert.Equal(environment, request.GetOwinEnvironment());
        }
        public void GetOwinResponse_ReturnsResponseForOwinEnvironment()
        {
            // Arrange
            IDictionary<string, object> expectedEnvironment = new Dictionary<string, object>();

            using (HttpRequestMessage request = new HttpRequestMessage())
            {
                request.SetOwinEnvironment(expectedEnvironment);

                // Act
                OwinResponse response = request.GetOwinResponse();

                // Assert
                Assert.Same(expectedEnvironment, response.Environment);
            }
        }
 private static HttpRequestMessage CreateRequestWithOwinEnvironment(IDictionary<string, object> environment)
 {
     HttpRequestMessage request = new HttpRequestMessage();
     request.SetOwinEnvironment(environment);
     return request;
 }
        private static void MapRequestProperties(HttpRequestMessage request, IDictionary<string, object> environment, string requestPathBase)
        {
            // Set the environment on the request
            request.SetOwinEnvironment(environment);

            // Set the virtual path root for link resolution and link generation to work
            // OWIN spec requires request path base to be either the empty string or start with "/"
            request.SetVirtualPathRoot(requestPathBase.Length == 0 ? "/" : requestPathBase);

            // Set a delegate to get the client certificate
            request.Properties[HttpPropertyKeys.RetrieveClientCertificateDelegateKey] = new Func<HttpRequestMessage, X509Certificate2>(
                req =>
                {
                    X509Certificate2 clientCertificate;
                    return environment.TryGetValue<X509Certificate2>(OwinConstants.ClientCertifiateKey, out clientCertificate) ? clientCertificate : null;
                });

            // Set a lazily-evaluated way of determining whether the request is local or not
            Lazy<bool> isLocal = new Lazy<bool>(() =>
                {
                    bool local;
                    if (environment.TryGetValue(OwinConstants.IsLocalKey, out local))
                    {
                        return local;
                    }
                    return false;
                }, isThreadSafe: false);
            request.Properties[HttpPropertyKeys.IsLocalKey] = isLocal;
        }
        public void GetOwinContext_ReturnsOwinContext_AfterSetContextEnvironment()
        {
            // Arrange
            var request = new HttpRequestMessage();
            var environment = new Dictionary<string, object>();
            request.SetOwinEnvironment(environment);

            // Act
            IOwinContext context = request.GetOwinContext();

            // Assert
            Assert.IsType<OwinContext>(context);
            Assert.Same(environment, context.Environment);
        }
        public void GetOwinEnvironment_ReturnsSetEnvironmentInstance()
        {
            // Arrange
            var request = new HttpRequestMessage();
            var environment = new Dictionary<string, object>();
            request.SetOwinEnvironment(environment);

            // Act & Assert
            Assert.Same(environment, request.GetOwinEnvironment());
        }