public async Task Send_farfare_notice_when_user_has_fanfare_and_is_arriving(bool hasFanfare, int timesSent)
        {
            // arrange
            var username        = "******";
            var expectedFanfare = new FanfareInfo
            {
                Message          = "message " + Guid.NewGuid(),
                Timeout          = 12312,
                YouTubeCode      = "ytcode" + Guid.NewGuid(),
                YouTubeStartTime = 111,
                YouTubeEndTime   = 222
            };
            var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build();
            var chatMessage      = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build();
            var request          = new UserHasArrived(chatMessage);

            MockCollection.Setup(x => x.ExistsAsync($"{username}::arrived_recently", null))
            .ReturnsAsync(new FakeExistsResult(false));
            MockCollection.Setup(x => x.GetAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile {
                HasFanfare = hasFanfare, Fanfare = expectedFanfare
            }));

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

            // assert
            _mockTwitchHub.Verify(x => x.ReceiveFanfare(expectedFanfare), Times.Exactly(timesSent));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task Returns_valid_sound_effects()
        {
            // arrange
            var validSoundEffects = new ValidSoundEffects
            {
                SoundEffects = new List <SoundEffectInfo>
                {
                    new SoundEffectInfo {
                        SoundEffectName = "woof" + Guid.NewGuid()
                    },
                    new SoundEffectInfo {
                        SoundEffectName = "meow" + Guid.NewGuid()
                    },
                    new SoundEffectInfo {
                        SoundEffectName = "carcrash" + Guid.NewGuid()
                    }
                }
            };
            var request = new SoundEffectLookup();

            MockCollection.Setup(x => x.GetAsync("validSoundEffects", null))
            .ReturnsAsync(new FakeGetResult(validSoundEffects));

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

            // assert
            Assert.That(result.SoundEffects, Is.Not.Null);
            Assert.That(result.SoundEffects, Is.Not.Empty);
            Assert.That(result.SoundEffects.Count, Is.EqualTo(validSoundEffects.SoundEffects.Count));
            foreach (var effect in validSoundEffects.SoundEffects)
            {
                Assert.That(result.SoundEffects.Any(x => x.SoundEffectName == effect.SoundEffectName), Is.True);
            }
        }
Ejemplo n.º 4
0
        public async Task Gets_content_and_says_it_to_chat_room()
        {
            // arrange
            var channel         = "somechannel" + Guid.NewGuid();
            var commandName     = "!somemessage";
            var expectedContent = "blah blah blah whatever " + Guid.NewGuid();
            var content         = new ValidStaticCommands
            {
                Commands = new List <StaticCommandInfo>
                {
                    new StaticCommandInfo
                    {
                        Command = commandName,
                        Content = expectedContent
                    }
                }
            };

            MockCollection.Setup(x => x.GetAsync("staticContentCommands", null))
            .ReturnsAsync(new FakeGetResult(content));
            var request = new StaticMessage(commandName, channel);

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

            // assert
            // _twitchClient.SendMessage(request.Channel, command.Content);
            MockTwitchClient.Verify(x => x.SendMessage(channel, expectedContent, false), Times.Once);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public async Task Show_current_project_url()
        {
            // arrange
            var expectedUrl     = "http://example.org/foo/bar";
            var expectedMessage = $"Current Project is: " + expectedUrl;
            var projectInfo     = new CurrentProjectInfo {
                Url = new Uri(expectedUrl)
            };
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername("doesntmatterusername")
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("!currentproject")
                              .WithChannel("doesntmatterchannel")
                              .Build();
            var request = new SayCurrentProject(chatMessage);

            MockCollection.Setup(x => x.GetAsync("currentProject", null))
            .ReturnsAsync(new FakeGetResult(projectInfo));

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedMessage, false), Times.Once);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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);
        }
        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);
        }
        public async Task Return_all_the_content_that_exists()
        {
            // arrange
            var request  = new StaticCommandsLookup();
            var commands = new ValidStaticCommands
            {
                Commands = new List <StaticCommandInfo>
                {
                    new StaticCommandInfo {
                        Command = "foo", Content = "bar"
                    },
                    new StaticCommandInfo {
                        Command = "foo2", Content = "bar2"
                    },
                }
            };

            MockCollection.Setup(x => x.GetAsync("staticContentCommands", null))
            .ReturnsAsync(new FakeGetResult(commands));

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

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Commands, Is.Not.Null);
            Assert.That(result.Commands.Any(), Is.True);
            Assert.That(result.Commands.Count, Is.EqualTo(commands.Commands.Count));
        }
        public async Task If_homePageInfo_document_doesnt_exist_return_empty_object()
        {
            // arrange
            MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeExistsResult(false));

            // act
            var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None);

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Badges, Is.Null);
        }
        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);
        }
        public async Task If_homePageInfo_retrieve_fails_then_return_empty_object()
        {
            // arrange
            MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null)).ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null))
            .Throws(new Exception("retrieve fails"));

            // act
            var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None);

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Badges, Is.Null);
        }
        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);
        }
        public async Task Return_empty_list_if_there_are_no_commands_stored_in_database()
        {
            // arrange
            var request = new StaticCommandsLookup();

            MockCollection.Setup(x => x.GetAsync("staticContentCommands", null))
            .Throws <Exception>();

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

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Commands == null || !result.Commands.Any(), Is.True);
        }
