本文整理汇总了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);
}
示例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");
}
}
示例3: HomeTests
public HomeTests()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<TestStartup>());
_client = server.CreateClient();
}
示例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");
}
}
示例5: PrimeWebCheckPrimeShould
public PrimeWebCheckPrimeShould()
{
// Arrange
_server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
示例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);
}
示例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);
}
}
示例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());
}
示例9: ClientCredentialsClient
public ClientCredentialsClient()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例10: UserInfoEndpointClient
public UserInfoEndpointClient()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例11: PictureControllerTest
public PictureControllerTest()
{
// Arrange
_server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
_client.BaseAddress = new Uri("https://localhost:44371/api/Picture/");
}
示例12: ResourceOwnerClient
public ResourceOwnerClient()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例13: IntrospectionTests
public IntrospectionTests()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例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();
}
示例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);
}