public void CreateGet_ShouldReturnConferenceCreateView() { // Arrange var conferencesIndexViewModel = A.Fake <IConferencesIndexViewModel>(); var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>(); var conferenceRepository = A.Fake <IConferenceRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel, conferenceRepository, sharedRepository); // Act var result = testController.Create(); // Assert result.ShouldBeOfType <ViewResult>(); }
public async Task CreatePost_WhenModelStateIsValid_ShouldAddConferenceToDataStoreAndRedirectToIndexView() { // Arrange var conferencesIndexViewModel = A.Fake <IConferencesIndexViewModel>(); var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>(); var conferenceRepository = A.Fake <IConferenceRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel, conferenceRepository, sharedRepository); var conference = new Conference(); // Act var result = await testController.Create(conference); // Assert A.CallTo(() => conferenceRepository.AddAsync(conference)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); result.ShouldBeOfType <RedirectToActionResult>(); ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index)); }
public async Task CreatePost_WhenModelStateIsNotValid_ShouldReturnConferenceCreateView() { // Arrange var conferencesIndexViewModel = A.Fake <IConferencesIndexViewModel>(); var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>(); var conferenceRepository = A.Fake <IConferenceRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel, conferenceRepository, sharedRepository); var conference = new Conference(); testController.ModelState.AddModelError("LongName", "Please enter a long name."); // Act var result = await testController.Create(conference); // Assert A.CallTo(() => conferenceRepository.AddAsync(conference)).MustNotHaveHappened(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened(); result.ShouldBeOfType <ViewResult>(); ((ViewResult)result).Model.ShouldBe(conference); }