示例#1
0
        public async Task ShoutOut_is_limited_to_mods_and_subs(bool isSub, bool isMod, int numVerified)
        {
            // arrange
            var userToShout      = "someusername";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("NonSub")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage($"!so {userToShout}")
                              .WithIsSubscriber(isSub)
                              .WithIsModerator(isMod)
                              .Build();
            var request = new ShoutOut(chatMessage);

            MockApiWrapper.Setup(m =>
                                 m.DoesUserExist(It.IsAny <string>())).ReturnsAsync(true);
            MockCollection.Setup(m => m.ExistsAsync(userToShout, null))
            .ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(m => m.GetAsync(userToShout, null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false),
                                    Times.Exactly(numVerified));
        }
示例#2
0
        public async Task ShoutOut_will_shout_the_given_username()
        {
            // arrange
            var userName         = "******";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesntmatter")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithIsSubscriber(true)
                              .WithMessage($"!so {userName}")
                              .Build();

            MockApiWrapper.Setup(x => x.DoesUserExist(userName)).ReturnsAsync(true);
            MockCollection.Setup(x => x.ExistsAsync(userName.ToLower(), null))
            .ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(x => x.GetAsync(userName.ToLower(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));
            var shout           = new ShoutOut(chatMessage);
            var expectedMessage = $"Hey everyone, check out @{userName}'s Twitch stream at https://twitch.tv/{userName}";

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedMessage, false), Times.Once);
        }
示例#3
0
        public async Task ShoutOut_will_use_custom_message_if_there_is_one()
        {
            // arrange
            var userProfile = new TwitcherProfile {
                ShoutMessage = "hey hey look at me" + Guid.NewGuid()
            };
            var userName             = "******";
            var expectedShoutMessage = userProfile.ShoutMessage + $" https://twitch.tv/{userName}";
            var twitchLibMessage     = TwitchLibMessageBuilder.Create()
                                       .WithUsername("doesntmatter")
                                       .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithIsSubscriber(true)
                              .WithMessage($"!so {userName}")
                              .Build();

            MockApiWrapper.Setup(x => x.DoesUserExist(userName)).ReturnsAsync(true);
            MockCollection.Setup(x => x.ExistsAsync(userName.ToLower(), null))
            .ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(x => x.GetAsync(userName.ToLower(), null))
            .ReturnsAsync(new FakeGetResult(userProfile));
            var shout = new ShoutOut(chatMessage);

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedShoutMessage, false), Times.Once);
        }
示例#4
0
        public async Task ShoutOut_WILL_shout_if_the_given_username_is_a_real_twitch_user()
        {
            // arrange
            var userLookup       = "doesntmattereither";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesntmatter")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithIsSubscriber(true)
                              .WithMessage($"!so {userLookup}")
                              .Build();

            MockApiWrapper.Setup(x => x.DoesUserExist(userLookup)).ReturnsAsync(true);
            MockCollection.Setup(x => x.ExistsAsync(userLookup.ToLower(), null))
            .ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(x => x.GetAsync(userLookup.ToLower(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));

            var shout = new ShoutOut(chatMessage);

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false), Times.Once);
        }
示例#5
0
        public async Task ShoutOut_will_not_shout_if_the_given_username_isnt_a_real_twitch_user()
        {
            // arrange
            var userLookup       = "doesntmattereither";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesntmatter")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithIsSubscriber(true)
                              .WithMessage($"!so {userLookup}")
                              .Build();

            MockApiWrapper.Setup(x => x.DoesUserExist(userLookup)).ReturnsAsync(false);
            var shout = new ShoutOut(chatMessage);

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false), Times.Never);
        }
        public async Task If_user_exists_then_perform_trout_action_with_target_username(string userThatDoesExist)
        {
            // arrange
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesn't matter")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage($"!trout {userThatDoesExist}")
                              .Build();

            MockApiWrapper.Setup(m => m.DoesUserExist(It.IsAny <string>()))
            .ReturnsAsync(true);

            var troutRequest = new Trout(chatMessage);

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

            // assert
            MockTwitchClient.Verify(x =>
                                    x.SendMessage(It.IsAny <string>(), $"/me slaps @{userThatDoesExist.Replace("@","")} around a bit with a large trout.", It.IsAny <bool>())
                                    , Times.Once);
        }
        public async Task If_user_doesnt_exist_trouting_say_error_message(string userThatDoesntExist)
        {
            // arrange
            var expectedMessage  = $"User {userThatDoesntExist.Replace("@", "")} doesn't exist.";
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesn't matter")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage($"!trout {userThatDoesntExist}")
                              .Build();

            MockApiWrapper.Setup(m => m.DoesUserExist(userThatDoesntExist))
            .ReturnsAsync(false);

            var troutRequest = new Trout(chatMessage);

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

            // assert
            MockTwitchClient.Verify(m =>
                                    m.SendMessage(It.IsAny <string>(), expectedMessage, false), Times.Once);
        }