Exemple #1
0
        public async Task SendMoveAI_GivenParameters_ExpectSomething()
        {
            //Arrange
            var state = new State(new[] {
                "...|.x.|...", "...|...|...", "...|...|...",
                "...|...|...", "...|...|...", "...|...|...",
                "...|...|...", "...|...|...", "...|...|..."
            });
            var agniKai = new AgniKai
            {
                Ticket = "Ticket"
            };

            agniKai.AddGamer(new Player
            {
                AgniKaiTicket = "Ticket",
                Name          = "Player-1",
                Indicator     = Field.X
            });
            agniKai.AddGamer(new AI
            {
                AgniKaiTicket = "Ticket",
                Name          = "Gamer-1",
                Indicator     = Field.O
            });
            var mockDatabase = Substitute.For <IDatabaseRepository>();

            mockDatabase.RecordMoveAsync(Arg.Any <string>(), Arg.Any <(int, int)>(), Arg.Any <Field>()).Returns(Task.CompletedTask);
            mockDatabase.GetStateAsync(Arg.Any <string>()).Returns(Task.FromResult(state));
            mockDatabase.GetAgniKaiByTicketAsync(Arg.Any <string>()).Returns(Task.FromResult(agniKai));
            var clients = Substitute.For <IHubCallerConnectionContext <object> >();
            var uiMock  = Substitute.For <IMockClient>();

            uiMock.When(x => x.broadcastState(Arg.Any <State>())).Do(x => { });
            clients.Group(Arg.Any <string>()).Returns(uiMock);
            var hub = new GameHub(mockDatabase)
            {
                Clients = clients
            };

            //Act
            await hub.SendMoveAI("Ticket", 0, 4, 'x');

            //Assert
            await mockDatabase.Received(1).RecordMoveAsync("Ticket", (0, 4), Field.X);

            await mockDatabase.Received(1).RecordMoveAsync("Ticket", Arg.Any <(int, int)>(), Field.O);

            await mockDatabase.Received(2).GetStateAsync("Ticket");

            await mockDatabase.Received(1).GetAgniKaiByTicketAsync("Ticket");

            uiMock.Received(1).broadcastState(state);
        }
        public void AddGamer_GivenPreviousGamerWithIndicatorX_ShouldAddGamerWithIndicatorO()
        {
            //Arrange
            var agniKai = new AgniKai {
                Ticket = string.Empty
            };
            var gamer = new Player {
                AgniKaiTicket = string.Empty, Name = "gamer_2"
            };

            //Act
            agniKai.AddGamer(new Player {
                AgniKaiTicket = string.Empty, Name = "gamer_1", Indicator = Field.X
            });
            agniKai.AddGamer(gamer);

            //Assert
            Assert.AreEqual(gamer.Indicator, Field.O);
        }
        public void GetNextGamerId_GivenAgniKaiWithOneGamer_ShouldReturnTwo()
        {
            //Arrange
            var agniKai = new AgniKai {
                Ticket = string.Empty
            };

            //Act
            agniKai.AddGamer(new AI {
                AgniKaiTicket = string.Empty, Name = "gamer_1"
            });

            //Assert
            Assert.AreEqual(2, agniKai.GetNextGamerId());
        }
        public void GetGamerByIndicator_GivenGamerExists_ExpectGamer()
        {
            //Arrange
            var gamer = new AI {
                Indicator = Field.O
            };
            var agniKai = new AgniKai {
                Ticket = "Ticket"
            };

            //Act
            agniKai.AddGamer(gamer);

            //Assert
            agniKai.GetGamerByIndicator(Field.O).ShouldBeEquivalentTo(gamer);
        }
        public void AddGamer_GivenGamer_ShouldAddGamer()
        {
            //Arrange
            var agniKai = new AgniKai {
                Ticket = string.Empty
            };
            var gamer = new AI {
                AgniKaiTicket = string.Empty, Name = "gamer_1"
            };

            //Act
            agniKai.AddGamer(gamer);
            var result = agniKai.GetGamerByName("gamer_1");

            //Assert
            result.ShouldBeEquivalentTo(gamer);
        }