private PlatoonService CreatePlatoonService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new PlatoonService(userId);

            return(service);
        }
示例#2
0
 public GameServiceTest()
 {
     _unitService    = new UnitService();
     _platoonService = new PlatoonService(_unitService);
     _armyService    = new ArmyService(_platoonService);
     _gameService    = new GameService(_armyService, _platoonService);
 }
示例#3
0
        public void PlatoonPut()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <ApplitactionDbContext>()
                              .UseSqlite(connection)
                              .Options;
                //var context = new ApplitactionDbContext(options);

                using (var context = new ApplitactionDbContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new ApplitactionDbContext(options))
                {
                    var g = new Strategy_game.Models.Game();
                    var c = new Strategy_game.Models.Country()
                    {
                        CountryName = "zzzz"
                    };
                    var a = new Strategy_game.Models.Archer()
                    {
                        OwnerCountry = c, Counter = 2
                    };
                    var h = new Strategy_game.Models.Horseman()
                    {
                        OwnerCountry = c, Counter = 2
                    };
                    var s = new Strategy_game.Models.Elite()
                    {
                        OwnerCountry = c, Counter = 2
                    };
                    var f = new Strategy_game.Models.Farm()
                    {
                        OwnerCountry = c, Counter = 4
                    };
                    var b = new Strategy_game.Models.Barrack()
                    {
                        OwnerCountry = c, Counter = 2
                    };



                    context.Games.Add(g);
                    context.Countries.Add(c);
                    context.Archers.Add(a);
                    context.Horsemans.Add(h);
                    context.Elites.Add(s);
                    context.Farms.Add(f);
                    context.Barracks.Add(b);



                    context.SaveChanges();
                    var ch = context.Countries.FirstOrDefaultAsync(d => d.CountryName == "zzzz").Result;

                    //var casd = context.Countries.FirstOrDefaultAsync();
                    var p = new Platoon()
                    {
                        Owner   = ch,
                        Archers = new Archer()
                        {
                            Counter = 150
                        },
                        Horsemans = new Horseman()
                        {
                            Counter = 150
                        },
                        Soldiers = new Elite()
                        {
                            Counter = 150
                        },
                    };
                    context.Platoons.Add(p);
                    context.SaveChanges();
                }

                using (var context = new ApplitactionDbContext(options))
                {
                    var service = new PlatoonService(context);



                    var p = context.Platoons
                            .Include(pts => pts.Archers)
                            .Include(pts => pts.Horsemans)
                            .Include(pts => pts.Soldiers)
                            .Include(pts => pts.Owner).FirstOrDefaultAsync().Result;



                    //service.DoOneRound();
                    var from = context.Countries.FirstOrDefaultAsync(C => C.CountryName == "zzzz").Result;

                    var ra = context.Archers.Include(Ra => Ra.OwnerCountry).FirstOrDefaultAsync(C => C.OwnerCountry.CountryName == "zzzz").Result;
                    var rh = context.Horsemans.Include(Ra => Ra.OwnerCountry).FirstOrDefaultAsync(C => C.OwnerCountry.CountryName == "zzzz").Result;
                    var rs = context.Elites.Include(Ra => Ra.OwnerCountry).FirstOrDefaultAsync(C => C.OwnerCountry.CountryName == "zzzz").Result;

                    service.putUnitToPlatoon(from.CountryId, p.PlatoonId);
                    service.putHorsemanInPlatoon(from.CountryId, p.PlatoonId);
                    service.putSoldierInPlatoon(from.CountryId, p.PlatoonId);

                    Assert.Equal(1, ra.Counter);
                    Assert.Equal(1, rh.Counter);
                    Assert.Equal(1, rs.Counter);

                    //Assert.Equal(0, p.Intent);
                    Assert.Equal(151, p.Archers.Counter);
                    Assert.Equal(151, p.Horsemans.Counter);
                    Assert.Equal(151, p.Soldiers.Counter);
                }
            }
            finally
            {
                connection.Close();
            }
        }