Exemplo n.º 1
0
 public void Init()
 {
     using (var context = new MyContext())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM Game");
         context.Database.ExecuteSqlCommand("DELETE FROM Setup");
         context.SaveChanges();
     }
 }
Exemplo n.º 2
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);


        }