Esempio n. 1
0
        internal void GivenDisconnectMessage_WhenConnected_SendsDisconnectedToSender()
        {
            // Arrange
            var server = new MessageServerFacade(
                this.container,
                this.messagingAdapter,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            server.Start().Wait();

            var dealer = new TestDealer(
                this.container,
                this.headerSerializer,
                this.requestSerializer,
                this.responseSerializer,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress,
                "001");

            dealer.Start().Wait();

            var connect = new Connect(
                dealer.ClientId,
                "None",
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            dealer.Send(connect);
            var response1 = (Connected)dealer.Receive();

            var disconnect = new Disconnect(
                dealer.ClientId,
                response1.SessionId,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            dealer.Send(disconnect);
            var response2 = (Disconnected)dealer.Receive();

            // Assert
            Assert.Equal(typeof(Connected), response1.Type);
            Assert.Equal(typeof(Disconnected), response2.Type);
            Assert.Equal(2, server.ReceivedCount);
            Assert.Equal(2, server.SentCount);
            Assert.Equal("TestDealer-001 connected to test-server session None", response1.Message);
            Assert.Equal("TestDealer-001 disconnected from test-server session None", response2.Message);

            // Tear Down
            dealer.Stop().Wait();
            server.Stop().Wait();
            dealer.Dispose();
            server.Dispose();
        }
Esempio n. 2
0
        internal void GivenMessage_WhichIsInvalidForThisPort_RespondsWithMessageRejected()
        {
            // Arrange
            var server = new MessageServerFacade(
                this.container,
                this.messagingAdapter,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            server.Start().Wait();

            var dealer = new TestDealer(
                this.container,
                this.headerSerializer,
                this.requestSerializer,
                this.responseSerializer,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            dealer.Start().Wait();

            // Act
            dealer.SendRaw(
                Encoding.UTF8.GetBytes("WOW"),
                BitConverter.GetBytes(3),
                Encoding.UTF8.GetBytes("Payload"));

            var response = dealer.Receive();

            // Assert
            Assert.Equal(typeof(MessageRejected), response.Type);
            Assert.Equal(1, server.ReceivedCount);
            Assert.Equal(1, server.SentCount);

            // Tear Down
            dealer.Stop().Wait();
            server.Stop().Wait();
            dealer.Dispose();
            server.Dispose();
        }
Esempio n. 3
0
        internal void GivenMessage_WhichIsEmptyBytes_RespondsWithMessageRejected()
        {
            // Arrange
            var server = new MessageServerFacade(
                this.container,
                this.messagingAdapter,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            server.Start().Wait();

            var dealer = new TestDealer(
                this.container,
                this.headerSerializer,
                this.requestSerializer,
                this.responseSerializer,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            dealer.Start().Wait();

            // Act
            dealer.SendString(string.Empty);
            var response = dealer.Receive();

            // Assert
            Assert.Equal(typeof(MessageRejected), response.Type);
            Assert.Equal(1, server.ReceivedCount);
            Assert.Equal(1, server.SentCount);

            // Tear Down
            dealer.Stop().Wait();
            server.Stop().Wait();
            dealer.Dispose();
            server.Dispose();
        }
Esempio n. 4
0
        internal void GivenMultipleMessages_StoresAndSendsResponsesToCorrectSender()
        {
            // Arrange
            var server = new MessageServerFacade(
                this.container,
                this.messagingAdapter,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress);

            server.Start().Wait();

            var dealer1 = new TestDealer(
                this.container,
                this.headerSerializer,
                this.requestSerializer,
                this.responseSerializer,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress,
                "001");

            dealer1.Start().Wait();

            var dealer2 = new TestDealer(
                this.container,
                this.headerSerializer,
                this.requestSerializer,
                this.responseSerializer,
                this.compressor,
                EncryptionSettings.None(),
                this.testRequestAddress,
                this.testResponseAddress,
                "002");

            dealer2.Start().Wait();

            // Act
            var connect1 = new Connect(
                dealer1.ClientId,
                "None",
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            var connect2 = new Connect(
                dealer2.ClientId,
                "None",
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            dealer1.Send(connect1);
            dealer2.Send(connect2);
            var response1 = (Connected)dealer1.Receive();
            var response2 = (Connected)dealer2.Receive();

            // Assert
            Assert.Equal("TestDealer-001 connected to test-server session None", response1.Message);
            Assert.Equal("TestDealer-002 connected to test-server session None", response2.Message);
            Assert.Equal(2, server.ReceivedCount);
            Assert.Equal(2, server.SentCount);

            // Tear Down
            dealer1.Stop().Wait();
            dealer2.Stop().Wait();
            server.Stop().Wait();
            dealer1.Dispose();
            dealer2.Dispose();
            server.Dispose();
        }