Exemplo n.º 1
0
        public void Adds_new_GamingConsole_to_the_GamingConsole_repository()
        {
            var gameConsole = new GamingConsole();
            GamingConsoleRepositoryMock.Setup(repo => repo.Add(gameConsole)).Verifiable();

            GamingConsoleController.Create(gameConsole);

            GamingConsoleRepositoryMock.Verify(repo => repo.Add(gameConsole));
        }
Exemplo n.º 2
0
        public void Returns_Edit_view_with_GamingConsole_retireved_from_repository()
        {
            var gamingConsole = new GamingConsole();
            GamingConsoleRepositoryMock.Setup(repo => repo.GetById(guid)).Returns(gamingConsole);

            var viewResult = GamingConsoleController.Edit(guid);

            viewResult.ViewName.ShouldEqual(string.Empty);
            viewResult.Model.ShouldEqual(gamingConsole);
        }
Exemplo n.º 3
0
        public void Returns_create_view_if_new_GamingConsole_name_already_exists()
        {
            SetupBranchRepositoryToReturnSomeRandomBranches();
            var gameConsole = new GamingConsole { Name = "foo", BranchName = "bar" };
            GamingConsoleRepositoryMock.Setup(repo => repo.IsConsoleNameExists("foo", "bar")).Returns(true);

            var viewResult = GamingConsoleController.Create(gameConsole) as ViewResult;

            viewResult.Model.ShouldEqual(gameConsole);
            viewResult.ViewName.ShouldEqual(string.Empty);
            AssertModelError(GamingConsoleController, "Name", "Console name already exists in the selected branch");
            AssertRandomBranchesPresentInViewBag(viewResult);
        }
Exemplo n.º 4
0
        public void Returns_create_view_if_new_GamingConsole_is_invalid()
        {
            SetupBranchRepositoryToReturnSomeRandomBranches();
            GamingConsoleController.ModelState.AddModelError("Name", "The Name field is required");

            var gameConsole = new GamingConsole();

            var viewResult = GamingConsoleController.Create(gameConsole) as ViewResult;

            viewResult.Model.ShouldEqual(gameConsole);
            viewResult.ViewName.ShouldEqual(string.Empty);
            AssertRandomBranchesPresentInViewBag(viewResult);
        }
Exemplo n.º 5
0
        public ActionResult Create(GamingConsole gamingConsole)
        {
            if (ModelState.IsValid)
            {
                if (!gamingConsoleRepository.IsConsoleNameExists(gamingConsole.Name, gamingConsole.BranchName))
                {
                    gamingConsoleRepository.Add(gamingConsole);
                    return RedirectToAction("Index");
                }
                ModelState.AddModelError("name", "Console name already exists in the selected branch");
            }

            ViewBag.Branches = MapBranchesToSelectListItems(branchRepository);
            return View(gamingConsole);
        }
Exemplo n.º 6
0
        public ActionResult Edit(GamingConsole gamingConsole)
        {
            gamingConsoleRepository.Update(gamingConsole);

            return RedirectToAction("Index");
        }
Exemplo n.º 7
0
 public ViewResult Create()
 {
     var gameConsole = new GamingConsole();
     ViewBag.Branches = MapBranchesToSelectListItems(branchRepository);
     return View(gameConsole);
 }
Exemplo n.º 8
0
 public void SetUp()
 {
     gamingConsole = new GamingConsole();
 }