public async Task Should_insert_message_into_bucket() { // arrange var expectedUsername = "******" + Guid.NewGuid(); var expectedMessage = "some message whatever " + Guid.NewGuid(); var expectedChannel = "mychannel" + Guid.NewGuid(); var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(expectedUsername) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage(expectedMessage) .WithChannel(expectedChannel) .Build(); var request = new StoreMessage(chatMessage); // act await _handler.Handle(request, CancellationToken.None); // assert _mockBucket.Verify(x => x.InsertAsync(It.Is <Document <ChatMessage> >(d => d.Id != Guid.Empty.ToString())), Times.Once()); _mockBucket.Verify(x => x.InsertAsync(It.Is <Document <ChatMessage> >(d => d.Content.Username == expectedUsername)), Times.Once()); _mockBucket.Verify(x => x.InsertAsync(It.Is <Document <ChatMessage> >(d => d.Content.Message == expectedMessage)), Times.Once()); _mockBucket.Verify(x => x.InsertAsync(It.Is <Document <ChatMessage> >(d => d.Content.Channel == expectedChannel)), Times.Once()); }
public async Task Should_insert_message_into_bucket() { // arrange var expectedUsername = "******" + Guid.NewGuid(); var expectedMessage = "some message whatever " + Guid.NewGuid(); var expectedChannel = "mychannel" + Guid.NewGuid(); var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(expectedUsername) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage(expectedMessage) .WithChannel(expectedChannel) .Build(); var request = new StoreMessage(chatMessage); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.IsAny <ChatMessage>(), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Username == expectedUsername), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Message == expectedMessage), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Channel == expectedChannel), null), Times.Once()); }
public async Task Is_chat_message_stored() { // arrange var expectedUsername = "******" + Guid.NewGuid(); var expectedMessage = "some message whatever " + Guid.NewGuid(); var expectedChannel = "mychannel" + Guid.NewGuid(); var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(expectedUsername) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage(expectedMessage) .WithChannel(expectedChannel) .Build(); var request = new StoreMessage(chatMessage); // act await _handler.Handle(request, CancellationToken.None); // assert var n1ql = $"SELECT RAW COUNT(*) FROM `{Bucket.Name}` WHERE message = $expectedMessage"; var result = await TestCluster.QueryAsync <int>(n1ql, QueryOptions.Create().Parameter("expectedMessage", expectedMessage).ScanConsistency(QueryScanConsistency.RequestPlus)); var count = await result.Rows.FirstOrDefaultAsync(); Assert.That(count, Is.EqualTo(1)); }