public void Add_SavesToDatabase() { var options = new DbContextOptionsBuilder <GameInfoContext>() .UseInMemoryDatabase(databaseName: "AddAchievement_ToDb") .Options; using (var context = new GameInfoContext(options)) { var achievementToAdd = new AddAchievementInputModel() { Name = "Achievement", AcquisitionConditions = "How to get" }; var service = new AchievementsService(context, null); service.Add(achievementToAdd); var expectedAchievement = new Achievement() { Name = achievementToAdd.Name, AcquisitionConditions = achievementToAdd.AcquisitionConditions }; Assert.NotEmpty(context.Achievements); Assert.Equal(expectedAchievement.Name, context.Achievements.First().Name); Assert.Equal(expectedAchievement.AcquisitionConditions, context.Achievements.First().AcquisitionConditions); } }
public IActionResult Add(AddAchievementInputModel inputModel) { if (!ModelState.IsValid) { return(View()); } _achievementsService.Add(inputModel); return(Redirect(Achievements_Root_Path)); }
public void Add(AddAchievementInputModel model) { var achievement = new Achievement { Name = model.Name, AcquisitionConditions = model.AcquisitionConditions }; this._db.Achievements.Add(achievement); this._db.SaveChanges(); }