Esempio n. 1
0
        public async Task DeleteWorkout_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.DeleteWorkoutAsync(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.DeleteWorkout(It.IsAny <int>()) as ViewResult;

            // Assert
            Assert.IsType <ViewResult>(result);
            Assert.Equal("/Error", result.ViewName);
        }
Esempio n. 2
0
        public async Task DeleteWorkout_RedirectToWorkouts_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.DeleteWorkoutAsync(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);

            // Act
            var result = await workoutController.DeleteWorkout(It.IsAny <int>()) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Workouts", result.ActionName);
        }
        public void DeleteWorkout()
        {
            // Act
            var controller = new WorkoutController();
            List <ExerciseType> lstExercises = new List <ExerciseType>();
            WorkoutRoutine      workout      = WorkoutRoutine.of(10, lstExercises, 100);

            // Arrange
            var result = controller.DeleteWorkout(workout, 5, 5);

            // Assert
            Assert.IsNotNull(result);
        }