Exemplo n.º 1
0
        public BusinessLayerTests()
        {
            var options = SqliteInMemory.CreateOptions <ApplicationContext>();

            context = new ApplicationContext(options);
            context.Database.EnsureCreated();

            // Seed Inventory content
            context.SeedItemTypes();
            context.SeedItemImages();


            // Seed Monster content
            context.SeedMonsterModels();
            context.SeedMonsterNames();
            context.SeedMonsterTitles();


            inventoryRepository = new InventoryRepository(context);
            inventoryService    = new InventoryService(inventoryRepository);

            playerRepository = new PlayerRepository(context);
            playerService    = new PlayerService(playerRepository);

            monsterRepository = new MonsterRepository(context);
            monsterService    = new MonsterService(monsterRepository);

            knightRepository   = new KnightRepository(context);
            landmarkRepository = new LandmarkRepository(context);
            landmarkService    = new LandmarkService(landmarkRepository, knightRepository);
        }
Exemplo n.º 2
0
        public void ShouldNotAddNullKnight()
        {
            KnightRepository.Add(null);

            var knights = _context.Knights.ToList();

            Assert.AreEqual(0, knights.Count());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            MessageType messageType = KnightRepository.Remove(id);

            if (messageType == MessageType.Success)
            {
                return(RedirectToAction("Index"));
            }
            return(HttpNotFound());
        }
        //
        // GET: /Knight/Details/5

        public ActionResult Details(int id = 0)
        {
            Knight knight = KnightRepository.FindById(id);

            if (knight == null)
            {
                return(HttpNotFound());
            }
            return(View(knight));
        }
        //
        // GET: /Knight/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Knight knight = KnightRepository.FindById(id);

            if (knight == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(knight));
        }
Exemplo n.º 6
0
        public void CanAddKnight()
        {
            Knight expected = PersonFactory.CreateKnight("Arthur");

            KnightRepository.Add(expected);

            var knights = _context.Knights.ToList();

            Assert.AreEqual(1, knights.Count());
            Assert.AreEqual(expected, knights.FirstOrDefault());
        }
 public ActionResult Create(Knight knight)
 {
     if (ModelState.IsValid && knight != null)
     {
         KnightRepository.Add(knight);
         return(RedirectToAction("Index"));
     }
     ViewBag.Message = Messages.Error_Field_Check;
     ViewBag.Title   = PersonResource.Title_CreateKnight;
     return(View(knight));
 }
Exemplo n.º 8
0
        public void RetrieveKnightById()
        {
            Knight expected = PersonFactory.CreateKnight("Arthur");

            _context.Knights.Add(expected);
            _context.SaveChanges();

            Knight actual = KnightRepository.FindById(expected.Id);

            ;
            Assert.AreEqual(expected, actual);
        }
        //
        // GET: /Knight/Delete/5

        public ActionResult Delete(int id = 0)
        {
            if (id > 0)
            {
                Knight knight = KnightRepository.FindById(id);
                if (knight != null)
                {
                    return(View(knight));
                }
            }
            return(HttpNotFound());
        }
Exemplo n.º 10
0
        public void KnightShouldNotUseBadIdToDelete()
        {
            Knight expected1 = PersonFactory.CreateKnight("Arthur");
            Knight expected2 = PersonFactory.CreateKnight("Lancelot");

            _context.Knights.Add(expected1);
            _context.Knights.Add(expected2);
            _context.SaveChanges();

            KnightRepository.Remove(6);

            var knights = _context.Knights.ToList();

            Assert.AreEqual(2, knights.Count());
        }
Exemplo n.º 11
0
        public void KnightCanBeUpdated()
        {
            Knight expected = PersonFactory.CreateKnight("Arthur");

            _context.Knights.Add(expected);
            _context.SaveChanges();

            expected.Email     = "*****@*****.**";
            expected.FirstName = "Arthur Junior";

            MessageType message = KnightRepository.Update(expected);

            Assert.AreEqual(MessageType.Success, message);
            Assert.AreEqual(expected, _context.Knights.Find(expected.Id));
        }
Exemplo n.º 12
0
        public void CanDeleteKnight()
        {
            Knight expected1 = PersonFactory.CreateKnight("Arthur");
            Knight expected2 = PersonFactory.CreateKnight("Lancelot");

            _context.Knights.Add(expected1);
            _context.Knights.Add(expected2);
            _context.SaveChanges();

            KnightRepository.Remove(expected1.Id);

            var knights = _context.Knights.ToList();

            Assert.AreEqual(1, knights.Count());
            Assert.AreEqual(expected2, knights.FirstOrDefault());
        }
Exemplo n.º 13
0
 public ActionResult Edit(Knight knight)
 {
     if (knight == null)
     {
         return(HttpNotFound());
     }
     if (ModelState.IsValid)
     {
         MessageType messageType = KnightRepository.Update(knight);
         if (messageType == MessageType.Success)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(knight));
 }
Exemplo n.º 14
0
 public virtual void TestInitialize()
 {
     LoadContext();
     KnightRepository = new KnightRepository(_context);
 }
 public LandmarkService(LandmarkRepository landmarkRepository, KnightRepository knightRepository)
 {
     this.landmarkRepo = landmarkRepository;
     this.knightRepo   = knightRepository;
 }
Exemplo n.º 16
0
        public void KnightCanNotEditANullKnight()
        {
            MessageType message = KnightRepository.Update(null);

            Assert.AreEqual(MessageType.Error, message);
        }
Exemplo n.º 17
0
        public void ShouldNotRetrieveKnightWithId0()
        {
            Knight actual = KnightRepository.FindById(0);

            Assert.IsNull(actual);
        }
Exemplo n.º 18
0
        //
        // GET: /Knight/

        public ActionResult Index()
        {
            return(View(KnightRepository.FindAll()));
        }
Exemplo n.º 19
0
 public KnightController()
 {
     KnightRepository = new KnightRepository(_context);
 }
Exemplo n.º 20
0
 public KnightsService(KnightRepository repo)
 {
     _repo = repo;
 }