Esempio n. 1
0
        public async void Fight_ShouldDecreaseRobotPoints()
        {
            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                }
            };

            var mockUserStore   = new Mock <IUserStore <User> >();
            var mockUserManager = new Mock <UserManager <User> >(
                mockUserStore.Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);


            this.dbContext        = MockDbContext.GetContext();
            this.service          = new RobotDataService(dbContext, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.armorService     = new ArmorDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.weaponService    = new WeaponDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.creepService     = new CreepDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper());
            this.dbContextService = new DbContextService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);



            var robot = new Models.Robots.Robot()
            {
                Id            = 1,
                BaseHealth    = 1000,
                CurrentHealth = 1000,
                BaseDamage    = 100,
                Type          = "Fire",
                ImageUrl      = "https://i.ytimg.com/vi/Rrb4jW_uJxE/hqdefault.jpg"
            };
            var creep = new Creep()
            {
                Id       = 1,
                Name     = "aaaa",
                Type     = "Fire",
                Health   = 1000,
                Damage   = 100,
                Bounty   = 10,
                ImageUrl = "1"
            };

            var controller = new BattleController
                             (
                mockUserManager.Object,
                MockAutoMapper.GetAutoMapper(),
                this.service,
                this.creepService,
                this.dbContextService
                             );

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, "Admin")
                    }))
                }
            };
            this.dbContext.Robots.Add(robot);
            this.dbContext.Creeps.Add(creep);
            this.dbContext.SaveChanges();
            await controller.Fight(robot.Id, creep.Id);

            Assert.AreEqual(0, robot.CurrentHealth);
        }
        public async void RepairCenter_ShouldRepairArmor()
        {
            var users = new[]
            {
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                }
            };



            //setup your expectations here

            var mockUserStore   = new Mock <IUserStore <User> >();
            var mockUserManager = new Mock <UserManager <User> >(
                mockUserStore.Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);
            this.dbContext        = MockDbContext.GetContext();
            this.service          = new RobotDataService(dbContext, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.armorService     = new ArmorDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.weaponService    = new WeaponDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.creepService     = new CreepDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper());
            this.dbContextService = new DbContextService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.userService      = new UserDataService(dbContext, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);

            var controller = new RepairCenterController(mockUserManager.Object, MockAutoMapper.GetAutoMapper(), dbContextService, this.service, armorService, weaponService, userService);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, "Admin")
                    }))
                }
            };
            var tempData = new TempDataDictionary(controller.HttpContext, Mock.Of <ITempDataProvider>());

            controller.TempData = tempData;

            var newwwwUser = new User()
            {
                Id = "1", Coins = 251
            };
            var armor = new ArmorDetailsViewModel()
            {
                Id           = 1,
                Name         = "mechoo",
                ArmorPoints  = 101,
                CurrentArmor = 50,
                Durability   = 50,
                ImageUrl     = "kk",
                Price        = 120,
            };

            dbContext.Users.Add(newwwwUser);
            var actualArmor = new Armor()
            {
                Id          = 1,
                Name        = "mechoo",
                ArmorPoints = 101,
                Durability  = 50,
                ImageUrl    = "kk",
                Price       = 120,
                UserId      = "1",
                User        = newwwwUser
            };

            this.dbContext.Armors.Add(actualArmor);
            this.dbContext.SaveChanges();
            await controller.Repair(1, "ArmorRepairViewModel");

            Assert.AreEqual(1, newwwwUser.Coins);
        }