本文整理汇总了C#中TestServer类的典型用法代码示例。如果您正苦于以下问题:C# TestServer类的具体用法?C# TestServer怎么用?C# TestServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestServer类属于命名空间,在下文中一共展示了TestServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: XForwardedForDefaultSettingsChangeRemoteIpAndPort
public async Task XForwardedForDefaultSettingsChangeRemoteIpAndPort()
{
var assertsExecuted = false;
var builder = new WebHostBuilder()
.Configure(app =>
{
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor
});
app.Run(context =>
{
Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString());
Assert.Equal(9090, context.Connection.RemotePort);
// No Original set if RemoteIpAddress started null.
Assert.False(context.Request.Headers.ContainsKey("X-Original-For"));
// Should have been consumed and removed
Assert.False(context.Request.Headers.ContainsKey("X-Forwarded-For"));
assertsExecuted = true;
return Task.FromResult(0);
});
});
var server = new TestServer(builder);
var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.Add("X-Forwarded-For", "11.111.111.11:9090");
await server.CreateClient().SendAsync(req);
Assert.True(assertsExecuted);
}
开发者ID:aspnet,项目名称:BasicMiddleware,代码行数:30,代码来源:ForwardedHeadersMiddlewareTest.cs
示例2: MiddlewareRejectsRequestIfTokenHeaderIsMissing
public async Task MiddlewareRejectsRequestIfTokenHeaderIsMissing()
{
var assertsExecuted = false;
var builder = new WebHostBuilder()
.UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/")
.UseIISIntegration()
.Configure(app =>
{
app.Run(context =>
{
var auth = context.Features.Get<IHttpAuthenticationFeature>();
Assert.Null(auth);
assertsExecuted = true;
return Task.FromResult(0);
});
});
var server = new TestServer(builder);
var req = new HttpRequestMessage(HttpMethod.Get, "");
var response = await server.CreateClient().SendAsync(req);
Assert.False(assertsExecuted);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
开发者ID:aspnet,项目名称:IISIntegration,代码行数:26,代码来源:IISMiddlewareTests.cs
示例3: HelloWorldMiddlewareTest
static HelloWorldMiddlewareTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<HelloWorldMiddleware.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:7,代码来源:HelloWorldMiddlewareTest.cs
示例4: ResetPasswordTests
public ResetPasswordTests(ITestOutputHelper output) {
_output = output;
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
_sender = _server.Host.Services.GetService<ISmsSender>() as Sender;
}
开发者ID:xyting,项目名称:RigoFunc.Account,代码行数:7,代码来源:ResetPasswordTests.cs
示例5: BufferResponseWithManualContentLength_NotReplaced
public async Task BufferResponseWithManualContentLength_NotReplaced()
{
var builder = new WebHostBuilder()
.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:aspnet,项目名称:BasicMiddleware,代码行数:26,代码来源:ResponseBufferingMiddlewareTests.cs
示例6: PrimeWebDefaultRequestShould
public PrimeWebDefaultRequestShould()
{
// Arrange
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
开发者ID:ColinDabritz,项目名称:Docs,代码行数:7,代码来源:PrimeWebDefaultRequestShould.cs
示例7: InnerServiceNotAvailableOutsideIsolation
public async Task InnerServiceNotAvailableOutsideIsolation() {
// Arrange
var builder = new WebHostBuilder()
.Configure(app => {
app.Isolate(
// Configure the isolated pipeline.
map => { },
// Configure the isolated services.
services => services.AddSingleton(new ValueService("Dummy")));
app.Run(async context => {
var service = context.RequestServices.GetService<ValueService>();
await context.Response.WriteAsync(service?.Value ?? "<null>");
});
});
var server = new TestServer(builder);
var client = server.CreateClient();
// Act
var response = await client.GetStringAsync("/");
// Assert
Assert.Equal("<null>", response);
}
开发者ID:aspnet-contrib,项目名称:AspNet.Hosting.Extensions,代码行数:28,代码来源:HostingExtensionsTests.cs
示例8: LargeContentMiddlewareTest
static LargeContentMiddlewareTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<LargeContentMiddleware.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:7,代码来源:LargeContentMiddlewareTest.cs
示例9: SetUp
public void SetUp()
{
api = new TestDuoApi(test_ikey, test_skey, test_host);
srv = new TestServer(test_ikey, test_skey);
srvThread = new Thread(srv.Run);
srvThread.Start();
}
开发者ID:ChrisGrishaw,项目名称:duo_api_csharp,代码行数:7,代码来源:ApiCallTest.cs
示例10: MiddlewareSkippedIfTokenIsMissing
public async Task MiddlewareSkippedIfTokenIsMissing()
{
var assertsExecuted = false;
var builder = new WebHostBuilder()
.UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/")
.UseIISIntegration()
.Configure(app =>
{
app.Run(context =>
{
var auth = context.Features.Get<IHttpAuthenticationFeature>();
Assert.Null(auth);
assertsExecuted = true;
return Task.FromResult(0);
});
});
var server = new TestServer(builder);
var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
var response = await server.CreateClient().SendAsync(req);
Assert.True(assertsExecuted);
response.EnsureSuccessStatusCode();
}
开发者ID:aspnet,项目名称:IISIntegration,代码行数:26,代码来源:IISMiddlewareTests.cs
示例11: LargeStaticViewTest
static LargeStaticViewTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<LargeStaticView.Startup>();
builder.UseProjectOf<LargeStaticView.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:8,代码来源:LargeStaticViewTest.cs
示例12: BlockchainInvestmentsApiRequestTest
public BlockchainInvestmentsApiRequestTest()
{
// Arrange
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
testMessage = "TestAPI";
}
开发者ID:rafaelturon,项目名称:blockchain-investments,代码行数:8,代码来源:BlockchainInvestmentsApiRequestTest.cs
示例13: GamePlatformTests
public GamePlatformTests()
{
var currentPath = PlatformServices.Default.Application.ApplicationBasePath;
var applicationPath = Path.GetFullPath(Path.Combine(currentPath, "../../../../TeammateOnlineApi"));
server = new TestServer(new WebHostBuilder().UseContentRoot(applicationPath).UseEnvironment("Testing").UseStartup<Startup>());
client = server.CreateClient();
}
开发者ID:thors1982,项目名称:TeammateOnlineApi,代码行数:8,代码来源:GamePlatformTests.cs
示例14: HelloWorldMvcTest
static HelloWorldMvcTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<HelloWorldMvc.Startup>();
builder.UseProjectOf<HelloWorldMvc.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:8,代码来源:HelloWorldMvcTest.cs
示例15: SetupInMemoryHost
public void SetupInMemoryHost()
{
_server = new TestServer(
new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>());
_client = _server.CreateClient();
}
开发者ID:ChrisAnn,项目名称:Speakr.WebApp,代码行数:8,代码来源:InMemoryTests.cs
示例16: MediumApiTest
static MediumApiTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<MediumApi.Startup>();
builder.UseProjectOf<MediumApi.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:8,代码来源:MediumApiTest.cs
示例17: BigViewsTest
static BigViewsTest()
{
var builder = new WebHostBuilder();
builder.UseStartup<BigViews.Startup>();
builder.UseProjectOf<BigViews.Startup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
}
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:8,代码来源:BigViewsTest.cs
示例18: GetServerByIndex
private TestServer GetServerByIndex(int index)
{
TestServer[] servers = new TestServer[0];
if (!m_Servers.TryGetValue(m_Config, out servers))
return null;
return servers[index];
}
开发者ID:xxjeng,项目名称:nuxleus,代码行数:9,代码来源:SocketServerTest.cs
示例19: CanConnect
public void CanConnect()
{
using( TestServer server = new TestServer( "TestServer", 9000 ) )
{
server.Start();
object obj = Activator.GetObject( typeof(TestRunner), ServerUtilities.MakeUrl("TestServer", 9000) );
Assert.IsNotNull( obj, "Unable to connect" );
}
}
开发者ID:taoxiease,项目名称:asegrp,代码行数:9,代码来源:TestServerTests.cs
示例20: CustomGrantClient
public CustomGrantClient()
{
var builder = new WebHostBuilder()
.UseStartup<Startup>();
var server = new TestServer(builder);
_handler = server.CreateHandler();
_client = server.CreateClient();
}
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:9,代码来源:CustomGrantClient.cs
注:本文中的TestServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论