Пример #1
0
        public async Task WhenStarting_ShouldBeAbleToJoinGiveaway()
        {
            // Arrange
            _MockHandler.SetupRequest(HttpMethod.Put, Config.GiveawayGame.RelayUrl, msg => msg.Method == HttpMethod.Put)
            .ReturnsResponse(HttpStatusCode.OK, _ => new HttpResponseMessage {
            });
            _MockHandler.SetupRequest(HttpMethod.Put, Config.GiveawayGame.RelayUrl, msg => msg.Method == HttpMethod.Put)
            .ReturnsResponse(HttpStatusCode.OK, _ => new HttpResponseMessage {
            });

            TwitchChat.Setup(t => t.BroadcastMessageOnChannel(It.Is <string>(s => s.StartsWith("Giveaway starting in "))));

            // Act
            _Game.ClearEntrants();
            _Game.Open(TwitchChat.Object, _Cmd);
            _Game.EnterGiveaway("1");
            var theTask = Task.Run(() => _Game.Start(TwitchChat.Object, _Cmd, 5));

            _Game.EnterGiveaway("2");
            await theTask.ContinueWith(_ => {
                // Assert
                TwitchChat.VerifyAll();
                Assert.Equal(CORE.GiveawayGameState.Running, _Game.State);
                Assert.NotEmpty(_Game.Entrants);
                Assert.Equal(2, _Game.Entrants.Count());
            });
        }
Пример #2
0
        public async Task WhenStarting_ShouldBeAbleToJoinGiveaway()
        {
            // Arrange
            TwitchChat.Setup(t => t.BroadcastMessageOnChannel(It.Is <string>(s => s.StartsWith("Giveaway starting in "))));

            // Act
            _Game.ClearEntrants();
            _Game.Open(TwitchChat.Object, _Cmd);
            _Game.EnterGiveaway("1");
            var theTask = Task.Run(() => _Game.Start(TwitchChat.Object, _Cmd, 5));

            _Game.EnterGiveaway("2");
            await theTask.ContinueWith(_ => {
                // Assert
                TwitchChat.VerifyAll();
                Assert.Equal(CORE.GiveawayGameState.Running, _Game.State);
                Assert.NotEmpty(_Game.Entrants);
                Assert.Equal(2, _Game.Entrants.Count());
            });
        }
Пример #3
0
        public void ShouldReportTheWinner()
        {
            // Arrange
            _Game.EnableCountdownTimer = false;
            var entrants = new[] { "testUser" };

            _MockHandler.SetupRequest(HttpMethod.Put, Config.GiveawayGame.RelayUrl, msg => msg.Method == HttpMethod.Put)
            .ReturnsResponse(HttpStatusCode.OK, _ => new HttpResponseMessage {
            });
            _MockHandler.SetupRequest(HttpMethod.Post, Config.GiveawayGame.RelayUrl, msg => msg.Method == HttpMethod.Post)
            .ReturnsResponse(HttpStatusCode.OK, new StringContent("testUser"));
            TwitchChat.Setup(t => t.BroadcastMessageOnChannel($"Congratulation @testUser - you have won the raffle!"));

            // Act
            _Game.Open(TwitchChat.Object, _Cmd);
            _Game.EnterGiveaway("1");
            _Game.Start(TwitchChat.Object, _Cmd);

            // Assert
            Assert.Equal(CORE.GiveawayGameState.Idle, _Game.State);
            TwitchChat.VerifyAll();
        }