Пример #1
0
        public async Task Send_Command_And_Receive_Response_With_Success()
        {
            //Arrange
            var commandId       = Guid.NewGuid().ToString();
            var commandResponse = new Command
            {
                Id     = commandId,
                Status = CommandStatus.Success,
            };

            OnDemandClientChannel.IsEstablished.Returns(true);

            OnDemandClientChannel.ProcessCommandAsync(null, CancellationToken.None).ReturnsForAnyArgs(commandResponse);
            await MessagingHubConnection.ConnectAsync();

            //Act
            var result = await MessagingHubSender.SendCommandAsync(new Command { Id = commandId }, CancellationToken.None);

            await Task.Delay(TIME_OUT);

            //Assert
            result.ShouldNotBeNull();
            result.Status.ShouldBe(CommandStatus.Success);
            result.Id.ShouldBe(commandId);
        }
Пример #2
0
        public async Task Start_Then_Stop_Should_Finish_OnDemandClientChannel()
        {
            //Arrange
            await MessagingHubConnection.ConnectAsync();

            // Act
            await MessagingHubConnection.DisconnectAsync();

            // Assert
            OnDemandClientChannel.ReceivedWithAnyArgs(1).FinishAsync(CancellationToken.None).Wait();
        }
        public async Task Add_MessageReceiver_And_Process_Message_With_Success()
        {
            //Arrange
            MessagingHubListener.AddMessageReceiver(_messageReceiver);
            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            //Act
            DispatchMessage();
            await Task.Delay(TIME_OUT);

            //Assert
            _messageReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }
        public async Task Add_CommandReceiver_And_Process_Command_With_Success()
        {
            //Arrange
            MessagingHubListener.AddCommandReceiver(_commandReceiver);
            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            //Act
            DispatchCommand();
            await Task.Delay(TIME_OUT);

            //Assert
            Assert.AreEqual(CommandStatus.Pending, _someCommand.Status);
            _commandReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }
        public async Task Add_Multiple_CommandReceivers_With_Different_Filters_And_Process_Command_With_Success()
        {
            //Arrange
            var otherCommandReceiver = Substitute.For <ICommandReceiver>();

            MessagingHubListener.AddCommandReceiver(_commandReceiver, c => Task.FromResult(c.Uri.Equals(_someCommand.Uri)));
            MessagingHubListener.AddCommandReceiver(otherCommandReceiver, c => Task.FromResult(c.Uri.Equals(new LimeUri("lime://test/message"))));

            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            //Act
            DispatchCommand();
            await Task.Delay(TIME_OUT);

            //Assert
            _commandReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
            otherCommandReceiver.DidNotReceiveWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }
        public async Task Add_Multiple_CommandReceivers_And_Process_Command_With_Success()
        {
            //Arrange
            var otherCommandReceiver = Substitute.For <ICommandReceiver>();

            MessagingHubListener.AddCommandReceiver(_commandReceiver);
            MessagingHubListener.AddCommandReceiver(otherCommandReceiver);

            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            //Act
            DispatchCommand();
            await Task.Delay(TIME_OUT);

            //Assert
            _commandReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
            otherCommandReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }
        public async Task Add_CommandReceiver_Process_Command_And_Stop_With_Success()
        {
            //Arrange
            MessagingHubListener.AddCommandReceiver(_commandReceiver);

            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            DispatchCommand();
            await Task.Delay(TIME_OUT);

            //Act
            await MessagingHubListener.StopAsync();

            await MessagingHubConnection.DisconnectAsync();

            //Assert
            _commandReceiver.ReceivedWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }
        public async Task Add_CommandReceiver_And_Send_Command_ResponseFailure_Should_Not_Process()
        {
            //Arrange
            MessagingHubListener.AddCommandReceiver(_commandReceiver);
            await MessagingHubConnection.ConnectAsync();

            await MessagingHubListener.StartAsync();

            //Act
            CommandProducer.Add(new Command
            {
                Id       = EnvelopeId.NewId(),
                Method   = CommandMethod.Get,
                Resource = new Contact(),
                Uri      = new LimeUri("lime://test/command"),
                Status   = CommandStatus.Failure
            });
            await Task.Delay(TIME_OUT);

            //Assert
            _commandReceiver.DidNotReceiveWithAnyArgs().ReceiveAsync(null, CancellationToken.None);
        }