当前位置: 首页>>代码示例>>C#>>正文


C# TestHost.TestServer类代码示例

本文整理汇总了C#中Microsoft.AspNet.TestHost.TestServer的典型用法代码示例。如果您正苦于以下问题:C# TestServer类的具体用法?C# TestServer怎么用?C# TestServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestServer类属于Microsoft.AspNet.TestHost命名空间,在下文中一共展示了TestServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDefaultCultureInfoIfCultureKeysAreMissing

        public async void GetDefaultCultureInfoIfCultureKeysAreMissing()
        {
            var builder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseRequestLocalization(new RequestLocalizationOptions
                    {
                        DefaultRequestCulture = new RequestCulture("en-US")
                    });
                    app.Run(context =>
                    {
                        var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
                        var requestCulture = requestCultureFeature.RequestCulture;
                        Assert.Equal("en-US", requestCulture.Culture.Name);
                        Assert.Equal("en-US", requestCulture.UICulture.Name);
                        return Task.FromResult(0);
                    });
                });

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();
                var response = await client.GetAsync("/page");
            }
        }
开发者ID:leloulight,项目名称:Localization,代码行数:25,代码来源:QueryStringRequestCultureProviderTest.cs

示例2: PrimeWebCheckPrimeShould

 public PrimeWebCheckPrimeShould()
 {
     // Arrange
     _server = new TestServer(TestServer.CreateBuilder()
         .UseStartup<Startup>());
     _client = _server.CreateClient();
 }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:7,代码来源:PrimeWebCheckPrimeShould.cs

示例3: GetCultureInfoFromQueryString

        public async void GetCultureInfoFromQueryString()
        {
            var builder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseRequestLocalization(new RequestLocalizationOptions
                    {
                        DefaultRequestCulture = new RequestCulture("en-US"),
                        SupportedCultures = new List<CultureInfo>
                        {
                            new CultureInfo("ar-SA")
                        },
                        SupportedUICultures = new List<CultureInfo>
                        {
                            new CultureInfo("ar-YE")
                        }
                    });
                    app.Run(context =>
                    {
                        var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
                        var requestCulture = requestCultureFeature.RequestCulture;
                        Assert.Equal("ar-SA", requestCulture.Culture.Name);
                        Assert.Equal("ar-YE", requestCulture.UICulture.Name);
                        return Task.FromResult(0);
                    });
                });

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();
                var response = await client.GetAsync("/page?culture=ar-SA&ui-culture=ar-YE");
            }
        }
开发者ID:leloulight,项目名称:Localization,代码行数:33,代码来源:QueryStringRequestCultureProviderTest.cs

示例4: DatabaseTestBase

 protected DatabaseTestBase()
 {
     // Arrange
     Server = new TestServer(
         TestServer.CreateBuilder()
             .UseStartup<TestStartup>());
 }
开发者ID:Sirikon,项目名称:HealthClinic.biz,代码行数:7,代码来源:DatabaseTestBase.cs

示例5: CustomServiceProviderSetsApplicationServices

 public async Task CustomServiceProviderSetsApplicationServices()
 {
     var builder = new WebApplicationBuilder().UseStartup<CustomContainerStartup>();
     var server = new TestServer(builder);
     string result = await server.CreateClient().GetStringAsync("/path");
     Assert.Equal("ApplicationServicesEqual:True", result);
 }
开发者ID:leloulight,项目名称:Hosting,代码行数:7,代码来源:TestServerTests.cs

示例6: CorsRequest_MatchPolicy_SetsResponseHeaders

        public async Task CorsRequest_MatchPolicy_SetsResponseHeaders()
        {
            // Arrange
            var appBuilder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseCors(builder =>
                        builder.WithOrigins("http://localhost:5001")
                               .WithMethods("PUT")
                               .WithHeaders("Header1")
                               .WithExposedHeaders("AllowedHeader"));
                    app.Run(async context =>
                    {
                        await context.Response.WriteAsync("Cross origin response");
                    });
                })
                .ConfigureServices(services => services.AddCors());

            using (var server = new TestServer(appBuilder))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/")
                    .AddHeader(CorsConstants.Origin, "http://localhost:5001")
                    .SendAsync("PUT");

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal(2, response.Headers.Count());
                Assert.Equal("Cross origin response", await response.Content.ReadAsStringAsync());
                Assert.Equal("http://localhost:5001", response.Headers.GetValues(CorsConstants.AccessControlAllowOrigin).FirstOrDefault());
                Assert.Equal("AllowedHeader", response.Headers.GetValues(CorsConstants.AccessControlExposeHeaders).FirstOrDefault());
            }
        }
开发者ID:leloulight,项目名称:CORS,代码行数:34,代码来源:CorsMiddlewareTests.cs

示例7: BufferResponseWithManualContentLength_NotReplaced

        public async Task BufferResponseWithManualContentLength_NotReplaced()
        {
            var builder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseResponseBuffering();
                    app.Run(async context =>
                    {
                        context.Response.ContentLength = 12;
                        Assert.False(context.Response.HasStarted);
                        Assert.True(context.Response.Body.CanSeek);
                        await context.Response.WriteAsync("Hello World");
                        Assert.False(context.Response.HasStarted);
                        Assert.True(context.Response.Body.CanSeek);
                    });
                });
            var server = new TestServer(builder);

            var response = await server.CreateClient().GetAsync("");
            response.EnsureSuccessStatusCode();
            Assert.Equal("Hello World", await response.Content.ReadAsStringAsync());

            IEnumerable<string> values;
            Assert.True(response.Content.Headers.TryGetValues("Content-Length", out values));
            Assert.Equal("12", values.FirstOrDefault());
        }
