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

            const int shoeId = -1;

            // Act
            var result = controller.Edit(shoeId);

            // Assert
            Assert.That(result,Is.InstanceOf<HttpNotFoundResult>());
        }
        public void Edit_WhenShowingView_ThenTheMatchingShoeIsShown()
        {
            // Arrange
            var dbContext = new FakeShoeTrackerDbContext()
                .WithShoe("some shoe", _currentUserId);
            var controller = new ShoeController(dbContext)
                .WithAuthenticatedUser("some user", _currentUserId);

            var shoeId = dbContext.Shoes.Select(s => s.ShoeId).First();

            // Act
            var result = controller.Edit(shoeId);

            // Assert
            var viewResult = (ViewResult) result;
            var shoe = viewResult.CastModel<Shoe>();

            Assert.That(shoe.ShoeId,Is.EqualTo(shoeId));
        }
        public void Edit_WhenSavingValidShoe_ThenShoeIsSaved()
        {
            // Arrange
            var dbContext = new FakeShoeTrackerDbContext();
            dbContext
                .WithShoe("foo", _currentUserId);
            var controller = new ShoeController(dbContext)
                .WithAuthenticatedUser("some user", _currentUserId)
                .WithValidModelState();

            var shoeId = dbContext.Shoes.Select(s => s.ShoeId).First();
            var shoeOnView = ((ViewResult)controller.Edit(shoeId)).CastModel<Shoe>();

            shoeOnView.Name = "some other name";

            // Act
            controller.Edit(shoeOnView);

            // Assert
            Assert.That(dbContext.NumerOfTimesSaveChangesCalled, Is.EqualTo(1));
        }