示例#1
0
        public void TestStrongConnectionStatus()
        {
            using (StartVerifiableLog(out var loggerFactory, LogLevel.Warning, expectedErrors: e => true,
                                      logChecker: s =>
            {
                Assert.Single(s);
                Assert.Equal("EndpointOffline", s[0].Write.EventId.Name);
                return(true);
            }))
            {
                var endpoint1 = new HubServiceEndpoint();
                var conn1     = new TestServiceConnection();
                var scf       = new TestServiceConnectionFactory(endpoint1 => conn1);
                var container = new StrongServiceConnectionContainer(scf, 5, endpoint1, loggerFactory.CreateLogger(nameof(TestStrongConnectionStatus)));

                // When init, consider the endpoint as online
                // TODO: improve the logic
                Assert.True(endpoint1.Online);

                conn1.SetStatus(ServiceConnectionStatus.Connecting);
                Assert.True(endpoint1.Online);

                conn1.SetStatus(ServiceConnectionStatus.Connected);
                Assert.True(endpoint1.Online);

                conn1.SetStatus(ServiceConnectionStatus.Disconnected);
                Assert.False(endpoint1.Online);

                conn1.SetStatus(ServiceConnectionStatus.Connecting);
                Assert.False(endpoint1.Online);

                conn1.SetStatus(ServiceConnectionStatus.Connected);
                Assert.True(endpoint1.Online);
            }
        }
        public ServiceConnectionProxy(ConnectionDelegate callback = null, PipeOptions clientPipeOptions = null,
                                      Func <Func <TestConnection, Task>, TestConnectionFactory> connectionFactoryCallback = null, int connectionCount = 1)
        {
            ConnectionFactory          = connectionFactoryCallback?.Invoke(ConnectionFactoryCallbackAsync) ?? new TestConnectionFactory(ConnectionFactoryCallbackAsync);
            ClientConnectionManager    = new ClientConnectionManager();
            _clientPipeOptions         = clientPipeOptions;
            ConnectionDelegateCallback = callback ?? OnConnectionAsync;

            ServiceConnectionContainer = new StrongServiceConnectionContainer(this, ConnectionFactory, connectionCount, new ServiceEndpoint("", ""));
        }
示例#3
0
        public ServiceConnectionProxy(ConnectionDelegate callback = null, PipeOptions clientPipeOptions = null,
                                      Func <Func <TestConnection, Task>, TestConnectionFactory> connectionFactoryCallback = null, int connectionCount = 1)
        {
            ConnectionFactory          = connectionFactoryCallback?.Invoke(ConnectionFactoryCallbackAsync) ?? new TestConnectionFactory(ConnectionFactoryCallbackAsync);
            ClientConnectionManager    = new ClientConnectionManager();
            _clientPipeOptions         = clientPipeOptions;
            ConnectionDelegateCallback = callback ?? OnConnectionAsync;

            ServiceConnectionContainer = new StrongServiceConnectionContainer(this, connectionCount, new HubServiceEndpoint("", null, null), NullLogger.Instance);
            ServiceMessageHandler      = (StrongServiceConnectionContainer)ServiceConnectionContainer;
        }
        public ServiceConnectionProxy(
            ConnectionDelegate callback   = null,
            PipeOptions clientPipeOptions = null,
            Func <Func <TestConnection, Task>, TestConnectionFactory> connectionFactoryCallback = null,
            int connectionCount = 1)
        {
            ConnectionFactory          = connectionFactoryCallback?.Invoke(ConnectionFactoryCallbackAsync) ?? new TestConnectionFactory(ConnectionFactoryCallbackAsync);
            ClientConnectionManager    = new ClientConnectionManager();
            _clientPipeOptions         = clientPipeOptions;
            ConnectionDelegateCallback = callback ?? OnConnectionAsync;

            ServerNameProvider = new DefaultServerNameProvider();

            // these two lines should be located in the end of this constructor.
            ServiceConnectionContainer = new StrongServiceConnectionContainer(this, connectionCount, new HubServiceEndpoint(), NullLogger.Instance);
            ServiceMessageHandler      = (StrongServiceConnectionContainer)ServiceConnectionContainer;
        }
 public ServiceConnectionProxy(ConnectionDelegate callback             = null, PipeOptions clientPipeOptions = null,
                               TestConnectionFactory connectionFactory = null, IServiceConnectionManager serviceConnectionManager = null)
 {
     ConnectionFactory       = connectionFactory ?? new TestConnectionFactory();
     ClientConnectionManager = new ClientConnectionManager();
     _clientPipeOptions      = clientPipeOptions;
     ServiceConnection       = new ServiceConnection(
         SharedServiceProtocol,
         this,
         ConnectionFactory,
         NullLoggerFactory.Instance,
         callback ?? OnConnectionAsync,
         this,
         Guid.NewGuid().ToString("N"),
         serviceConnectionManager);
     ServiceConnectionContainer = new StrongServiceConnectionContainer(null, connectionFactory, new List <IServiceConnection>()
     {
         ServiceConnection
     }, new ServiceEndpoint("", ""));
 }