public void CreateGet_ShouldReturnSeasonCreateView() { // Arrange var seasonsIndexViewModel = A.Fake <ISeasonsIndexViewModel>(); var seasonsDetailsViewModel = A.Fake <ISeasonsDetailsViewModel>(); var seasonRepository = A.Fake <ISeasonRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new SeasonsController(seasonsIndexViewModel, seasonsDetailsViewModel, seasonRepository, sharedRepository); // Act var result = testController.Create(); // Assert result.ShouldBeOfType <ViewResult>(); }
public async Task CreatePost_WhenModelStateIsValid_ShouldAddSeasonToDataStoreAndRedirectToIndexView() { // Arrange var seasonsIndexViewModel = A.Fake <ISeasonsIndexViewModel>(); var seasonsDetailsViewModel = A.Fake <ISeasonsDetailsViewModel>(); var seasonRepository = A.Fake <ISeasonRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new SeasonsController(seasonsIndexViewModel, seasonsDetailsViewModel, seasonRepository, sharedRepository); var season = new Season(); // Act var result = await testController.Create(season); // Assert A.CallTo(() => seasonRepository.AddAsync(season)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); result.ShouldBeOfType <RedirectToActionResult>(); ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index)); }
public async Task CreatePost_WhenModelStateIsNotValid_ShouldReturnSeasonCreateView() { // Arrange var seasonsIndexViewModel = A.Fake <ISeasonsIndexViewModel>(); var seasonsDetailsViewModel = A.Fake <ISeasonsDetailsViewModel>(); var seasonRepository = A.Fake <ISeasonRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new SeasonsController(seasonsIndexViewModel, seasonsDetailsViewModel, seasonRepository, sharedRepository); var season = new Season(); testController.ModelState.AddModelError("Year", "Please enter a year."); // Act var result = await testController.Create(season); // Assert A.CallTo(() => seasonRepository.AddAsync(season)).MustNotHaveHappened(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened(); result.ShouldBeOfType <ViewResult>(); ((ViewResult)result).Model.ShouldBe(season); }