Exemplo n.º 1
0
 public void CanCallInitMultipleTimes()
 {
     using (var sut = new MixerRestClient(LoggerFactory, Client))
     {
         sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);
         sut.InitAsync(ChannelName, null).Wait(Simulator.TIMEOUT);
     }
 }
Exemplo n.º 2
0
        public void LookupUserReturnNullIdUnknownUser()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var userId = sut.LookupUserIdAsync("InvalidUserNameForSure").Result;
                userId.Should().BeNull();
            }
        }
Exemplo n.º 3
0
        public void HandlesUnknownGameTypeById()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var gameType = sut.LookupGameTypeByIdAsync(34634).Result;

                // Assert
                gameType.Should().BeNull();
            }
        }
Exemplo n.º 4
0
        public void CanInit()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                // Assert
                Handler.RequestHistory.Count.Should().Be(2);
                sut.UserId.Should().Be(UserId);
                sut.UserName.Should().Be(UserName);
            }
        }
Exemplo n.º 5
0
        public void CanLookupUserId()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var r = sut.LookupUserIdAsync(OtherUserName).Result;

                // Assert
                r.Should().Be(OtherUserId);
            }
        }
Exemplo n.º 6
0
        public void CheckAcceptsHeader()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                // Assert
                var req = Handler.FindRequest($"channels/{WebUtility.UrlEncode(ChannelName)}");
                req.Should().NotBeNull();
                req.Method.Should().Be(HttpMethod.Get);
                req.Headers.Should().Contain(new KeyValuePair <string, string>("Accept", "application/json"));
            }
        }
Exemplo n.º 7
0
        public void CanGetChannelInfo()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var(title, gameTypeId) = sut.GetChannelInfoAsync().Result;

                // Assert
                title.Should().Be("Test stream title 1");
                gameTypeId.Should().Be(GameTypeId);
            }
        }
Exemplo n.º 8
0
        public void ParsesStreamStartAndRoundsCorrectly()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var r = sut.GetStreamStartedAtAsync().Result;

                // Assert
                r.Should().NotBeNull();
                r.Value.Should().Be(StartedAtTestValue);
            }
        }
Exemplo n.º 9
0
        public void CanLookupGameTypeById()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var gameType = sut.LookupGameTypeByIdAsync(GameTypeId).Result;

                // Assert
                gameType.Should().NotBeNull();
                gameType.Id.Should().Be(GameTypeId);
                gameType.Name.Should().Be("TestGameName");
            }
        }
Exemplo n.º 10
0
        public void ChatAuthRequest()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var result = sut.GetChatAuthKeyAndEndpointsAsync().Result;

                // Assert
                result.Should().NotBeNull();
                result.Authkey.Should().Be(SimAuth.Value.ChatAuthKey);
                result.Endpoints.Should().BeEquivalentTo(Endpoints);
            }
        }
Exemplo n.º 11
0
        public void WillRetryInit()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client)
            {
                RetryDelay = 0, MaxTries = 5
            })
            {
                Action call = () => sut.InitAsync("InvalidChannelName", Token).Wait(Simulator.TIMEOUT);

                // Assert
                call.Should().Throw <MixerException>();
                Handler.RequestHistory.Count.Should().Be(5);
            }
        }
Exemplo n.º 12
0
        public static IMixerRestApi GetApi <TEntity>(HttpMethod method, string endpoint, string content,
                                                     string json = null, int version = 1)
        {
            var mockBaseClient = new Mock <IBaseHttpClient>();

            mockBaseClient.Setup(x => x.GetHttpResponse <TEntity>(method, endpoint, json, version))
            .ReturnsAsync(new HttpResponseMessage {
                Content = new StringContent(content)
            });

            var restClient = new MixerRestClient(mockBaseClient.Object);

            return(new MixerRestApi(restClient));
        }
Exemplo n.º 13
0
        public void CanLookupGameTypeByQuery()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var gameTypes = sut.LookupGameTypeAsync("GameName").Result;

                // Assert
                gameTypes.Should().NotBeNull();
                gameTypes.Should().ContainSingle();
                gameTypes.First().Id.Should().Be(GameTypeId);
                gameTypes.First().Name.Should().Be("GameName");
            }
        }
Exemplo n.º 14
0
        public void CanUnbanUser()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                var result = sut.UnbanUserAsync(OtherUserName).Result;

                // Assert
                var req = Handler.FindRequest($"channels/{ChannelId}/users/{OtherUserId}", new HttpMethod("PATCH"));
                req.Should().NotBeNull();
                req.Content.Should().NotBeNullOrWhiteSpace();

                var doc = JToken.Parse(req.Content);
                doc["remove"].Should().NotBeNull();
                doc["remove"].Values <string>().Should().Contain("Banned");
            }
        }
Exemplo n.º 15
0
        public void CanUpdateGetChannelInfo()
        {
            using (var sut = new MixerRestClient(LoggerFactory, Client))
            {
                sut.InitAsync(ChannelName, Token).Wait(Simulator.TIMEOUT);

                sut.UpdateChannelInfoAsync("New stream title", GameTypeId).Wait();

                var req = Handler.FindRequest($"channels/{ChannelId}", new HttpMethod("PATCH"));
                req.Should().NotBeNull();
                req.Content.Should().NotBeNullOrWhiteSpace();

                var doc = JToken.Parse(req.Content);
                doc["name"].Should().NotBeNull();
                doc["name"].Value <string>().Should().Be("New stream title");
                doc["typeId"].Should().NotBeNull();
                doc["typeId"].Value <uint>().Should().Be(GameTypeId);
            }
        }