Beispiel #1
0
        public async Task SendAsync <TMessage>(TMessage message)
            where TMessage : class, new()
        {
            var xtResult = await _sendReceive.SendAsync(message);

            ThrowOnNonSuccess(xtResult);
        }
Beispiel #2
0
        public async Task Sender_Without_a_Server_returns_Endpoint_not_found_Exception(object configuration)
        {
            // Arrange
            var config = (SocketConfiguration)configuration;

            config.TimeOut = TimeSpan.FromMilliseconds(50);
            using var sut  = new SendReceive(config);
            // no server this time around

            // Act
            var xtResult = await sut.SendAsync <Message>(new Message());

            // Assert
            Assert.False(xtResult.IsSuccess);
        }
Beispiel #3
0
        public async Task Sends_With_Server_TimeOut_return_no_success(object configuration)
        {
            // Arrange
            var config = (SocketConfiguration)configuration;

            config.TimeOut = TimeSpan.FromSeconds(1);
            using var sut  = new SendReceive(config);
            // is a timeout
            sut.SetupReceiver <Message>(m => Thread.Sleep(1500));

            // Act
            var xtResult = await sut.SendAsync(new Message());

            // Assert
            Assert.False(xtResult.IsSuccess);
        }
Beispiel #4
0
        public async Task SendReceive_works()
        {
            // Arrange
            var config = new ConfigurationTestData().GetSocketConfigInProc;

            using var sut = new SendReceive(config);
            int result = -1;

            sut.SetupReceiver <Message>(m => result = m.Number);

            // Act
            await sut.SendAsync(new Message { Number = 42 });

            // Assert
            Assert.Equal(42, result);
        }
Beispiel #5
0
        public async Task Exception_propagation_when_server_response_Throws_to_Requester()
        {
            var ipc = new ConfigurationTestData().GetSocketConfigInProc;

            using var sut = new SendReceive(ipc);
            sut.SetupReceiver <Message>(r =>
            {
                throw new ArgumentException("this is a unit test proving the exception propagation works");
            });

            // Act
            var result = await sut.SendAsync <Message>(new Message());

            // Assert
            Assert.False(result.IsSuccess);
            Assert.NotNull(result.Exception);
            Assert.Contains("ArgumentException", result.Exception.Message);
            Assert.StartsWith("Server failed with" + Environment.NewLine + "ArgumentException", result.Exception.Message);
        }
Beispiel #6
0
        public async Task AsyncSendAndReceive()
        {
            // Arrange
            var ipc = new ConfigurationTestData().GetSocketConfigInProc;

            using var sut = new SendReceive(ipc);
            var result = -1;

            sut.SetupReceiverAsync <Message>(r =>
            {
                result = r.Number;
                return(Task.CompletedTask);
            });

            // Act
            var xtResult = await sut.SendAsync(new Message { Number = 2 });

            // Assert
            Assert.True(xtResult.IsSuccess);
            Assert.Equal(2, result);
        }