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(); }
internal void Given1000Messages_StoresAndSendsResponsesToSenderInOrder() { // 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(); // Act for (var i = 0; i < 1000; i++) { var request = new DataRequest( new Dictionary <string, string> { { "Payload", $"TEST-{i}" } }, Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); dealer.Send(request); dealer.Receive(); } // Assert Assert.Equal(1000, server.ReceivedMessages.Count); Assert.Equal(1000, server.ReceivedCount); Assert.Equal(1000, server.SentCount); Assert.Equal("TEST-999", server.ReceivedMessages[^ 1].Query.FirstOrDefault().Value);
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(); }