public void TestCreateGet() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); ViewResult result = controller.Create() as ViewResult; Assert.AreEqual(result.ViewName, ""); }
public void TestDeleteGetInvalidBaseballCard() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); int baseballCardId = -1; HttpNotFoundResult result = controller.Delete(baseballCardId) as HttpNotFoundResult; Assert.IsNotNull(result); }
public void TestDeleteGetValidBaseballCard() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); int baseballCardId = 1; ViewResult result = controller.Delete(baseballCardId) as ViewResult; BaseballCard card = (BaseballCard)result.ViewData.Model; // Test the view model contains a list of fish Assert.IsNotNull(card, "The card does not exist"); Assert.IsTrue(card.Player == mockCards[1].Player); }
public void TestUploadPostInvalid() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); ViewResult result = controller.Upload(null) as ViewResult; Assert.AreEqual(result.ViewName, "Upload"); Assert.IsNotNull(result.TempData["error"]); }
public void TestIndexHasListOfBaseballCards() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); ViewResult result = controller.Index() as ViewResult; List<BaseballCard> cards = (List<BaseballCard>)result.ViewData.Model; // Test the view model contains a list of fish Assert.IsNotNull(cards, "The list of cards does not exist"); Assert.IsTrue(cards.Count == mockCards.Count); }
public void TestEditPostValidBaseballCard() { BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); BaseballCard baseballCard = new BaseballCard() { BaseballCardId = 1, Player = "Heman has teh Powerz", Team = "shera" }; RedirectToRouteResult result = controller.Edit(baseballCard) as RedirectToRouteResult; Assert.IsNotNull(result); BaseballCard bballCard = mockCardRepository.Object.GetAllCards()[1]; Assert.AreEqual(bballCard.Player, baseballCard.Player); }
public void TestEditPostInvalidModelState() { string message = "There has been an error, please try again or contact System Administrator."; BaseballCardController controller = new BaseballCardController(mockCardRepository.Object); controller.ModelState.AddModelError("error", message); BaseballCard baseballCard = null; ViewResult result = controller.Edit(baseballCard) as ViewResult; Assert.IsNotNull(result); Assert.IsFalse(result.ViewData.ModelState.IsValid); Assert.IsTrue(result.ViewData.ModelState["error"].Errors.Count > 1); }