예제 #1
0
 public void TestCreateNewWorkout()
 {
     workout workout = new workout();
     workout.id = 100;
     workout.name = "TestWorkoutName";
     workout.description = "TestWorkoutDescription";
     workout.category_id = 1;
     workout.created_by_user_id = 1;
     workout_exercise workoutExercise = new workout_exercise();
     workoutExercise.id = 4;
     workoutExercise.exercise_id = 1;
     workoutExercise.workout_id = 100;
     workoutExercise.position = 1;
     workoutExercise.duration = 5;
     workout.workout_exercise.Add(workoutExercise);
     db.Setup(c => c.workouts.Add(workout)).Returns(workout);
     RedirectToRouteResult result = controller.New(workout) as RedirectToRouteResult;
     Assert.IsNotNull(result);
     Assert.AreEqual(100, result.RouteValues["workoutId"], "workoutId was not 100");
     Assert.AreEqual("Details", result.RouteValues["action"], "action was not Details");
     Assert.AreEqual("Home", result.RouteValues["controller"], "controller was not Home");
 }
 public void TestHomeControllerCreateNewWorkoutWithValidationErrs()
 {
     var workout = new workout();
     var workoutExercise = new workout_exercise();
     workout.workout_exercise.Add(workoutExercise);
     adminCon.ModelState.AddModelError("Fail", "Failed");
     ViewResult result = adminCon.New(workout) as ViewResult;
     Assert.IsNotNull(result);
     Assert.AreEqual("DetailedError", result.ViewName);
     Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult));
     var model = result.Model as HttpStatusCodeResult;
     Assert.AreEqual(400, model.StatusCode);
     Assert.AreEqual("Could not create the workout with the given values.", model.StatusDescription);
 }
 public void TestHomeControllerCreateNewWorkoutWithNoUserError()
 {
     adminCon = new AdminWorkoutsController(db.Object)
     {
         ControllerContext = MockContext.AuthenticationContext("not_a_real_user")
     };
     var workout = new workout();
     var workoutExercise = new workout_exercise();
     workout.workout_exercise.Add(workoutExercise);
     ViewResult result = adminCon.New(workout) as ViewResult;
     Assert.IsNotNull(result);
     Assert.AreEqual("DetailedError", result.ViewName);
     Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult));
     var model = result.Model as HttpStatusCodeResult;
     Assert.AreEqual(500, model.StatusCode);
     Assert.AreEqual("No user could be associated with the workout being created", model.StatusDescription);
 }
예제 #4
0
 public void TestHomeControllerCreateNewWorkoutWithBadPassedObj()
 {
     var workout = new workout();
     var workoutExercise = new workout_exercise();
     workout.workout_exercise.Add(workoutExercise);
     var ex = new Exception();
     db.Setup(c => c.workouts.Add(workout)).Throws(ex);
     ViewResult result = controller.New(workout) as ViewResult;
     Assert.IsNotNull(result);
     Assert.AreEqual("DetailedError", result.ViewName);
     Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult));
     var model = result.Model as HttpStatusCodeResult;
     Assert.AreEqual(500, model.StatusCode);
     Assert.AreEqual("Failed to create the requested workout.", model.StatusDescription);
 }