コード例 #1
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void WillReconnectToNextServer()
        {
            var sim = SimAnon.Value;
            var ws  = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                var url1 = ws.ConnectUrl;

                // Prepare new ClientWebSocket for consumption by client code, and dispose the old one
                sim.ChatWebSocket = new SimulatedClientWebSocket(true, false, Simulator.CHAT_WELCOME);
                ws.Dispose();
                ws = sim.ChatWebSocket;
                bool reconnectSucceeded = ws.JoinedChat.Wait(Simulator.TIMEOUT);

                var url2 = ws.ConnectUrl;

                reconnectSucceeded.Should().BeTrue();
                url1.Should().NotBeNull();
                url2.Should().NotBeNull();
                url1.Should().NotBe(url2);
            }
        }
コード例 #2
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void TimeoutUserSendsCorrectPackets()
        {
            var sim = SimAuth.Value;
            var ws  = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                var id        = ws.LastId.GetValueOrDefault() + 1;
                var replyJson = BuildTimeoutReply(id);

                var task = sut.TimeoutUserAsync("SomeTestUser", TimeSpan.FromMinutes(5));
                ws.InjectPacket(replyJson);

                task.Wait(Simulator.TIMEOUT);                 // Wait for TimeoutUserAsync to complete

                // Validate packet sent
                ws.LastPacket["type"].Should().NotBeNull();
                ws.LastPacket["type"].Value <string>().Should().Be("method");
                ws.LastPacket["method"].Should().NotBeNull();
                ws.LastPacket["method"].Value <string>().Should().Be("timeout");
                ws.LastPacket["arguments"].Should().NotBeNull();
                var args = ws.LastPacket["arguments"].Values <string>().ToArray();
                args.Should().HaveCount(2);
                args[0].Should().Be("SomeTestUser");
                args[1].Should().Be("5m0s");

                task.Result.Should().BeTrue();
            }
        }
コード例 #3
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void AddCorrectHeaders()
        {
            var sim = SimAuth.Value;
            var ws  = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                ws.Headers.Should().Contain("x-is-bot", "true");
            }
        }
コード例 #4
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void WIllRetryFailedInitialChatConnection()
        {
            var sim = SimAuth.Value;
            var ws  = sim.ChatWebSocket = new SimulatedClientWebSocket(true, true, failConnectCount: 4);

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                var task     = sut.StartAsync();
                var didRetry = ws.FailedConnectAttemptsReached.Wait(Simulator.TIMEOUT);
                ws.ConnectionAttempts.Should().BeGreaterOrEqualTo(4);
                didRetry.Should().BeTrue();
            }
        }
コード例 #5
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void ImplementsCorrectInterfaces()
        {
            var sim    = SimAnon.Value;
            var packet = BuildChatMessage(sim, 56789, "connor", "Hello world!");
            var ws     = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);
                var result = Assert.Raises <ChatMessageEventArgs>(x => sut.ChatMessage += x, x => sut.ChatMessage -= x, () => ws.InjectPacket(packet));
                //            Assert.IsAssignableFrom<IChatService>(result.Sender);
            }
        }
コード例 #6
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void HandlesNullAvatar()
        {
            var sim    = SimAnon.Value;
            var packet = BuildChatMessage(sim, 56789, "connor", "Hello world!", roles: new string[] { "Owner", "Mod" }, avatar: null);
            var ws     = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);
                using (var monitor = sut.Monitor())
                {
                    ws.InjectPacket(packet);
                    monitor.Should().Raise(nameof(sut.ChatMessage))
                    .WithArgs <ChatMessageEventArgs>(a => a.Avatar == "" && a.UserName == "connor")
                    .WithSender(sut);
                }
            }
        }
コード例 #7
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void RaisesUserLeftEvent()
        {
            var sim    = SimAnon.Value;
            var packet = BuildUserJoinOrLeave(sim, "SomeNewUser", 34103083, isJoin: false);
            var ws     = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);
                using (var monitor = sut.Monitor())
                {
                    ws.InjectPacket(packet);
                    monitor.Should().Raise(nameof(sut.UserLeft))
                    .WithArgs <ChatUserInfoEventArgs>(a => a.UserId == 34103083 && a.UserName == "SomeNewUser" && a.ChannelId == sim.ChannelInfo.Id)
                    .WithSender(sut);
                }
            }
        }
