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; }
public override bool Execute() { try { var myHost = new IISExpressTestHost(HostLocation[0].ToString()); myHost.Initialize(keepAlive: 2, connectionTimeout: 120, disconnectTimeout: 10, hearbeatInterval: 1, enableAutoRejoiningGroups: false); } catch (WebException ex) { var response = ex.Response; if (response == null) { Log.LogError(ex.ToString()); throw; } using (response) { using (var sr = new StreamReader(response.GetResponseStream())) { Log.LogError(sr.ReadToEnd()); throw; } } } catch (Exception ex) { Log.LogError(ex.ToString()); throw; } return true; }
protected ITestHost CreateHost(HostType hostType, TransportType transportType) { ITestHost host = null; switch (hostType) { case HostType.IISExpress: host = new IISExpressTestHost(); host.Transport = CreateTransport(transportType); break; case HostType.Memory: var mh = new MemoryHost(); host = new MemoryTestHost(mh); host.Transport = CreateTransport(transportType, mh); break; default: break; } return(host); }
protected ITestHost CreateHost(HostType hostType, TransportType transportType) { string testName = GetTestName() + "." + hostType + "." + transportType + "." + Interlocked.Increment(ref _id); ITestHost host = null; string logBasePath = Path.Combine(Directory.GetCurrentDirectory(), ".."); switch (hostType) { case HostType.IISExpress: host = new IISExpressTestHost(testName); host.TransportFactory = () => CreateTransport(transportType); host.Transport = host.TransportFactory(); break; case HostType.Memory: var mh = new MemoryHost(); host = new MemoryTestHost(mh, Path.Combine(logBasePath, testName)); 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; } var writer = CreateClientTraceWriter(testName); host.ClientTraceOutput = writer; if (hostType != HostType.Memory) { string clientNetworkPath = Path.Combine(logBasePath, testName + ".client.network.log"); host.Disposables.Add(SystemNetLogging.Enable(clientNetworkPath)); string httpSysTracePath = Path.Combine(logBasePath, testName + ".httpSys"); IDisposable httpSysTracing = StartHttpSysTracing(httpSysTracePath); // If tracing is enabled then turn it off on host dispose if (httpSysTracing != null) { host.Disposables.Add(httpSysTracing); } } TraceListener traceListener = EnableTracing(testName, logBasePath); host.Disposables.Add(new DisposableAction(() => { traceListener.Close(); Trace.Listeners.Remove(traceListener); })); EventHandler<UnobservedTaskExceptionEventArgs> handler = (sender, args) => { Trace.TraceError("Unobserved task exception: " + args.Exception.GetBaseException()); args.SetObserved(); }; TaskScheduler.UnobservedTaskException += handler; host.Disposables.Add(new DisposableAction(() => { TaskScheduler.UnobservedTaskException -= handler; })); return host; }
protected ITestHost CreateHost(HostType hostType, TransportType transportType) { string testName = GetTestName() + "." + hostType + "." + transportType + "." + Interlocked.Increment(ref _id); ITestHost host = null; string logBasePath = Path.Combine(Directory.GetCurrentDirectory(), ".."); switch (hostType) { case HostType.IISExpress: host = new IISExpressTestHost(testName); host.TransportFactory = () => CreateTransport(transportType); host.Transport = host.TransportFactory(); break; case HostType.Memory: var mh = new MemoryHost(); host = new MemoryTestHost(mh, Path.Combine(logBasePath, testName)); 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; } var writer = CreateClientTraceWriter(testName); host.ClientTraceOutput = writer; if (hostType != HostType.Memory) { string clientNetworkPath = Path.Combine(logBasePath, testName + ".client.network.log"); host.Disposables.Add(SystemNetLogging.Enable(clientNetworkPath)); string httpSysTracePath = Path.Combine(logBasePath, testName + ".httpSys"); IDisposable httpSysTracing = StartHttpSysTracing(httpSysTracePath); // If tracing is enabled then turn it off on host dispose if (httpSysTracing != null) { host.Disposables.Add(httpSysTracing); } } TraceListener traceListener = EnableTracing(testName, logBasePath); host.Disposables.Add(new DisposableAction(() => { traceListener.Close(); Trace.Listeners.Remove(traceListener); })); EventHandler <UnobservedTaskExceptionEventArgs> handler = (sender, args) => { Trace.TraceError("Unobserved task exception: " + args.Exception.GetBaseException()); args.SetObserved(); }; TaskScheduler.UnobservedTaskException += handler; host.Disposables.Add(new DisposableAction(() => { TaskScheduler.UnobservedTaskException -= handler; })); return(host); }
public void FallbackToLongPollingIIS() { using (ITestHost host = new IISExpressTestHost()) { host.Initialize(); var connection = CreateConnection(host.Url + "/fall-back"); var tcs = new TaskCompletionSource<object>(); connection.StateChanged += change => { if (change.NewState == ConnectionState.Reconnecting) { tcs.TrySetException(new Exception("The connection should not be reconnecting")); } }; var client = new DefaultHttpClient(); var transports = new IClientTransport[] { new ServerSentEventsTransport(client) { ConnectionTimeout = TimeSpan.Zero }, new LongPollingTransport(client) }; var transport = new AutoTransport(client, transports); connection.Start(transport).Wait(); Assert.Equal(connection.Transport.Name, "longPolling"); Assert.False(tcs.Task.Wait(TimeSpan.FromSeconds(5))); connection.Stop(); } }