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


C# TestServer.CreateClient方法代码示例

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


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

示例1: 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

示例2: 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

示例3: HomeTests

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

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

示例4: 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

示例5: PrimeWebCheckPrimeShould

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

示例6: 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

示例7: 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

示例8: 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

示例9: ClientCredentialsClient

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

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

示例10: UserInfoEndpointClient

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

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

示例11: PictureControllerTest

 public PictureControllerTest()
 {
     // Arrange
     _server = new TestServer(TestServer.CreateBuilder()
         .UseStartup<Startup>());
     _client = _server.CreateClient();
     _client.BaseAddress = new Uri("https://localhost:44371/api/Picture/");
 }
开发者ID:s165519,项目名称:ASPNET5Examples,代码行数:8,代码来源:PictureControllerTests.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: IntrospectionTests

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

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

示例14: BaseControllerTest

        public BaseControllerTest()
        {
            _server = new TestServer(TestServer.CreateBuilder()
                .UseStartup<Startup>());
            _server.BaseAddress = new Uri("http://localhost:5000");
            _client = _server.CreateClient();

            _serviceProvider = new ServiceCollection().BuildServiceProvider();
        }
开发者ID:CWISoftware,项目名称:accounts,代码行数:9,代码来源:BaseControllerTest.cs

示例15: CanHostMvc

 public async Task CanHostMvc()
 {
     var server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());
     var client = server.CreateClient();
     var res = await client.GetAsync("/api/Resources");
     Assert.Equal(HttpStatusCode.OK, res.StatusCode);
     var body = await res.Content.ReadAsStringAsync();
     Assert.Equal("Hello Web!", body);
 }
开发者ID:pmhsfelix,项目名称:AspNet5Mvc6FactsAndSamples,代码行数:9,代码来源:MvcSimpleTest.cs


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