/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { int id = (int)e.Parameter; DataContext = new ArmorDetailsViewModel(id); base.OnNavigatedTo(e); }
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); }