public async Task DeleteEntry_ReturnsViewError_WhenNoDelete() { // Arrange var mockUserManager = new FakeUserManager(); var mockMapper = new Mock <IMapper>(); var mockLoggerFactory = new Mock <ILoggerFactory>(); var mockLogger = new Mock <ILogger>(); mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object); var mockWorkoutService = new Mock <IWorkoutService>(); mockWorkoutService.Setup(w => w.DeleteWorkoutEntryAsync(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(false) .Verifiable(); var mockExerciseService = new Mock <IExerciseService>(); var mockChallengeService = new Mock <IChallengeService>(); var mockWorkoutRepository = new Mock <IWorkoutRepository>(); var workoutController = new WorkoutController( mockLoggerFactory.Object, mockMapper.Object, mockWorkoutService.Object, mockExerciseService.Object, mockUserManager, mockWorkoutRepository.Object, mockChallengeService.Object); // Act var result = await workoutController.DeleteEntry(It.IsAny <int>(), It.IsAny <int>()) as ViewResult; // Assert Assert.IsType <ViewResult>(result); Assert.Equal("/Error", result.ViewName); }
public async Task DeleteEntry_RedirectToEditWorkout_IfDeleted() { // Arrange var mockUserManager = new FakeUserManager(); var mockMapper = new Mock <IMapper>(); var mockLoggerFactory = new Mock <ILoggerFactory>(); var mockLogger = new Mock <ILogger>(); mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object); var mockWorkoutService = new Mock <IWorkoutService>(); mockWorkoutService.Setup(w => w.DeleteWorkoutEntryAsync(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(true) .Verifiable(); var mockExerciseService = new Mock <IExerciseService>(); var mockChallengeService = new Mock <IChallengeService>(); var mockWorkoutRepository = new Mock <IWorkoutRepository>(); var workoutController = new WorkoutController( mockLoggerFactory.Object, mockMapper.Object, mockWorkoutService.Object, mockExerciseService.Object, mockUserManager, mockWorkoutRepository.Object, mockChallengeService.Object); var expectedRedirectValues = new RouteValueDictionary() { { "controller", "Workout" }, { "action", "EditWorkout" }, { "id", 0 } }; // Act var result = await workoutController.DeleteEntry(It.IsAny <int>(), It.IsAny <int>()) as RedirectToActionResult; // Assert Assert.IsType <RedirectToActionResult>(result); Assert.Equal("EditWorkout", result.ActionName); Assert.Equal(expectedRedirectValues, result.RouteValues); }