Esempio n. 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);
        }
Esempio n. 2
0
        public async Task ReceiveAsync_EmptyQueue_ReturnsNull()
        {
            // Arrange
            StubQueue queue = new StubQueue("mongodb://localhost:27017", "eventsTest", "testQueue");

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

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

            // Assert
            Assert.Null(result);
        }
Esempio n. 3
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);
        }