Пример #1
0
        public async Task ConnectedEvent_SetsDisconnectError_ConnectToThrows()
        {
            var disconnectError = new Error {
                error_code = 100, message = "Go away!"
            };

            SimpleInMemListener listener = (SimpleInMemListener)transport.MakeListener(address);

            listener.Connected += (sender, args) =>
            {
                args.DisconnectError = disconnectError;
            };

            await listener.StartAsync();

            try
            {
                await transport.ConnectToAsync(address);

                Assert.Fail("Expected an exception to be thrown, but one wasn't.");
            }
            catch (SimpleInMemProtocolErrorException ex)
            {
                Assert.AreSame(disconnectError, ex.Details);
            }
        }
Пример #2
0
        public async Task DefaultSetup(IService service, int count)
        {
            transport = transportBuilder.Construct();
            listener = (SimpleInMemListener)transport.MakeListener(address);
            listener.AddService(service);
            await listener.StartAsync();

            connections = new SimpleInMemConnection[count];

            for (int connectionIndex = 0; connectionIndex < count; connectionIndex++)
            {
                connections[connectionIndex] = (SimpleInMemConnection)await transport.ConnectToAsync(address, System.Threading.CancellationToken.None);
                Assert.IsTrue(connections[connectionIndex].IsConnected);
                Assert.IsTrue(connections[connectionIndex].IsPaired);
            }
        }
        public async Task DefaultSetup(IService service, int count)
        {
            transport = transportBuilder.Construct();
            listener  = (SimpleInMemListener)transport.MakeListener(address);
            listener.AddService(service);
            await listener.StartAsync();

            connections = new SimpleInMemConnection[count];

            for (int connectionIndex = 0; connectionIndex < count; connectionIndex++)
            {
                connections[connectionIndex] = (SimpleInMemConnection)await transport.ConnectToAsync(address, System.Threading.CancellationToken.None);

                Assert.IsTrue(connections[connectionIndex].IsConnected);
                Assert.IsTrue(connections[connectionIndex].IsPaired);
            }
        }
Пример #4
0
        public void AddRemoveService()
        {
            SimpleInMemListener listener = (SimpleInMemListener)transport.MakeListener(address);

            listener.AddService <CalculatorService>(service);

            foreach (var serviceMethod in service.Methods)
            {
                Assert.True(listener.IsRegistered($"{serviceMethod.MethodName}"));
            }

            Assert.False(listener.IsRegistered("Divide"));
            listener.RemoveService <CalculatorService>(service);

            foreach (var serviceMethod in service.Methods)
            {
                Assert.False(listener.IsRegistered($"{serviceMethod.MethodName}"));
            }
            Assert.False(listener.IsRegistered("Divide"));
        }
Пример #5
0
        public async Task ConnectedEvent_HasRightRemoteEndpointDetails()
        {
            SimpleInMemConnection listenerConnection = null;
            var connectedEventDone = new ManualResetEventSlim(initialState: false);

            SimpleInMemListener listener = (SimpleInMemListener)transport.MakeListener(address);

            listener.Connected += (sender, args) =>
            {
                Assert.AreSame(listener, sender);
                listenerConnection = (SimpleInMemConnection)args.Connection;
                connectedEventDone.Set();
            };

            await listener.StartAsync();

            var connection = (SimpleInMemConnection)await transport.ConnectToAsync(address);

            bool wasSignaled = connectedEventDone.Wait(TimeSpan.FromSeconds(30));

            Assert.IsTrue(wasSignaled, "Timed out waiting for Connected event to complete");

            Assert.AreEqual(connection.Id, listenerConnection.Id);
        }