Beispiel #1
0
        public void CavetubeMainTest2_RoomIdNotFound()
        {
            var clientFactory = new MockCavetubeClientFactory();
            var mockClient    = clientFactory.MockCavetubeClient;
            var authFactory   = new MockCavetubeAuthFactory();
            var mockAuth      = authFactory.MockCavetubeAuth;
            var pso2Factory   = new MockPso2LogWatcherFactory();
            var mockPso2      = pso2Factory.MockPso2LogWatcher;

            var summary = new SummaryWrapper();
            //summary.RoomId = "roomid";
            var manualEvent = new ManualResetEvent(false);
            var check       = true;

            mockAuth.Setup(a => a.Login(It.IsAny <string>(), It.IsAny <string>())).Returns("apikey");
            mockClient.Setup(cl => cl.JoinRoom(It.IsAny <string>())).Raises(m => m.OnJoin += null, "roomid");
            mockClient.Setup(cl => cl.LeaveRoom()).Raises(m => m.OnLeave += null, "roomid");
            mockClient.Setup(cl => cl.GetSummary(It.IsAny <string>())).Returns(summary);
            mockClient.Setup(cl => cl.PostComment(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string, string>((name, message, apikey) =>
            {
                check = false;
                manualEvent.Set();
                Assert.AreEqual("someone", name);
                Assert.AreEqual("message", message);
                Assert.AreEqual("apikey", apikey);
            });

            var msg = new Pso2LogEventArgs();

            msg.From    = "someone";
            msg.SendTo  = "GUILD";
            msg.Message = "message";
            mockPso2.Setup(pso2 => pso2.Start()).Raises(pso2 => pso2.Pso2LogEvent += null, msg);

            var ex = Assert.Throws <ApplicationException>(() =>
            {
                Pso2LogSender.CavetubeMain(authFactory, clientFactory, pso2Factory, () =>
                {
                    check = false;
                    manualEvent.WaitOne();
                });
            });

            Assert.AreEqual("部屋IDの取得に失敗しました", ex.Message);

            Assert.True(check);
        }
Beispiel #2
0
        public void JoinningTest()
        {
            var factory    = new MockCavetubeClientFactory();
            var mockClient = factory.MockCavetubeClient;

            mockClient.Setup(cl => cl.JoinRoom(It.IsAny <string>())).Raises(m => m.OnJoin += null, "roomid");
            mockClient.Setup(cl => cl.LeaveRoom()).Raises(m => m.OnLeave += null, "roomid");
            var  client = factory.CreateCavetubeClient();
            bool check  = false;

            CavetubeUtility.Joinning(
                client,
                "roomId",
                () => {
                check = true;
            });
            Assert.IsTrue(check);
        }
        public void CavetubeMainTest2_RoomIdNotFound()
        {
            var clientFactory = new MockCavetubeClientFactory();
            var mockClient = clientFactory.MockCavetubeClient;
            var authFactory = new MockCavetubeAuthFactory();
            var mockAuth = authFactory.MockCavetubeAuth;
            var pso2Factory = new MockPso2LogWatcherFactory();
            var mockPso2 = pso2Factory.MockPso2LogWatcher;

            var summary = new SummaryWrapper();
            //summary.RoomId = "roomid";
            var manualEvent = new ManualResetEvent(false);
            var check = true;

            mockAuth.Setup(a => a.Login(It.IsAny<string>(), It.IsAny<string>())).Returns("apikey");
            mockClient.Setup(cl => cl.JoinRoom(It.IsAny<string>())).Raises(m => m.OnJoin += null, "roomid");
            mockClient.Setup(cl => cl.LeaveRoom()).Raises(m => m.OnLeave += null, "roomid");
            mockClient.Setup(cl => cl.GetSummary(It.IsAny<string>())).Returns(summary);
            mockClient.Setup(cl => cl.PostComment(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Callback<string, string, string>((name, message, apikey) =>
                {
                    check = false;
                    manualEvent.Set();
                    Assert.AreEqual("someone", name);
                    Assert.AreEqual("message", message);
                    Assert.AreEqual("apikey", apikey);
                });

            var msg = new Pso2LogEventArgs();
            msg.From = "someone";
            msg.SendTo = "GUILD";
            msg.Message = "message";
            mockPso2.Setup(pso2 => pso2.Start()).Raises(pso2 => pso2.Pso2LogEvent += null, msg);

            var ex = Assert.Throws<ApplicationException>(() =>
            {
                Pso2LogSender.CavetubeMain(authFactory, clientFactory, pso2Factory, () =>
                {
                    check = false;
                    manualEvent.WaitOne();
                });
            });
            Assert.AreEqual("部屋IDの取得に失敗しました", ex.Message);

            Assert.True(check);
        }
 public void JoinningTest()
 {
     var factory = new MockCavetubeClientFactory();
     var mockClient = factory.MockCavetubeClient;
     mockClient.Setup(cl => cl.JoinRoom(It.IsAny<string>())).Raises(m => m.OnJoin += null, "roomid");
     mockClient.Setup(cl => cl.LeaveRoom()).Raises(m => m.OnLeave += null, "roomid");
     var client = factory.CreateCavetubeClient();
     bool check = false;
     CavetubeUtility.Joinning(
         client,
         "roomId",
         () => {
             check = true;
         });
     Assert.IsTrue(check);
 }