public GameContract GetGameResult(int gameId)
        {
            using(var context = new MyContext())
            {
                var game = context.Games.Find(gameId);

                if (game == null)
                    return null;

                var gameContract = new GameContract();
               
                gameContract.Id = game.Id;
                gameContract.TimeStamp = game.TimeStamp;
                gameContract.PlayerOne = new SetupContract(game.PlayerOne);

                if(game.PlayerTwo != null)
                    gameContract.PlayerTwo = new SetupContract(game.PlayerTwo);
                
                if(game.Winner != null)
                    gameContract.Winner = new SetupContract(game.Winner);

                return gameContract;
               
            }
        }
        public void LMServiceTest_SendSetupTwice_Success()
        {
            //1. Arrange
            ClearTables();
            ILMService service = new LMService();

            var setup = new SetupContract()
            {
                PlayerName = "Linksonder",
                Top = "Jax",
                Jungle = "Zac",
                Mid = "Katarina",
                Supp = "Sona",
                Adc = "Vayne"
            };

            //2. Act
            int id = service.SendSetup(setup);

            setup.PlayerName = "Rechtsboven";

            id = service.SendSetup(setup);

            //3. Assert
            using (var context = new MyContext())
            {
                var game = context.Games.First();

                Assert.AreEqual(1, context.Games.Count());
                Assert.IsNotNull(game.PlayerOne);
                Assert.IsNotNull(game.PlayerTwo);
                Assert.IsNotNull(game.Winner);
                Assert.AreEqual("Linksonder", game.PlayerOne.PlayerName);
            }
        }
예제 #3
0
 public void Init()
 {
     using (var context = new MyContext())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM Game");
         context.Database.ExecuteSqlCommand("DELETE FROM Setup");
         context.SaveChanges();
     }
 }
예제 #4
0
        public void TestContext()
        {
            //1. arrange
            var context = new MyContext();

            context.Setups.Add(new Setup()
            {
                Jungle = "Shaco",
                PlayerName = "Linksonder"
            });

            
            //2. act
            context.SaveChanges();

            //3. assert
            var result = context.Setups.ToList();
            Assert.AreEqual(1, result.Count);
        }
        public int SendSetup(SetupContract setup)
        {
                var setupModel = new Setup()
                {
                    PlayerName = setup.PlayerName,
                    Top = setup.Top,
                    Jungle = setup.Jungle,
                    Mid = setup.Mid,
                    Supp = setup.Supp,
                    Adc = setup.Adc
                };

             using (var context = new MyContext())
             {
                 var game = context.Games.FirstOrDefault(m => m.PlayerTwo == null);

                 if(game != null)
                 {
                     game.PlayerTwo = setupModel;
                     game.Winner = game.PlayerOne;
                     game.TimeStamp = DateTime.Now;
                 }
                 else
                 {
                     game = new Game()
                     {
                         PlayerOne = setupModel,
                         TimeStamp = DateTime.Now,
                     };

                     context.Games.Add(game);
                 }

                context.SaveChanges();
                return game.Id;
            }
        }
        public void LMServiceTest_GetGameResult_Success()
        {

            //1. Arrange
            ILMService service = new LMService();
            ClearTables();
            Game game = null;

            using (var context = new MyContext())
            {
                game = new Game()
                {
                    PlayerOne = new Setup()
                    {
                        PlayerName = "Linksonder"
                    },
                    TimeStamp = new DateTime(1990, 03, 15)
                };

                context.Games.Add(game);
                context.SaveChanges();
            }

            //2. Act
            GameContract result = service.GetGameResult(game.Id);

            //3. Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.PlayerOne);
            Assert.IsNull(result.PlayerTwo);
            Assert.IsNull(result.Winner);


        }