Example #1
0
        public void HubContextService_ChangeUsernameWithActiveGameAndToAlternatePlayerWithActiveGame()
        {
            var session = new Session();
            session.User = new User();
            session.User.Username = "******";
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            var mockHubContext = new MockHubContext("connection #5");

            IActiveGoGame activeGame;
            CreateActiveGame(session.User, null, "adbbdfd999bd4541ba4d742a858dc5f1", out activeGame); var game = new GoGame();

            User newUser = new User();
            newUser.Username = "******";
            newUser.Id = 8;

            GoGamePlayer newPlayer = new GoGamePlayer();
            newPlayer.User = newUser;
            newPlayer.UserId = 8;
            newPlayer.Id = 14;

            var newGame = new GoGame();
            newGame.BlackPlayer = newPlayer;
            newGame.WhitePlayer = null;
            newGame.GameState = "0123400003430400";
            newGame.HubId = "5ad61645b24f4f40b55309c96c1a9b81";
            newGame.Id = 23;

            var dataService = new Mock<IDataService>();
            dataService.Setup(x => x.FindOrCreateUser(It.Is<string>(y => y.Equals("new user")))).Returns(newUser);
            dataService.Setup(x => x.FindGoPlayer(It.Is<int>(y => y == 8))).Returns(newPlayer);
            dataService.Setup(x => x.FindActiveGoGame(It.Is<int>(y => y == 14))).Returns(newGame);

            mockHubContext.Client<IHubClient>("5ad61645b24f4f40b55309c96c1a9b81").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable();
            mockHubContext.Groups.Setup(x => x.Remove(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("adbbdfd999bd4541ba4d742a858dc5f1")))).Verifiable();
            mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("5ad61645b24f4f40b55309c96c1a9b81")))).Verifiable();
            mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.setUsername(It.Is<string>(y => y.Equals("new user")))).Verifiable();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, null, dataService.Object);
            hubGoService.ChangeUser("new user");
            mockHubContext.VerifyClients();
            mockHubContext.Groups.VerifyAll();
        }
Example #2
0
        public void HubContextService_TestGetInitialDataNoUserNoActiveGame()
        {
            var session = new Session();
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            var mockHubContext = new MockHubContext("connection #5");
            mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.setUsername(It.Is<string>(y => y.Equals("none")))).Verifiable();

            var activeGame = new Mock<IActiveGoGame>();
            activeGame.Setup(x => x.Game).Returns((GoGame)null);

            var goService = new Mock<IGoService>();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame.Object, goService.Object, null);
            hubGoService.GetInitialData();
            mockHubContext.VerifyClients();
        }
Example #3
0
        private void TestNullSession(Action<GameOfGoHubService> action)
        {
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)null);

            var mockHubContext = new MockHubContext("connection #5");
            mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.createSession()).Verifiable();

            var activeGame = new Mock<IActiveGoGame>();
            activeGame.Setup(x => x.Game).Returns((GoGame)null);

            var goService = new Mock<IGoService>();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame.Object, goService.Object, null);
            action.Invoke(hubGoService);
            mockHubContext.VerifyClients();
        }
Example #4
0
        public void HubContextService_TestValidPlayUpdatesGame()
        {
            var session = new Session();
            session.User = new User();
            session.User.Username = "******";
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            var mockHubContext = new MockHubContext("connection #5");
            mockHubContext.Client<IHubClient>("1049b75fc3d64ff2aec1c91efa8f49c7").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable();

            IActiveGoGame activeGame;
            CreateActiveGame(session.User, null, "1049b75fc3d64ff2aec1c91efa8f49c7", out activeGame);

            var goService = new Mock<IGoService>();
            goService.Setup(x => x.Play(It.Is<int>(y => y == 10), It.Is<int>(z => z == 2))).Returns(true).Verifiable();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, goService.Object, null);
            hubGoService.Play(10, 2);
            mockHubContext.VerifyClients();
        }
Example #5
0
        public void HubContextService_TestNewGame()
        {
            var session = new Session();
            session.User = new User();
            session.User.Username = "******";
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            IActiveGoGame activeGame;
            var game = CreateActiveGame(session.User, null, "adbbdfd999bd4541ba4d742a858dc5f1", out activeGame);

            var mockHubContext = new MockHubContext("connection #5");
            mockHubContext.Client<IHubClient>("5ad61645b24f4f40b55309c96c1a9b81").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable();

            var newGame = new GoGame();
            newGame.BlackPlayer = game.WhitePlayer;
            newGame.WhitePlayer = null;
            newGame.GameState = "0123400003430400";
            newGame.HubId = "5ad61645b24f4f40b55309c96c1a9b81";
            newGame.Id = 23;

            var goService = new Mock<IGoService>();
            goService.Setup(x => x.NewGame()).Returns(newGame).Verifiable();

            mockHubContext.Groups.Setup(x => x.Remove(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("adbbdfd999bd4541ba4d742a858dc5f1")))).Verifiable();
            mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("5ad61645b24f4f40b55309c96c1a9b81")))).Verifiable();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, goService.Object, null);
            hubGoService.NewGame();
            mockHubContext.VerifyClients();
            mockHubContext.Groups.VerifyAll();
        }
Example #6
0
        public void HubContextService_TestGetInitialDataWithUserWithActiveGame()
        {
            var session = new Session();
            session.User = new User();
            session.User.Username = "******";
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            var mockHubContext = new MockHubContext("connection #5");
            mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.setUsername(It.Is<string>(y => y.Equals("White Player")))).Verifiable();

            IActiveGoGame activeGame;
            CreateActiveGame(session.User, null, "96cc91ebea4740aaa91099dd0ca4272a", out activeGame);

            mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(z => z.Equals("96cc91ebea4740aaa91099dd0ca4272a")))).Verifiable();
            mockHubContext.Client<IHubClient>("96cc91ebea4740aaa91099dd0ca4272a").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable();

            var goService = new Mock<IGoService>();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, goService.Object, null);
            hubGoService.GetInitialData();
            mockHubContext.VerifyClients();
            mockHubContext.Groups.VerifyAll();
        }