コード例 #8
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void DetectsUserRoles()
        {
            var sim    = SimAnon.Value;
            var packet = BuildChatMessage(sim, 56789, "connor", "Hello world!", roles: new string[] { "Owner", "Mod" });
            var ws     = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);
                using (var monitor = sut.Monitor())
                {
                    ws.InjectPacket(packet);
                    monitor.Should().Raise(nameof(sut.ChatMessage))
                    .WithArgs <ChatMessageEventArgs>(a => a.Message == "Hello world!" && a.UserName == "connor" && a.UserId == 56789 && a.IsModerator && a.IsOwner && !a.IsWhisper)
                    .WithSender(sut);
                }
            }
        }
コード例 #9
0
ファイル: Constellation.cs プロジェクト: jbdk/MixerLib
        public void WillReconnect()
        {
            var sim = SimAnon.Value;
            var ws  = sim.ConstellationWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                // Prepare new ClientWebSocket for consumption by client code, and dispose the old one
                sim.ConstellationWebSocket = new SimulatedClientWebSocket(false, false, Simulator.CONSTALLATION_WELCOME);
                ws.Dispose();
                ws = sim.ConstellationWebSocket;
                var connectedAndJoined = ws.JoinedConstallation.Wait(Simulator.TIMEOUT * 5);

                connectedAndJoined.Should().BeTrue();
            }
        }
コード例 #10
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void CanHandleRealDataDump()
        {
            var sim = SimAuth.Value;
            var ws  = sim.ConstellationWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                foreach (var line in File.ReadAllLines("Data/ChatDump.json"))
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    ws.InjectPacket(line);
                }
            }
        }
コード例 #11
0
ファイル: Constellation.cs プロジェクト: jbdk/MixerLib
        public void CanCombineEvent()
        {
            var packet = BuildChannelStatusEvent("channel:1234:update", followers: 22, viewers: 43, online: true);

            var sim = SimAnon.Value;
            var ws  = sim.ConstellationWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);
                using (var monitor = sut.Monitor())
                {
                    ws.InjectPacket(packet);
                    monitor.Should().Raise(nameof(sut.ChannelUpdate))
                    .WithArgs <ChannelUpdateEventArgs>(a => a.Channel.NumFollowers == 22 && a.Channel.ViewersCurrent == 43 && a.Channel.Online == true && a.ChannelId == sim.ChannelInfo.Id)
                    .WithSender(sut);
                }
            }
        }
コード例 #12
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void WillConnectAndJoinAnonymously()
        {
            var sim = SimAnon.Value;

            var ws = sim.ChatWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                var connectedAndJoined = ws.JoinedChat.Wait(Simulator.TIMEOUT);
                connectedAndJoined.Should().BeTrue();

                ws.LastPacket["method"].Should().NotBeNull();
                ws.LastPacket["method"].Value <string>().Should().Be("auth");
                ws.LastPacket["arguments"].Should().NotBeNull();
                var args = ws.LastPacket["arguments"].ToString(Formatting.None);
                args.Should().Be($"[{sim.ChannelInfo.Id}]");
            }
        }
コード例 #13
0
ファイル: Chat.cs プロジェクト: jbdk/MixerLib
        public void CantSendAnononymously()
        {
            var sim = SimAnon.Value;
            var ws  = sim.ChatWebSocket;

            const string text = "Some test message";

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                var id        = ws.LastId.GetValueOrDefault() + 1;
                var replyJson = BuildMsgReply(sim, id, text);

                var task = sut.SendMessageAsync(text);
                ws.InjectPacket(replyJson);

                task.Wait(Simulator.TIMEOUT);                 // Wait for SendMessageAsync to complete
                task.Result.Should().BeFalse();
            }
        }
コード例 #14
0
ファイル: Constellation.cs プロジェクト: jbdk/MixerLib
        public void WillConnectAndJoin()
        {
            var sim = SimAnon.Value;
            var ws  = sim.ConstellationWebSocket;

            using (var sut = new MixerClientInternal(ChannelName, LoggerFactory, sim))
            {
                sut.StartAsync().Wait(Simulator.TIMEOUT);

                var connectedAndJoined = ws.JoinedConstallation.Wait(Simulator.TIMEOUT);

                connectedAndJoined.Should().BeTrue();
                // {{"id": 1,"type": "method","method": "livesubscribe","params": {"events": ["channel:1234:update" ]}}}
                ws.LastPacket["method"].Should().NotBeNull();
                ws.LastPacket["method"].Value <string>().Should().Be("livesubscribe");
                var args = $"[{sim.ChannelInfo.Id},{sim.ChannelInfo.UserId},\"{sim.ChatAuthKey}\"]";
                ws.LastPacket["params"].Should().NotBeNull();
                ws.LastPacket["params"]["events"].Should().NotBeNull();
                var events = ws.LastPacket["params"]["events"].ToString(Formatting.None);
                events.Should().ContainAll($"channel:{sim.ChannelInfo.Id}:update");
            }
        }