示例#1
0
        public void GetApiKeyTest()
        {
            var factory = new MockCavetubeAuthFactory();
            var mock = factory.MockCavetubeAuth;
            mock.Setup(a => a.Login(It.IsAny<string>(), It.IsAny<string>())).Returns("apikey");
            ICavetubeAuth auth = mock.Object;

            using (CavetubeAuthManager manager = new CavetubeAuthManager("hakusai", "password", factory))
            {
                Assert.AreEqual("apikey", manager.GetApiKey());
            }

            mock.Verify(a => a.Logout("hakusai", "password"), Times.Once());
        }
示例#2
0
        public void GetApiKeyTest()
        {
            var factory = new MockCavetubeAuthFactory();
            var mock    = factory.MockCavetubeAuth;

            mock.Setup(a => a.Login(It.IsAny <string>(), It.IsAny <string>())).Returns("apikey");
            ICavetubeAuth auth = mock.Object;

            using (CavetubeAuthManager manager = new CavetubeAuthManager("hakusai", "password", factory))
            {
                Assert.AreEqual("apikey", manager.GetApiKey());
            }

            mock.Verify(a => a.Logout("hakusai", "password"), Times.Once());
        }
示例#3
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);
        }
示例#4
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);
        }