Ejemplo n.º 16
0
        public async Task Returns_no_valid_sound_effects_if_validSoundEffects_data_doesnt_exist()
        {
            // arrange
            var request = new SoundEffectLookup();

            MockCollection.Setup(x => x.GetAsync("validSoundEffects", null))
            .Throws <Exception>();

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

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.SoundEffects == null || !result.SoundEffects.Any(), Is.True);
        }
        public async Task Return_homePageInfo_from_database()
        {
            // arrange
            var info = new HomePageInfo();

            info.Badges = new List <SocialMediaBadge>();
            info.Badges.Add(new SocialMediaBadge {
                Icon = "foo", Text = "bar"
            });
            MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null)).ReturnsAsync(new FakeExistsResult(true));
            MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeGetResult(info));

            // act
            var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None);

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(info));
        }
Ejemplo n.º 18
0
        public async Task Says_okay_if_able_to_store()
        {
            // arrange
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername(MockTwitchOptions.Object.Value.Username)
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("!setcurrentproject http://validurl.com")
                              .Build();
            var request = new SetCurrentProject(chatMessage);

            MockCollection.Setup(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null))
            .ReturnsAsync(new FakeMutationResult());

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), "Okay, got it!", false), Times.Once);
        }
Ejemplo n.º 19
0
        public async Task Says_an_error_message_if_unable_to_store()
        {
            // arrange
            var twitchLibMessage = TwitchLibMessageBuilder.Create()
                                   .WithUsername(MockTwitchOptions.Object.Value.Username)
                                   .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("!setcurrentproject http://validurl.com")
                              .Build();
            var request = new SetCurrentProject(chatMessage);

            MockCollection.Setup(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null))
            .Throws <Exception>();

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

            // assert
            MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), "I was unable to store that, sorry!", false), Times.Once);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
        public async Task No_fanfare_if_there_is_no_user_profile()
        {
            // arrange
            var username         = "******";
            var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build();
            var chatMessage      = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build();
            var request          = new UserHasArrived(chatMessage);

            // setup: user has NOT arrive recently
            MockCollection.Setup(m => m.ExistsAsync($"{username}::arrived_recently", null))
            .ReturnsAsync(new FakeExistsResult(false));
            // setup: don't care about the arrive_recently document being added
            MockCollection.Setup(m => m.UpsertAsync(It.IsAny <string>(), It.IsAny <UserHasArrivedMarker>(), null));
            // setup: user does NOT have a profile
            MockCollection.Setup(m => m.GetAsync(username.ToLower(), null))
            .ReturnsAsync(new FakeGetResult(null));

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

            // assert
            _mockTwitchHub.Verify(m => m.ReceiveFanfare(It.IsAny <FanfareInfo>()), Times.Never);
        }
Ejemplo n.º 23
0
        public async Task If_no_current_project_set_show_default_message()
        {
            // arrange
            var expectedDefaultMessage = "I haven't set any current project yet, sorry!";
            var twitchLibMessage       = TwitchLibMessageBuilder.Create()
                                         .WithUsername("doesntmatterusername")
                                         .Build();
            var chatMessage = ChatMessageBuilder.Create()
                              .WithTwitchLibMessage(twitchLibMessage)
                              .WithMessage("!currentproject")
                              .WithChannel("doesntmatterchannel")
                              .Build();
            var request = new SayCurrentProject(chatMessage);

            MockCollection.Setup(m => m.GetAsync("currentProject", null))
            .Throws <Exception>();

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

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