private void RegisterApplicationComponents(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            // Register application services
            container.RegisterMvcControllers(app);
            container.RegisterMvcViewComponents(app);

            container.Register <IUserService, AspNetUserService>(Lifestyle.Scoped);
            container.Register <CustomMiddleware>();

            // Cross-wire required framework services
            container.RegisterSingleton <Func <IViewBufferScope> >(() => AspNetCoreExtensions.GetRequestService <IViewBufferScope>(app));
            container.RegisterSingleton(loggerFactory);

            container.Verify();
        }
Exemplo n.º 2
0
        public void GetRequestUri(string scheme, string host, int?port, string pathBase, string path, string queryString)
        {
            // Given
            if (scheme != null)
            {
                httpRequest.Setup(x => x.Scheme).Returns(scheme);
            }
            if (host != null)
            {
                httpRequest.Setup(x => x.Host).Returns(new HostString(host, port ?? 80));
            }
            if (pathBase != null)
            {
                httpRequest.Setup(x => x.PathBase).Returns(pathBase);
            }
            if (path != null)
            {
                httpRequest.Setup(x => x.Path).Returns(path);
            }
            if (queryString != null)
            {
                httpRequest.Setup(x => x.QueryString).Returns(new QueryString(queryString));
            }

            // When
            string uri = AspNetCoreExtensions.GetRequestUri(httpRequest.Object);

            // Then
            string expected = string.Concat(
                scheme,
                (scheme != null ? "://" : ""),
                host,
                (port != null) ? $":{port}" : "",
                pathBase,
                path,
                queryString
                );
            string obtained = uri;

            Assert.Equal(expected, obtained);
        }