示例#1
0
        public async Task SendAsync_RequestInQueue()
        {
            // Arrange
            StubQueue             queue      = new StubQueue("mongodb://localhost:27017", "eventsTest", "testQueue");
            var                   command    = new CommandToQueue(1, "test", DateTime.Now.AddMinutes(10));
            List <CommandWrapper> repository = new List <CommandWrapper>();

            queue.MoqCollection
            .Setup(c => c.Insert(It.IsAny <CommandWrapper>()))
            .Returns(new WriteConcernResult(new BsonDocument()))
            .Callback <CommandWrapper>(repository.Add);

            // Act
            await queue.SendAsync(command, default(CancellationToken));

            // Assert
            var result = repository.FirstOrDefault();

            Assert.NotNull(result);
            Assert.IsType(typeof(CommandToQueue), result.Payload);
            var resultCommand = (CommandToQueue)result.Payload;

            Assert.Equal(command.IntValue, resultCommand.IntValue);
            Assert.Equal(command.StringValue, resultCommand.StringValue);
            Assert.Equal(command.DateTimeValue, resultCommand.DateTimeValue);
        }
        public async Task SendAsync_RequestInQueue()
        {
            // Arrange
            var collection = new ConcurrentQueue<ICommand>();
            InMemoryCommandQueue queue = new InMemoryCommandQueue(collection);
            var command = new CommandToQueue();

            // Act
            await queue.SendAsync(command, default(CancellationToken));

            // Assert
            Assert.Equal(1, collection.Count);
        }
示例#3
0
        public async Task SendAsync_RequestInQueue()
        {
            // Arrange
            var collection             = new ConcurrentQueue <ICommand>();
            InMemoryCommandQueue queue = new InMemoryCommandQueue(collection);
            var command = new CommandToQueue();

            // Act
            await queue.SendAsync(command, default(CancellationToken));

            // Assert
            Assert.Equal(1, collection.Count);
        }
示例#4
0
        public async Task ReceiveAsync_EmptyQueue_ReturnsCommand()
        {
            // Arrange
            StubQueue queue   = new StubQueue("mongodb://localhost:27017", "eventsTest", "testQueue");
            var       command = new CommandToQueue(1, "test", DateTime.Now.AddMinutes(10));

            queue.MoqCollection
            .Setup(c => c.FindAs <CommandWrapper>(It.IsAny <IMongoQuery>()))
            .Returns(CreateCursor(queue.MoqCollection.Object, new[] { new CommandWrapper(command) }));

            // Act
            var result = await queue.ReceiveAsync(default(CancellationToken));

            // Assert
            Assert.NotNull(result);
            Assert.IsType(typeof(CommandToQueue), result);
            var resultCommand = (CommandToQueue)result;

            Assert.Equal(command.IntValue, resultCommand.IntValue);
            Assert.Equal(command.StringValue, resultCommand.StringValue);
            Assert.Equal(command.DateTimeValue, resultCommand.DateTimeValue);
        }