示例#1
0
 void Start()
 {
     _renderer       = GetComponent <SpriteRenderer>();
     _headController = GetComponentInParent <HeadController>();
     _mover          = GetComponentInParent <TestMove>();
     _mover.RegisterOnStateChange(OnStateChange);
     SetTargetSprite();
 }
示例#2
0
        public void UT_When_HandleMove_Then_Success()
        {
            var sessionName = "player1-vs-player2";
            var player1 = new TestSessionPlayer()
            {
                SessionName = sessionName,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 1",
                    Name = "player1"
                }
            };
            var player2 = new TestSessionPlayer()
            {
                SessionName = sessionName,
                PendingToMove = true,
                Information = new User
                {
                    DisplayName = "Player 2",
                    Name = "player2"
                }
            };
            var session = new GameSession(player1, player2);

            var testMoveObject = new TestMoveObject { Answer = "Test Answer" };
            var testMove = new TestMove(testMoveObject);

            var moveResponse = new TestResponse(new TestResponseObject { IsCorrect = true }) { IsWin = false };

            var sessionServiceMock = new Mock<ISessionService>();

            sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == sessionName)))
                .Returns(session)
                .Verifiable();

            var moveProcessorMock = new Mock<IMoveProcessor<TestMoveObject, TestResponseObject>>();

            moveProcessorMock
                .Setup(p => p.Process(It.Is<SessionGamePlayer>(x => x == player2), It.Is<IGameMove<TestMoveObject>>(m => m == testMove)))
                .Returns(moveResponse)
                .Verifiable();

            this.moveService = new MoveService<TestMoveObject, TestResponseObject>(sessionServiceMock.Object, moveProcessorMock.Object);

            var response = this.moveService.Handle(sessionName, player1.Information.Name, testMove);

            sessionServiceMock.VerifyAll();
            moveProcessorMock.VerifyAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(moveResponse, response);
        }
示例#3
0
 void Awake()
 {
     dir   = Vector2.zero;
     mover = GetComponent <TestMove> ();
 }
        public void UT_When_HandleWinnerGameMove_Then_Success()
        {
            var testMoveObject = new TestMoveObject { Answer = "Test Answer" };
            var testMove = new TestMove(testMoveObject);
            var moveResponse = new TestResponse(new TestResponseObject { IsCorrect = true }) { IsWin = true };
            var moveResultNotificationObject = Mock.Of<IMoveResultReceivedServerMessage>(o => o.SessionName == this.sessionName && o.PlayerName == this.requestPlayer);

            this.sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == this.session.Name)))
                .Returns(this.session)
                .Verifiable();
            this.moveFactoryMock
                .Setup(f => f.Create(It.Is<string>(s => s == this.moveInformation)))
                .Returns(testMove)
                .Verifiable();
            this.moveServiceMock
                .Setup(s => s.Handle(It.Is<string>(x => x == this.session.Name), It.Is<string>(x => x == this.requestPlayer),
                    It.Is<IGameMove<TestMoveObject>>(m => m == testMove)))
                .Returns(moveResponse)
                .Verifiable();
            this.sessionHistoryServiceMock
                .Setup(x => x.Add(It.Is<string>(s => s == this.sessionName),
                    It.Is<string>(s => s == this.requestPlayer),
                    It.Is<ISessionHistoryItem<TestMoveObject, TestResponseObject>>(i => i.Move == testMove.MoveObject
                        && i.Response == moveResponse.MoveResponseObject)))
                .Verifiable();
            this.sessionServiceMock
                    .Setup(s => s.Finish(It.Is<string>(x => x == this.sessionName)))
                    .Verifiable();

            var gameProgressPluginComponent = this.GetGameProgressPluginComponent();
            var gameMoveRequest = new SendMoveClientMessage
            {
                SessionName = this.sessionName,
                UserName = this.requestPlayer,
                MoveInformation = "Test"
            };
            var clientContract = new ClientContract
            {
                Type = GamifyClientMessageType.SendMove,
                Sender = this.requestPlayer,
                SerializedClientMessage = this.serializer.Serialize(gameMoveRequest)
            };
            var canHandle = gameProgressPluginComponent.CanHandleClientMessage(clientContract);

            gameProgressPluginComponent.HandleClientMessage(clientContract);

            this.moveServiceMock.VerifyAll();
            this.sessionServiceMock.VerifyAll();
            this.sessionHistoryServiceMock.VerifyAll();
            this.moveFactoryMock.VerifyAll();
            this.notificationServiceMock.Verify(s => s.SendBroadcast(It.Is<int>(t => t == GamifyServerMessageType.GameFinished),
                    It.Is<object>(o => ((GameFinishedServerMessage)o).SessionName == this.session.Name &&
                    ((GameFinishedServerMessage)o).WinnerPlayerName == this.requestPlayer),
                    It.Is<string>(x => x == this.session.Player2Name),
                    It.Is<string>(x => x == this.session.Player1Name)));

            Assert.IsTrue(canHandle);
        }