本文整理汇总了C#中HostType类的典型用法代码示例。如果您正苦于以下问题:C# HostType类的具体用法?C# HostType怎么用?C# HostType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostType类属于命名空间,在下文中一共展示了HostType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstanceContext
public void InstanceContext(HostType hostType)
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
string applicationUrl = deployer.Deploy<InstanceContextStartup>(hostType);
string[] urls = new string[] { applicationUrl, applicationUrl + "/one", applicationUrl + "/two" };
bool failed = false;
foreach (string url in urls)
{
string previousResponse = null;
for (int count = 0; count < 3; count++)
{
string currentResponse = HttpClientUtility.GetResponseTextFromUrl(url);
if (!currentResponse.Contains("SUCCESS") || (previousResponse != null && currentResponse != previousResponse))
{
failed = true;
}
previousResponse = currentResponse;
}
}
Assert.True(!failed, "At least one of the instance contexts is not correct");
}
}
示例2: ApplicationPoolStop
public void ApplicationPoolStop(HostType hostType)
{
var serverInstance = new NotificationServer();
serverInstance.StartNotificationService();
try
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
string applicationUrl = deployer.Deploy(hostType, Configuration);
Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl) == "SUCCESS");
if (hostType == HostType.IIS)
{
string webConfig = deployer.GetWebConfigPath();
string webConfigContent = File.ReadAllText(webConfig);
File.WriteAllText(webConfig, webConfigContent);
}
}
bool receivedNotification = serverInstance.NotificationReceived.WaitOne(20 * 1000);
Assert.True(receivedNotification, "Cancellation token was not issued on closing host");
}
finally
{
serverInstance.Dispose();
}
}
示例3: Static_ValidIfModifiedSince
public void Static_ValidIfModifiedSince(HostType hostType)
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
var applicationUrl = deployer.Deploy(hostType, ValidModifiedSinceConfiguration);
var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) };
var fileContent = File.ReadAllBytes(@"RequirementFiles/Dir1/RangeRequest.txt");
var response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
//Modified since = lastmodified. Expect a 304
httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified;
response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode);
//Modified since > lastmodified. Expect a 304
httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified.Value.AddMinutes(12);
response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode);
//Modified since < lastmodified. Expect an OK.
httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified.Value.Subtract(new TimeSpan(10 * 1000));
response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, fileContent.Length - 1);
//Modified since is an invalid date string. Expect an OK.
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-Modified-Since", "InvalidDate");
response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
}
}
示例4: ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval
public void ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
// Test cannot be async because if we do host.ShutDown() after an await the connection stops.
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(keepAlive: 9, messageBusType: messageBusType);
var connection = CreateHubConnection(host);
using (connection)
{
var disconnectWh = new ManualResetEventSlim();
connection.Closed += () =>
{
disconnectWh.Set();
};
SetReconnectDelay(host.Transport, TimeSpan.FromSeconds(15));
connection.Start(host.Transport).Wait();
// Without this the connection start and reconnect can race with eachother resulting in a deadlock.
Thread.Sleep(TimeSpan.FromSeconds(3));
// Set reconnect window to zero so the second we attempt to reconnect we can ensure that the reconnect window is verified.
((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(0);
host.Shutdown();
Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
}
}
}
示例5: AddingToMultipleGroups
public void AddingToMultipleGroups(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize();
int max = 10;
var countDown = new CountDownRange<int>(Enumerable.Range(0, max));
var connection = new Client.Hubs.HubConnection(host.Url);
var proxy = connection.CreateHubProxy("MultGroupHub");
proxy.On<User>("onRoomJoin", user =>
{
Assert.True(countDown.Mark(user.Index));
});
connection.Start(host.Transport).Wait();
for (int i = 0; i < max; i++)
{
var user = new User { Index = i, Name = "tester", Room = "test" + i };
proxy.InvokeWithTimeout("login", user);
proxy.InvokeWithTimeout("joinRoom", user);
}
Assert.True(countDown.Wait(TimeSpan.FromSeconds(30)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));
connection.Stop();
}
}
示例6: ConnectionErrorCapturesExceptionsThrownInClientHubMethod
public void ConnectionErrorCapturesExceptionsThrownInClientHubMethod(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
var wh = new ManualResetEventSlim();
Exception thrown = new Exception(),
caught = null;
host.Initialize();
var connection = CreateHubConnection(host);
var proxy = connection.CreateHubProxy("ChatHub");
proxy.On("addMessage", () =>
{
throw thrown;
});
connection.Error += e =>
{
caught = e;
wh.Set();
};
connection.Start(host.Transport).Wait();
proxy.Invoke("Send", "");
Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
Assert.Equal(thrown, caught);
}
}
示例7: Security_ReturnUrlAndSecureCookie
public void Security_ReturnUrlAndSecureCookie(HostType hostType)
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
string applicationUrl = deployer.Deploy(hostType, ReturnUrlAndSecureCookieConfiguration);
string secureServerUri = new UriBuilder(applicationUrl) { Scheme = Uri.UriSchemeHttps }.Uri.AbsoluteUri;
HttpClientHandler handler = new HttpClientHandler();
HttpClient httpClient = new HttpClient(handler);
// Unauthenticated request - verify Redirect url
HttpResponseMessage response = httpClient.GetAsync(applicationUrl).Result;
CookiesCommon.IsRedirectedToCookiesLogin(response.RequestMessage.RequestUri, applicationUrl, "Unauthenticated requests not automatically redirected to login page", "MyRedirectUrl");
var validCookieCredentials = new FormUrlEncodedContent(new kvp[] { new kvp("username", "test"), new kvp("password", "test") });
response = httpClient.PostAsync(response.RequestMessage.RequestUri, validCookieCredentials).Result;
response.EnsureSuccessStatusCode();
//Verify cookie sent
Assert.False(handler.CookieContainer.Count != 1, "Forms auth cookie not received automatically after successful login");
Cookie loginCookie = handler.CookieContainer.GetCookies(new Uri(secureServerUri))[0];
Assert.Equal(loginCookie.Secure, true);
}
}
示例8: GetAccountTypeByHostType
public AccountTypeDB GetAccountTypeByHostType(HostType hostType)
{
DBManager db = new DBManager();
string accountTypeName = AccountTypeDB.FromTypeCodeToString(hostType);
var accountType = db.GetAccountTypeByName(accountTypeName);
return accountType;
}
示例9: SuccessiveTimeoutTest
public void SuccessiveTimeoutTest(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim(false);
host.Initialize(keepAlive: null);
var connection = CreateConnection(host, "/my-reconnect");
((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));
connection.Reconnected += () =>
{
mre.Set();
};
connection.Start(host.Transport).Wait();
// Assert that Reconnected is called
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
// Assert that Reconnected is called again
mre.Reset();
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
// Clean-up
mre.Dispose();
connection.Stop();
}
}
示例10: Static_DirectoryBrowserDefaults
public void Static_DirectoryBrowserDefaults(HostType hostType)
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
string applicationUrl = deployer.Deploy(hostType, DirectoryBrowserDefaultsConfiguration);
HttpResponseMessage response = null;
//1. Check directory browsing enabled at application level
var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response);
Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response");
Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8");
Assert.True(responseText.Contains("RequirementFiles/"));
//2. Check directory browsing @RequirementFiles with a ending '/'
responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles/", out response);
Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response");
Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8");
Assert.True(responseText.Contains("Dir1/") && responseText.Contains("Dir2/") && responseText.Contains("Dir3/"), "Directories Dir1, Dir2, Dir3 not found");
//2. Check directory browsing @RequirementFiles with request path not ending '/'
responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles", out response);
Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response");
Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8");
Assert.True(responseText.Contains("Dir1/") && responseText.Contains("Dir2/") && responseText.Contains("Dir3/"), "Directories Dir1, Dir2, Dir3 not found");
}
}
示例11: ReconnectRequestPathEndsInReconnect
public void ReconnectRequestPathEndsInReconnect(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var tcs = new TaskCompletionSource<bool>();
var receivedMessage = false;
host.Initialize(keepAlive: null,
connectionTimeout: 2,
disconnectTimeout: 6);
var connection = CreateConnection(host, "/examine-reconnect");
connection.Received += (reconnectEndsPath) =>
{
if (!receivedMessage)
{
tcs.TrySetResult(reconnectEndsPath == "True");
receivedMessage = true;
}
};
connection.Start(host.Transport).Wait();
// Wait for reconnect
Assert.True(tcs.Task.Wait(TimeSpan.FromSeconds(10)));
Assert.True(tcs.Task.Result);
// Clean-up
connection.Stop();
}
}
示例12: NetworkController
//클라이언트에서 사용할 때.
public NetworkController(string serverAddress) {
m_hostType = HostType.Client;
GameObject nObj = GameObject.Find("Network");
m_network = nObj.GetComponent<TransportTCP>();
m_network.Connect(serverAddress, USE_PORT);
}
示例13: ThrownWebExceptionShouldBeUnwrapped
public void ThrownWebExceptionShouldBeUnwrapped(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize();
var connection = new Client.Connection(host.Url + "/ErrorsAreFun");
// Expecting 404
var aggEx = Assert.Throws<AggregateException>(() => connection.Start(host.Transport).Wait());
connection.Stop();
using (var ser = aggEx.GetError())
{
if (hostType == HostType.IISExpress)
{
Assert.Equal(System.Net.HttpStatusCode.InternalServerError, ser.StatusCode);
}
else
{
Assert.Equal(System.Net.HttpStatusCode.NotFound, ser.StatusCode);
}
Assert.NotNull(ser.ResponseBody);
Assert.NotNull(ser.Exception);
}
}
}
示例14: CreateHost
protected ITestHost CreateHost(HostType hostType, TransportType transportType)
{
ITestHost host = null;
switch (hostType)
{
case HostType.IISExpress:
host = new IISExpressTestHost();
host.TransportFactory = () => CreateTransport(transportType);
host.Transport = host.TransportFactory();
break;
case HostType.Memory:
var mh = new MemoryHost();
host = new MemoryTestHost(mh);
host.TransportFactory = () => CreateTransport(transportType, mh);
host.Transport = host.TransportFactory();
break;
case HostType.Owin:
host = new OwinTestHost();
host.TransportFactory = () => CreateTransport(transportType);
host.Transport = host.TransportFactory();
break;
default:
break;
}
return host;
}
示例15: Static_ContentTypes
public void Static_ContentTypes(HostType hostType)
{
using (ApplicationDeployer deployer = new ApplicationDeployer())
{
var applicationUrl = deployer.Deploy(hostType, ContentTypesConfiguration);
var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) };
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleAVI.avi", "video/x-msvideo");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleC.c", "text/plain");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCHM.chm", "application/octet-stream");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCpp.cpp", "text/plain");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCss.CSS", "text/css");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCSV.csV", "application/octet-stream");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCUR.cur", "application/octet-stream");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleDisco.disco", "text/xml");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampledoc.doc", "application/msword");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampledocx.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleHTM.htm", "text/html");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Samplehtml.html", "text/html");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampleico.ico", "image/x-icon");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleJPEG.jpg", "image/jpeg");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleJPG.jpg", "image/jpeg");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SamplePNG.png", "image/png");
DownloadAndCompareFiles(httpClient, @"RequirementFiles\Dir1\EmptyFile.txt", "text/plain");
//Unknown MIME types should not be served by default
var response = httpClient.GetAsync(@"RequirementFiles\ContentTypes\Unknown.Unknown").Result;
Assert.Equal<HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);
}
}