Exemplo n.º 1
0
        /// <summary>
        /// Initializes common resources.
        /// </summary>
        /// <param name="container">The composition container.</param>
        protected void EtpSetUp(IContainer container)
        {
            _container = container;

            // Clean up any remaining resources
            _client?.Dispose();
            _server?.Dispose();

            // Get next available port number
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var port = ((IPEndPoint)listener.LocalEndpoint).Port;

            listener.Stop();

            // Update EtpServerUrl setting
            var uri = new Uri(TestSettings.EtpServerUrl);
            var url = TestSettings.EtpServerUrl.Replace($":{uri.Port}", $":{port}");

            // Create server and client instances
            _server = CreateServer(port);
            _client = InitClient(CreateClient(url));

            // Resolve dependencies early to avoid object disposed
            var streaming = container.Resolve <IChannelStreamingProducer>();
            var discovery = container.Resolve <IDiscoveryStore>();
            var store     = container.Resolve <IStoreStore>();

            // Register server handlers
            _server.Register(() => streaming);
            _server.Register(() => discovery);
            _server.Register(() => store);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes common resources.
        /// </summary>
        /// <param name="webSocketType">The WebSocket type.</param>
        /// <param name="etpSubProtocol">The ETP websocket sub-protocol</param>
        protected void SetUpWithProxy(WebSocketType webSocketType, string etpSubProtocol)
        {
            // Clean up any remaining resources
            _client?.Dispose();
            _server?.Dispose();

            var proxiedServer = CreateServer(webSocketType);

            _server = new EtpSelfHostedProxyWebServer(GetAvailablePort(), proxiedServer);

            // Use hostname so .NET will connect through the proxy.
            var uri = new UriBuilder(proxiedServer.Uri.Scheme, "vcap.me", proxiedServer.Uri.Port, proxiedServer.Uri.AbsolutePath, proxiedServer.Uri.Query).Uri;

            _client = CreateClient(webSocketType, etpSubProtocol, uri.ToWebSocketUri().ToString());
        }