コード例 #1
0
        public async Task Create_recent_activity_marker_document_if_necessary()
        {
            // arrange
            var username = "******";

            MockCollection.Setup(x => x.ExistsAsync($"{username}::arrived_recently", null))
            .ReturnsAsync(new FakeExistsResult(false));
            var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build();
            var chatMessage      = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build();
            var request          = new UserHasArrived(chatMessage);

            MockCollection.Setup(x => x.GetAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));
            _mockTwitchHub.Setup(x => x.ReceiveFanfare(It.IsAny <FanfareInfo>()));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(x => x.UpsertAsync(
                                      It.Is <string>(k => k == $"{username}::arrived_recently"),
                                      It.IsAny <UserHasArrivedMarker>(),
                                      It.IsAny <UpsertOptions>()), Times.Once);
            MockCollection.Verify(x => x.UpsertAsync(
                                      It.IsAny <string>(),
                                      It.IsAny <UserHasArrivedMarker>(),
                                      It.Is <UpsertOptions>(u =>
                                                            (u.GetInternalPropertyValue <TimeSpan, UpsertOptions>("ExpiryValue")).Hours == 12)),
                                  Times.Once);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        public async Task If_profile_does_exist_then_upsert_doesnt_happen()
        {
            // arrange
            var username = "******";
            var request  = new CreateProfileIfNotExists(username);

            MockCollection.Setup(m => m.ExistsAsync(username, null)).ReturnsAsync(new FakeExistsResult(true));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(m => m.UpsertAsync(It.IsAny <string>(), It.IsAny <TwitcherProfile>(), null), Times.Never);
        }
コード例 #4
0
        public async Task Profile_is_looked_up_by_twitch_username()
        {
            // arrange
            var username = "******";
            var request  = new GetProfile(username);

            MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(m => m.GetAsync(username, It.IsAny <GetOptions>()), Times.Once);
        }
コード例 #5
0
        public async Task Should_not_create_a_profile_if_one_already_exists()
        {
            // arrange
            var username         = "******";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername(username)
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("notnull")
                              .Build();
            var request = new ModifyProfile(chatMessage);

            MockCollection.Setup(x => x.ExistsAsync(username, null))
            .ReturnsAsync(new FakeExistsResult(true));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(x => x.InsertAsync(username, It.IsAny <TwitcherProfile>(), null), Times.Never);
        }
コード例 #6
0
        public async Task Should_create_a_profile_if_one_doesnt_exist()
        {
            // arrange
            var username         = "******";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername(username)
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("doesntmatter")
                              .Build();
            var request = new ModifyProfile(chatMessage);

            MockCollection.Setup(m => m.ExistsAsync(username, null))
            .ReturnsAsync(new FakeExistsResult(false));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(x => x.InsertAsync(username, It.Is <TwitcherProfile>(
                                                         y => y.Type == "profile"), null), Times.Once);
        }
コード例 #7
0
        public async Task Only_the_bot_user_itself_can_set_the_current_project()
        {
            // arrange
            var notTheBotUser    = MockTwitchOptions.Object.Value.Username + Guid.NewGuid();
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername(notTheBotUser)
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("doesntmatter")
                              .Build();

            var request = new SetCurrentProject(chatMessage);

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert - twitch client never used, bucket never used
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()),
                                    Times.Never);
            MockCollection.Verify(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null),
                                  Times.Never);
        }