public void Add_SavesToDatabase() { var options = new DbContextOptionsBuilder <GameInfoContext>() .UseInMemoryDatabase(databaseName: "AddNPC_ToDb") .Options; using (var context = new GameInfoContext(options)) { var NPCToAdd = new AddNPCInputModel() { Name = "NPC Name" }; var service = new NPCsService(context, null); service.Add(NPCToAdd); var expectedNPC = new NPC() { Name = NPCToAdd.Name }; Assert.NotEmpty(context.NPCs); Assert.Equal(expectedNPC.Name, context.NPCs.First().Name); } }
public void Add(AddNPCInputModel model) { var npc = new NPC { Name = model.Name }; this._db.NPCs.Add(npc); this._db.SaveChanges(); }
public IActionResult Add(AddNPCInputModel inputModel) { if (!ModelState.IsValid) { return(View()); } _NPCsService.Add(inputModel); return(Redirect(NPCs_Root_Path)); }