System.Collections.Concurrent.BlockingCollection.Add(Lime.Protocol.Command)

Here are the examples of the csharp api class System.Collections.Concurrent.BlockingCollection.Add(Lime.Protocol.Command) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

1. Example

Project: lime-csharp
Source File: ChannelListenerTests.cs
[Fact]
        public async Task Start_MultipleCommandsReceived_CallsConsumer()
        {
            // Arrange
            var commands = new List<Command>();
            var count = Dummy.CreateRandomInt(100) + 2;
            for (int i = 0; i < count; i++)
            {
                commands.Add(
                    Dummy.CreateCommand());
            }
            var target = GetAndStartTarget();

            // Act
            foreach (var command in commands)
            {
                _producedCommands.Add(command);
            }

            // Assert
            _producedCommands.Add(_completionCommand);
            (await target.CommandListenerTask.WithCancellation(_cancellationToken)).ShouldBe(_completionCommand);
            _consumedCommands.Count.ShouldBe(count);
            _channel.Verify(c => c.ReceiveCommandAsync(It.IsAny<CancellationToken>()), Times.Exactly(count + 1));
        }

2. Example

Project: lime-csharp
Source File: ChannelListenerTests.cs
[Fact]
        public async Task Start_ConsumerCompletedWhileProducingCommands_StopsConsuming()
        {
            // Arrange
            var commands = new List<Command>();
            var count = Dummy.CreateRandomInt(500) + 2;
            var halfCount = count / 2;
            for (int i = 0; i < count; i++)
            {
                commands.Add(
                    Dummy.CreateCommand(Dummy.CreateTextContent()));
            }

            int consumedCount = 0;
            _commandConsumer = (m) =>
            {
                consumedCount++;
                if (consumedCount == halfCount)
                {
                    return TaskUtil.FalseCompletedTask;
                }
                return TaskUtil.TrueCompletedTask;
            };

            var target = GetAndStartTarget();

            // Act
            foreach (var command in commands)
            {
                _producedCommands.Add(command);
            }

            // Assert
            var unconsumedCommand = await target.CommandListenerTask;
            unconsumedCommand.ShouldNotBeNull();
            _producedCommands.ShouldNotContain(unconsumedCommand);
            _consumedCommands.ShouldNotContain(unconsumedCommand);
            consumedCount.ShouldBe(halfCount);
            _channel.Verify(c => c.ReceiveCommandAsync(It.IsAny<CancellationToken>()), Times.Exactly(halfCount));
            _producedCommands.Count.ShouldBe(count - halfCount);
        }

3. Example

Project: lime-csharp
Source File: DataflowChannelListenerTests.cs
[Fact]
        public async Task Start_MultipleCommandsReceived_SendsToBuffer()
        {
            // Arrange
            var commands = new List<Command>();
            var count = Dummy.CreateRandomInt(100);
            for (int i = 0; i < count; i++)
            {
                commands.Add(
                    Dummy.CreateCommand(Dummy.CreateTextContent()));
            }
            var target = GetAndStartTarget();

            // Act
            foreach (var command in commands)
            {
                _producedCommands.Add(command);
            }

            // Assert
            for (int i = 0; i < count; i++)
            {
                var actual = await _commandBufferBlock.ReceiveAsync();
                commands.ShouldContain(actual);
            }
        }

4. Example

Project: lime-csharp
Source File: ChannelListenerTests.cs
[Fact]
        public async Task Start_CommandReceived_CallsConsumer()
        {
            // Arrange
            var command = Dummy.CreateCommand(Dummy.CreateTextContent());
            var target = GetAndStartTarget();

            // Act
            _producedCommands.Add(command);
            var actual = _consumedCommands.Take(_cancellationToken);

            // Assert            
            actual.ShouldBe(command);
            _producedCommands.Add(_completionCommand);
            (await target.CommandListenerTask.WithCancellation(_cancellationToken)).ShouldBe(_completionCommand);
            _channel.Verify(c => c.ReceiveCommandAsync(It.IsAny<CancellationToken>()), Times.Exactly(2));
        }

5. Example

Project: lime-csharp
Source File: ChannelBaseTests.cs
[Fact]
        [Trait("Category", "ProcessCommandAsync")]
        public async Task ProcessCommandAs/n ..... /n //View Source file for more details /n }