public async Task GetsStatsById() { using (var context = new ApplicationDbContext(_options)) { context.Stats.AddRange( new Stats { Id = 1 }, new Stats { Id = 2 }); context.SaveChanges(); } using (var context = new ApplicationDbContext(_options)) { var statsRepository = new StatsRepository(context); var stats = await statsRepository.GetById(1); var stats2 = await statsRepository.GetById(2); Assert.NotNull(stats); Assert.NotNull(stats2); Assert.Equal(1, stats.Id); Assert.Equal(2, stats2.Id); } }
public void UpdateStats() { StatsRepository repo = new StatsRepository(new StatsSQLContext()); Stats s = repo.GetById(2); s.Spirit += 10; int spirit = s.Spirit; repo.Update(s); s = repo.GetById(2); Assert.AreEqual(s.Spirit, spirit, "Stats weren't updated."); s.Spirit -= 10; repo.Update(s); }
public void StatsSelect() { StatsRepository repo = new StatsRepository(new StatsSQLContext()); Stats s = repo.GetById(1); Assert.IsNotNull(s, "Stats wasn't correctly retrieved"); }
public ActionResult UpdateFunction(DatabaseStatModel model) { var repo = new StatsRepository(new StatsSQLContext()); Stats s = repo.GetById(model.SelectedId); Stats prevS = new Stats(s.Level, s.Experience, s.Health, s.Spirit, s.HealthRegen, s.SpiritRegen, s.Strength, s.Dexterity, s.Intelligence); prevS.Id = s.Id; if (model.Level != 0) { s.Level = model.Level; } if (model.Health != 0) { s.Health = model.Health; } if (model.Spirit != 0) { s.Spirit = model.Spirit; } if (model.Strength != 0) { s.Strength = model.Strength; } if (model.Dexterity != 0) { s.Dexterity = model.Dexterity; } if (model.Intelligence != 0) { s.Intelligence = model.Intelligence; } repo.Update(s); return(Content($"Succesfully updated </br>{prevS.ToReadableString()} </br>to </br>{s.ToReadableString()}")); }