Exemplo n.º 1
0
        public void Setup()
        {
            _mockTwitchClient = new Mock <ITwitchClient>();
            _mockMediator     = new Mock <IMediator>();
            _handler          = new HelpHandler(_mockTwitchClient.Object, _mockMediator.Object);

            //_mediator.Send<ValidStaticCommands>(new StaticCommandsLookup());
            _fakeStaticCommands = new ValidStaticCommands
            {
                Commands = new List <StaticCommandInfo>
                {
                    new StaticCommandInfo {
                        Command = "!foo", Content = "foo content " + Guid.NewGuid()
                    },
                    new StaticCommandInfo {
                        Command = "!bar", Content = "bar content " + Guid.NewGuid()
                    },
                    new StaticCommandInfo {
                        Command = "!baz", Content = "foo content " + Guid.NewGuid()
                    },
                }
            };
            _mockMediator.Setup(m =>
                                m.Send <ValidStaticCommands>(It.IsAny <StaticCommandsLookup>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_fakeStaticCommands);
        }
        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));
        }
Exemplo n.º 3
0
 public SaveDashboardData(HomePageInfo homePageInfo, ValidStaticCommands staticCommandInfo, TriviaMessages triviaMessages, ChatNotificationInfo chatNotificationInfo)
 {
     HomePageInfo         = homePageInfo;
     StaticCommandInfo    = staticCommandInfo;
     TriviaMessages       = triviaMessages;
     ChatNotificationInfo = chatNotificationInfo;
 }
Exemplo n.º 4
0
        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"
                    },
                }
            };

            _mockBucket.Setup(x => x.GetAsync <ValidStaticCommands>("staticContentCommands"))
            .ReturnsAsync(new FakeOperationResult <ValidStaticCommands> {
                Success = true, Value = 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));
        }
Exemplo n.º 5
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
                    }
                }
            };

            _mockBucket.Setup(x => x.GetAsync <ValidStaticCommands>("staticContentCommands"))
            .ReturnsAsync(new FakeOperationResult <ValidStaticCommands> {
                Value = 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);
        }
Exemplo n.º 6
0
        public async Task SaveDashboardData_has_correct_serialized_objects_from_strings()
        {
            // arrange
            var homePageInfo = new HomePageInfo {
                Badges = new List <SocialMediaBadge> {
                    new SocialMediaBadge {
                        Icon = "tumblr", Text = "mgroves"
                    }
                }
            };
            var staticContentCommands = new ValidStaticCommands {
                Commands = new List <StaticCommandInfo> {
                    new StaticCommandInfo {
                        Command = "defend", Content = "defend the channel against invaders!"
                    }
                }
            };
            var triviaMessages = new TriviaMessages {
                Messages = new List <string> {
                    "hey what's up"
                }
            };
            var chatNotificationInfo = new ChatNotificationInfo();

            var homePageInfoJson          = JsonConvert.SerializeObject(homePageInfo);
            var chatNotificationInfoJson  = JsonConvert.SerializeObject(chatNotificationInfo);
            var staticContentCommandsJson = JsonConvert.SerializeObject(staticContentCommands);
            var triviaMessagesJson        = JsonConvert.SerializeObject(triviaMessages);

            // act
            await _controller.DashboardPost(homePageInfoJson, staticContentCommandsJson, triviaMessagesJson, chatNotificationInfoJson);

            // assert
            _mockMediator.Verify(m => m.Send(
                                     It.Is <SaveDashboardData>(x =>
                                                               x.HomePageInfo.Badges[0].Icon == homePageInfo.Badges[0].Icon
                                                               &&
                                                               x.StaticCommandInfo.Commands[0].Command == staticContentCommands.Commands[0].Command),
                                     It.IsAny <CancellationToken>()), Times.Once);
        }
Exemplo n.º 7
0
 public SaveDashboardData(HomePageInfo homePageInfo, ValidStaticCommands staticCommandInfo, TriviaMessages triviaMessages)
 {
     HomePageInfo      = homePageInfo;
     StaticCommandInfo = staticCommandInfo;
     TriviaMessages    = triviaMessages;
 }