开发者ID:leloulight,项目名称:BasicMiddleware,代码行数:26,代码来源:ResponseBufferingMiddlewareTests.cs

示例8: AuthorizeEndpointTestBase

 public AuthorizeEndpointTestBase()
 {
     _mockPipeline = new MockAuthorizationPipeline(Clients, Scopes, Users);
     _server = TestServer.Create(null, _mockPipeline.Configure, _mockPipeline.ConfigureServices);
     _browser = new Browser(_server.CreateHandler());
     _client = new HttpClient(_browser);
 }
开发者ID:haoas,项目名称:IdentityServer4,代码行数:7,代码来源:AuthorizeEndpointTestBase.cs

示例9: GetFallbackLanguage_ReturnsFromSupportedCulture_AcceptLanguageListContainsSupportedCultures

        public async void GetFallbackLanguage_ReturnsFromSupportedCulture_AcceptLanguageListContainsSupportedCultures()
        {
            var builder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseRequestLocalization(new RequestLocalizationOptions
                    {
                        DefaultRequestCulture = new RequestCulture("fr-FR"),
                        SupportedCultures = new List<CultureInfo>
                        {
                            new CultureInfo("ar-SA"),
                            new CultureInfo("en-US")
                        }
                    });
                    app.Run(context =>
                    {
                        var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
                        var requestCulture = requestCultureFeature.RequestCulture;
                        Assert.Equal("ar-SA", requestCulture.Culture.Name);
                        return Task.FromResult(0);
                    });
                });

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();
                client.DefaultRequestHeaders.AcceptLanguage.ParseAdd("en-GB,ar-SA,en-US");
                var count = client.DefaultRequestHeaders.AcceptLanguage.Count;
                var response = await client.GetAsync(string.Empty);
            }
        }
开发者ID:leloulight,项目名称:Localization,代码行数:31,代码来源:AcceptLanguageHeaderRequestCultureProviderTest.cs

示例10: XForwardedForOverrideBadIpDoesntChangeRemoteIp

        public async Task XForwardedForOverrideBadIpDoesntChangeRemoteIp()
        {
            var assertsExecuted = false;

            var builder = new WebApplicationBuilder()
                .Configure(app =>
                {
                    app.UseOverrideHeaders(new OverrideHeaderOptions
                    {
                        ForwardedOptions = ForwardedHeaders.XForwardedFor
                    });
                    app.Run(context =>
                    {
                        Assert.Null(context.Connection.RemoteIpAddress);
                        assertsExecuted = true;
                        return Task.FromResult(0);
                    });
                });
            var server = new TestServer(builder);

            var req = new HttpRequestMessage(HttpMethod.Get, "");
            req.Headers.Add("X-Forwarded-For", "BAD-IP");
            await server.CreateClient().SendAsync(req);
            Assert.True(assertsExecuted);
        }
开发者ID:leloulight,项目名称:BasicMiddleware,代码行数:25,代码来源:OverrideHeaderMiddlewareTest.cs

示例11: HomeTests

        public HomeTests()
        {
            var server = new TestServer(TestServer.CreateBuilder()
                .UseStartup<TestStartup>());

            _client = server.CreateClient();
        }
开发者ID:mdymel,项目名称:AspNetCoreRazorTests,代码行数:7,代码来源:HomeTests.cs

示例12: ResourceOwnerClient

        public ResourceOwnerClient()
        {
            var server = new TestServer(TestServer.CreateBuilder()
                                .UseStartup<Startup>());

            _handler = server.CreateHandler();
            _client = server.CreateClient();
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:8,代码来源:ResourceOwnerClient.cs

示例13: IntegrationTestBase

 protected IntegrationTestBase()
 {
     ServerUrl = new Uri("http://localhost");
     _runningServer = TestServer.Create(Configure, ConfigureServices);
     ClientConfiguration = new ClientConfiguration();
     HttpMessageHandler handler = _runningServer.CreateHandler();
     ClientConfiguration.HttpMessageHandler = handler;
 }
开发者ID:geffzhang,项目名称:Bolt,代码行数:8,代码来源:IntegrationTestBase.cs

示例14: IntrospectionTests

        public IntrospectionTests()
        {
            var server = new TestServer(TestServer.CreateBuilder()
                                .UseStartup<Startup>());

            _handler = server.CreateHandler();
            _client = server.CreateClient();
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:8,代码来源:IntrospectionTests.cs

示例15: ClientCredentialsClient

        public ClientCredentialsClient()
        {
            var server = new TestServer(TestServer.CreateBuilder()
                                .UseStartup<Startup>());

            _handler = server.CreateHandler();
            _client = server.CreateClient();
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:8,代码来源:ClientCredentialsClient.cs


注:本文中的Microsoft.AspNet.TestHost.TestServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。