public async Task EventCreatePostSuccessTest() { _mapper.Setup(x => x.Map <EventCreateViewModel, EventCreateDTO>(It.IsAny <EventCreateViewModel>())).Returns(new EventCreateDTO()); _eventUserManager.Setup(x => x.CreateEventAsync(new EventCreateDTO())); // Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventCreate(GetEventCreateViewModel()); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(actionResult); Assert.Equal("EventUser", viewResult.ActionName); Assert.NotNull(viewResult); }
public async Task EventEditPostFailureTest() { //Arrange _mapper.Setup(x => x.Map <EventCreateViewModel, EventCreateDTO>(It.IsAny <EventCreateViewModel>())).Returns(new EventCreateDTO()); _eventUserManager.Setup(x => x.EditEventAsync(new EventCreateDTO())); // Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventEdit(GetEventCreateViewModel()); eventUserController.ModelState.AddModelError("NameError", "Required"); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(actionResult); Assert.Equal("EventUser", viewResult.ActionName); Assert.NotNull(viewResult); }
public async Task EventCreateGetSuccessTest() { //Arrange _eventUserManager.Setup(x => x.InitializeEventCreateDTOAsync()).ReturnsAsync(new EventCreateDTO()); _mapper.Setup(m => m.Map <EventCreateDTO, EventCreateViewModel>(It.IsAny <EventCreateDTO>())) .Returns(GetEventCreateViewModel()); //Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventCreate(); //Arrange var viewResult = Assert.IsType <ViewResult>(actionResult); var viewModel = Assert.IsType <EventCreateViewModel>(viewResult.Model); Assert.NotNull(actionResult); }
public async Task EventUserSuccssesTest() { //Arrange _eventUserManager.Setup(am => am.EventUserAsync(It.IsAny <string>(), It.IsAny <ClaimsPrincipal>())) .ReturnsAsync(new EventUserDTO()); _mapper.Setup(m => m.Map <EventUserDTO, EventUserViewModel>(It.IsAny <EventUserDTO>())).Returns(GetEventUserViewModel()); string userId = "3"; //Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventUser(userId); //Arrange var viewResult = Assert.IsType <ViewResult>(actionResult); var viewModel = Assert.IsType <EventUserViewModel>(viewResult.Model); Assert.NotNull(actionResult); }
public async Task EventCreateGetFailureTest() { //Arrange _eventUserManager.Setup(x => x.InitializeEventCreateDTOAsync()) .ThrowsAsync(new Exception()); _mapper.Setup(m => m.Map <EventCreateDTO, EventCreateViewModel>(It.IsAny <EventCreateDTO>())) .Returns(new EventCreateViewModel()); //Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventCreate(); //Arrange Assert.NotNull(actionResult); var viewResult = Assert.IsType <RedirectToActionResult>(actionResult); Assert.Equal("HandleError", viewResult.ActionName); Assert.Equal("Error", viewResult.ControllerName); }
public async Task EventUserFailureTest() { //Arrange _eventUserManager.Setup(x => x.EventUserAsync(It.IsAny <string>(), It.IsAny <ClaimsPrincipal>())) .ThrowsAsync(new Exception()); _mapper.Setup(m => m.Map <EventUserDTO, EventUserViewModel>(It.IsAny <EventUserDTO>())) .Returns(new EventUserViewModel()); //Act var eventUserController = new EventUserController(_eventUserManager.Object, _mapper.Object); var actionResult = await eventUserController.EventUser(""); //Arrange Assert.NotNull(actionResult); var viewResult = Assert.IsType <RedirectToActionResult>(actionResult); Assert.Equal("HandleError", viewResult.ActionName); Assert.Equal("Error", viewResult.ControllerName); }
public void EventCreateMethodGetNotReturnError() { //arrange _repository.Setup(c => c.User.FindByCondition(It.IsAny <Expression <Func <User, bool> > >())). Returns(GetBadUserFields()); _repository.Setup(c => c.EventCategory.FindByCondition(It.IsAny <Expression <Func <EventCategory, bool> > >())). Returns(GetBadEventsCategoriesForTests()); _repository.Setup(c => c.EventType.FindByCondition(It.IsAny <Expression <Func <EventType, bool> > >())). Returns(GetBadEventsTypeForTests()); //action var controller = new EventUserController(_repository.Object, _usermanager.Object, _iCreateEventVM.Object); var result = controller.EventCreate(); //assert var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(null, viewResult.ViewName); Assert.NotNull(viewResult); }
public void EventUserPageReprezentation() { //arrange _repository.Setup(c => c.Event.FindByCondition(It.IsAny <Expression <Func <Event, bool> > >())). Returns(GetEventsEorTest()); _repository.Setup(c => c.User.FindByCondition(It.IsAny <Expression <Func <User, bool> > >())). Returns(GetUsersForTests()); _repository.Setup(c => c.EventAdmin.FindByCondition(It.IsAny <Expression <Func <EventAdmin, bool> > >())). Returns(GetEventAdminsForTests()); _repository.Setup(c => c.Participant.FindByCondition(It.IsAny <Expression <Func <Participant, bool> > >())). Returns(GetParticipantsForTests()); //action var controller = new EventUserController(_repository.Object, _usermanager.Object, _iCreateEventVM.Object); var result = controller.EventUser(); //assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <EventUserViewModel>(viewResult.Model); }
public void EventUserPageIsNullReturnError() { //arrange _repository.Setup(c => c.Event.FindByCondition(It.IsAny <Expression <Func <Event, bool> > >())). Returns(GetBadEventFields()); _repository.Setup(c => c.User.FindByCondition(It.IsAny <Expression <Func <User, bool> > >())). Returns(GetBadUserFields()); _repository.Setup(c => c.EventAdmin.FindByCondition(It.IsAny <Expression <Func <EventAdmin, bool> > >())). Returns(GetBadEventAdminFields()); _repository.Setup(c => c.Participant.FindByCondition(It.IsAny <Expression <Func <Participant, bool> > >())). Returns(GetBadParticipantFields()); //action var controller = new EventUserController(_repository.Object, _usermanager.Object, _iCreateEventVM.Object); var result = controller.EventUser(); //assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("HandleError", redirectToActionResult.ActionName); Assert.NotNull(redirectToActionResult); }