public async Task MyMiddleware_Should_Set_RequestHeader_And_ResponseHeader()
    {
        //Arrange
        var cookieStore = new Dictionary <string, string> {
            { "cookie-name", "cookie-value" }
        };
        var cookies     = new RequestCookieCollection(cookieStore);
        var request     = Mock.Of <IOwinRequest>();
        var requestMock = Mock.Get(request);

        requestMock.Setup(_ => _.Cookies).Returns(cookies);
        requestMock.Setup(_ => _.User.Identity.IsAuthenticated).Returns(true);
        requestMock.Setup(_ => _.Headers.Append(It.IsAny <string>(), It.IsAny <string>()));
        var response    = new OwinResponse();
        var context     = Mock.Of <OwinContext>();
        var contextMock = Mock.Get(context);

        contextMock.CallBase = true;
        contextMock.Setup(_ => _.Request).Returns(request);
        contextMock.Setup(_ => _.Response).Returns(response);
        RequestDelegate next         = _ => Task.FromResult((object)null);
        var             myMiddleware = new MyMiddleware(next);
        //Act
        await myMiddleware.Invoke(context);

        //Assert
        requestMock.Verify(_ => _.Headers.Append("header-name", "header-value"));
        response.Headers.ContainsKey("Set-Cookie");
    }
예제 #2
0
        public void Setup()
        {
            inner = Substitute.For <Transport>();

            GameObject gameObject = new GameObject();

            middleware       = gameObject.AddComponent <MyMiddleware>();
            middleware.inner = inner;
        }
예제 #3
0
        public void Setup()
        {
            inner = Substitute.For <Transport>();

            GameObject gameObject = new GameObject();

            middleware       = gameObject.AddComponent <MyMiddleware>();
            middleware.inner = inner;
            //manually call awake in editmode
            middleware.Awake();
        }
예제 #4
0
        IMiddleware IMiddlewareFactory.Create(Type middlewareType)
        {
            AssertNotDisposed();

            if (middlewareType != typeof(MyMiddleware))
            {
                throw new InvalidOperationException("Unknown middleware type");
            }

            var scopedDependency = NewScopedDependency();
            var middleware       =
                new MyMiddleware(
                    _singletonDependency,
                    scopedDependency);

            RegisterScopedDependencyForDispose(middleware, scopedDependency);
            return(middleware);
        }