public void Create_WhenSavingInValidWorkout_ThenWorkoutIsNotSaved()
        {
            // Arrange
            var dbContext = new FakeShoeTrackerDbContext();
            var controller = new WorkoutController(dbContext)
                .WithAuthenticatedUser("some user", _currentUserId)
                .WithInvalidModelState();

            var workoutOnView = controller.Create().CastModel<EditWorkoutViewModel>();

            // Act
            controller.Create(workoutOnView);

            // Assert
            Assert.That(dbContext.Workouts.Count(), Is.EqualTo(0));
        }
        public void Create_WhenSavingValidWorkout_ThenWorkoutIsSaved()
        {
            // Arrange
            var dbContext = new FakeShoeTrackerDbContext()
                .WithShoe("Some show", _currentUserId);
            var controller = new WorkoutController(dbContext)
                .WithAuthenticatedUser("some user", _currentUserId)
                .WithValidModelState();

            var workoutOnView = controller.Create().CastModel<EditWorkoutViewModel>();
            workoutOnView.Distance = 1.2m;
            workoutOnView.Name = "my name";
            workoutOnView.WorkoutDate = DateTime.Today.AddDays(-4);
            workoutOnView.ShoeUsedId = long.Parse(workoutOnView.AvailableShoes.First().Value);

            // Act
            controller.Create(workoutOnView);

            // Assert
            Assert.That(dbContext.Workouts.Count(), Is.EqualTo(1));
            Assert.That(dbContext.Workouts.First().UserId, Is.EqualTo(_currentUserId));
            Assert.That(dbContext.Workouts.First().Distance, Is.EqualTo(workoutOnView.Distance));
            Assert.That(dbContext.Workouts.First().Name, Is.EqualTo(workoutOnView.Name));
            Assert.That(dbContext.Workouts.First().ShoeUsed.ShoeId, Is.EqualTo(workoutOnView.ShoeUsedId));
            Assert.That(dbContext.Workouts.First().WorkoutDate, Is.EqualTo(workoutOnView.WorkoutDate));
        }
        public void Create_WhenShowingView_ThenNewWorkoutHasDefaults()
        {
            // Arrange
            var dbContext = new FakeShoeTrackerDbContext()
                .WithShoe("Foo", _currentUserId)
                .WithShoe("Bar", _currentUserId)
                .WithShoe("Other", "some other user");
            var controller = new WorkoutController(dbContext)
                .WithAuthenticatedUser("some user", _currentUserId);

            // Act
            var result = controller.Create();

            // Assert
            var modelData = result.CastModel<EditWorkoutViewModel>();

            Assert.That(modelData.WorkoutDate, Is.EqualTo(DateTime.Today));
            Assert.That(modelData.AvailableShoes.Count(), Is.EqualTo(2));
        }