public async Task Regular_comment_on_twitch_should_be_saved_to_database() { // arrange await _service.StartAsync(CancellationToken.None); var messageText = "hello just checking in " + Guid.NewGuid(); var username = "******" + Guid.NewGuid(); var arrivedKey = $"{username}::arrived_recently"; DocumentsToRemove.Add(arrivedKey); // clean up the "arrived" document // act _fakeTwitchClient.FakeRaiseMessage(messageText, username: username); // assert - message was saved var findMessage = TestCluster.QueryAsync <dynamic>( $"SELECT m.message FROM `{Bucket.Name}` m WHERE m.message = $message", QueryOptions.Create().Parameter("message", messageText).ScanConsistency(QueryScanConsistency.RequestPlus)); var rows = await findMessage.Result.Rows.ToListAsync(); Assert.That(rows.Count, Is.EqualTo(1)); // assert - user arrived doc was saved var userArrivedExists = await Collection.ExistsAsync(arrivedKey); Assert.That(userArrivedExists.Exists, Is.True); }
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)); }