Example #1
0
        public IActionResult ResolveTaxToSupport(int id, [Bind("Id,Cities")] TaxToSupportInput viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                GameLoop loop = new GameLoop(_context, id);
                loop.ResolveTaxToSupport(viewModel.Cities);
                return(RedirectToAction(nameof(Index), new { id = viewModel.Id }));
            }
            return(View(viewModel));
        }
Example #2
0
        public void TestTaxToSupportReturnsNotFoundWithIdMismatch()
        {
            //Get a test controller
            GameContext        context        = GetTestContext("gameloop_tax_to_support_mismatch");
            GameLoopController testController = new GameLoopController(context);

            //Generate the form data
            TaxToSupportInput input = new TaxToSupportInput {
                Id = 4, Cities = 5
            };

            //Run the controller's ResolveTaxToSupport() with a mismatched Id
            IActionResult result = testController.ResolveTaxToSupport(1, input);

            //Assert that we got a not found result
            Assert.IsType <NotFoundResult>(result);
        }
Example #3
0
        public void TestTaxToSupportReturnsToFormOnInvalidModel()
        {
            //Get a test controller
            GameContext        context        = GetTestContext("gameloop_tax_to_support_invalid");
            GameLoopController testController = new GameLoopController(context);

            //Add an error to force the Post: Create() method to return to the form
            testController.ModelState.AddModelError("test error", "automated unit test error");

            //Generate the form data
            TaxToSupportInput input = new TaxToSupportInput {
                Id = 1, Cities = 5
            };

            //Run the controller's ResolveTaxToSupport() with an invalid model
            IActionResult result = testController.ResolveTaxToSupport(1, input);

            //Assert that...
            //...we got a view back
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
        }
Example #4
0
        public void CanResolveTaxToSupport()
        {
            //Get a test controller
            GameContext        context        = GetTestContext("gameloop_tax_to_support");
            GameLoopController testController = new GameLoopController(context);

            //Generate the form data
            TaxToSupportInput input = new TaxToSupportInput {
                Id = 1, Cities = 5
            };

            //Run the controller's Details() without an Id
            IActionResult result = testController.ResolveTaxToSupport(1, input);

            //Assert that...
            //...we got a redirect back
            RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result);

            //...the action is the index
            Assert.Equal(nameof(GameLoopController.Index), redirect.ActionName);
            //...the route data is the ID of the active civ
            Assert.Equal(input.Id, redirect.RouteValues["id"]);
        }