public void CanResolveMoveAstEnd() { //Get a test controller GameContext context = GetTestContext("gameloop_end"); GameLoopController testController = new GameLoopController(context); //Configure the active civ's status ActiveCiv activeCiv = context.ActiveCivs.Find(1); activeCiv.AstPosition = 16; activeCiv.Cities = 5; activeCiv.CurrentPhase = (int)ActiveCiv.Phases.MoveAST; context.SaveChanges(); //Run the controller's Details() without an Id IActionResult result = testController.Index(1); //Assert that... //...we got a redirect back RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result); //...the controller is "ActiveCivController" Assert.Equal("ActiveCivs", redirect.ControllerName); //...the action is the index Assert.Equal(nameof(ActiveCivsController.Details), redirect.ActionName); //...the route data is the ID of the new active civ Assert.Equal(activeCiv.Id, redirect.RouteValues["id"]); }
public void CanResolveMoveAstForward(string dbString, int astPosition, int cities, string expectedMessage) { //Get a test controller GameContext context = GetTestContext(dbString); GameLoopController testController = new GameLoopController(context); //Configure the active civ's status ActiveCiv activeCiv = context.ActiveCivs.Find(1); activeCiv.AstPosition = astPosition; activeCiv.Cities = cities; activeCiv.CurrentPhase = (int)ActiveCiv.Phases.MoveAST; context.SaveChanges(); //Run the resolution (via the index, since MoveAST is private IActionResult result = testController.Index(1); //Assert that... //...we got a view back ViewResult viewResult = Assert.IsType <ViewResult>(result); //...the view model is an ActiveCiv Assert.IsAssignableFrom <ActiveCiv>(viewResult.ViewData.Model); //...the view bag has the message we expect Assert.Equal(expectedMessage, viewResult.ViewData["MovementMessage"]); }
public void TestIndexWithOutOfRangeIdReturnsNotFound() { //Get a test controller GameContext context = GetTestContext("gameloop_details_oob_id"); GameLoopController testController = new GameLoopController(context); //Run the controller's Details() with an Id that isn't present in the database IActionResult result = testController.Index(context.ActiveCivs.Count() + 20); Assert.IsType <NotFoundResult>(result); }
public void TestIndexWithoutIdReturnsNotFound() { //Get a test controller GameContext context = GetTestContext("gameloop_details_no_id"); GameLoopController testController = new GameLoopController(context); //Run the controller's Details() without an Id IActionResult result = testController.Index(null); Assert.IsType <NotFoundResult>(result); }
public void CanDisplayIndexAtTaxToSupport() { //Get a test controller GameContext gameContext = GetTestContext("gameloop_display_taxtosupport"); GameLoopController testController = new GameLoopController(gameContext); //Run the controller's Index() IActionResult result = testController.Index(1); //Assert that... //...we got a view back ViewResult viewResult = Assert.IsType <ViewResult>(result); //...the view data is a set of advancements Assert.IsAssignableFrom <TaxToSupportInput>(viewResult.ViewData.Model); }