本文整理汇总了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");
}
}
示例2: PrimeWebCheckPrimeShould
public PrimeWebCheckPrimeShould()
{
// Arrange
_server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
示例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");
}
}
示例4: DatabaseTestBase
protected DatabaseTestBase()
{
// Arrange
Server = new TestServer(
TestServer.CreateBuilder()
.UseStartup<TestStartup>());
}
示例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);
}
示例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());
}
}
示例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());
}
示例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);
}
示例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);
}
}
示例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);
}
示例11: HomeTests
public HomeTests()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<TestStartup>());
_client = server.CreateClient();
}
示例12: ResourceOwnerClient
public ResourceOwnerClient()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例13: IntegrationTestBase
protected IntegrationTestBase()
{
ServerUrl = new Uri("http://localhost");
_runningServer = TestServer.Create(Configure, ConfigureServices);
ClientConfiguration = new ClientConfiguration();
HttpMessageHandler handler = _runningServer.CreateHandler();
ClientConfiguration.HttpMessageHandler = handler;
}
示例14: IntrospectionTests
public IntrospectionTests()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}
示例15: ClientCredentialsClient
public ClientCredentialsClient()
{
var server = new TestServer(TestServer.CreateBuilder()
.UseStartup<Startup>());
_handler = server.CreateHandler();
_client = server.CreateClient();
}