public void AddExercise()
        {
            // Act
            var controller = new WorkoutController();

            // Arrange
            var result = controller.AddWorkout();
        }
Beispiel #2
0
        public async Task AddWorkout_ReturnsViewError_Database()
        {
            // 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.GetAllWorkoutsAsync(It.IsAny <int>()))
            .ReturnsAsync(new List <WorkoutDto> {
                new WorkoutDto {
                }
            })
            .Verifiable();     // Return list of workouts
            mockWorkoutService.Setup(w => w.AddWorkoutAsync(It.IsAny <NewWorkoutDto>()))
            .ReturnsAsync(0)   // Error in database
            .Verifiable();
            mockWorkoutService.Setup(w => w.GetWorkoutAsync(It.IsAny <int>()))
            .ReturnsAsync(new WorkoutDto {
                WorkoutEntryDtos = new List <WorkoutEntryDto>()
            })
            .Verifiable();
            var mockExerciseService = new Mock <IExerciseService>();

            mockExerciseService.Setup(e => e.GetAllExercisesAsync())
            .ReturnsAsync(new List <ExerciseDto>())
            .Verifiable();
            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.AddWorkout() as ViewResult;

            // Assert
            Assert.IsType <ViewResult>(result);
            Assert.Equal("/Error", result.ViewName);
        }
Beispiel #3
0
        public async Task AddWorkout_ReturnsEditRedirectViewResult_WithWorkoutModel()
        {
            // Arrange
            var mockUserManager  = new FakeUserManager();
            var mockMapper       = new Mock <IMapper>();
            var workoutEntries   = new List <WorkoutEntryViewModel>();
            var exercises        = new List <ExerciseDto>();
            var workoutViewModel = new WorkoutViewModel()
            {
                CreationDate = DateTime.MinValue, ExerciseId = 0, Name = "Workout",
                Exercises    = exercises, Id = 0, Reps = 10, Weight = 10, Set = 10, WorkoutEntries = workoutEntries
            };

            mockMapper.Setup(m => m.Map <WorkoutDto, WorkoutViewModel>(It.IsAny <WorkoutDto>()))
            .Returns(workoutViewModel)
            .Verifiable();
            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.GetAllWorkoutsAsync(It.IsAny <int>()))
            .ReturnsAsync(new List <WorkoutDto> {
                new WorkoutDto {
                }
            })
            .Verifiable();     // Return list of workouts
            mockWorkoutService.Setup(w => w.AddWorkoutAsync(It.IsAny <NewWorkoutDto>()))
            .ReturnsAsync(1)
            .Verifiable();
            mockWorkoutService.Setup(w => w.GetWorkoutAsync(It.IsAny <int>()))
            .ReturnsAsync(new WorkoutDto {
                WorkoutEntryDtos = new List <WorkoutEntryDto>()
            })
            .Verifiable();
            var mockExerciseService = new Mock <IExerciseService>();

            mockExerciseService.Setup(e => e.GetAllExercisesAsync())
            .ReturnsAsync(exercises);
            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()
            //{
            //    // TODO
            //    { "Id", 0 },
            //    { "Name", "Workout" },
            //    { "CreationDate", DateTime.MinValue },
            //    //{ "WorkoutEntries", workoutEntries },
            //    //{ "Exercises", exercises },
            //    { "ExerciseId", 0 },
            //    { "Set", 10 },
            //    { "Weight", 10 },
            //    { "Reps", 10 }
            //};

            // Act
            var result = await workoutController.AddWorkout() as RedirectToActionResult;

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("EditWorkout", result.ActionName);
            //Assert.Equal(expectedRedirectValues, result.RouteValues);
        }