Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        public void Add(AddNPCInputModel model)
        {
            var npc = new NPC
            {
                Name = model.Name
            };

            this._db.NPCs.Add(npc);
            this._db.SaveChanges();
        }
Beispiel #3
0
        public IActionResult Add(AddNPCInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            _NPCsService.Add(inputModel);

            return(Redirect(NPCs_Root_Path));
        }