public void ThenUpdatesSortOrderForEachVehicle()
        {
            var vehicleOne = new Vehicle {
                VehicleId = 1, Name = "oldName", SortOrder = 0
            };
            var vehicleTwo = new Vehicle {
                VehicleId = 2, Name = "oldName", SortOrder = 1
            };
            var vehicleThree = new Vehicle {
                VehicleId = 3, Name = "oldName", SortOrder = 2
            };

            _vehicleRepo.Setup(vr => vr.GetVehicle(It.IsAny <int>(), 1)).Returns(vehicleOne);
            _vehicleRepo.Setup(vr => vr.GetVehicle(It.IsAny <int>(), 2)).Returns(vehicleTwo);
            _vehicleRepo.Setup(vr => vr.GetVehicle(It.IsAny <int>(), 3)).Returns(vehicleThree);

            var newOrder = new[] { 3, 2, 1 };
            var handler  = new UpdateVehicleSortOrder(_vehicleRepo.Object);

            handler.Execute(UserId, newOrder);

            Assert.Equal(2, vehicleOne.SortOrder);
            Assert.Equal(1, vehicleTwo.SortOrder);
            Assert.Equal(0, vehicleThree.SortOrder);
        }
        public void ThenDelegatesToVehicleRepositoryForEachVehicle()
        {
            var vehicleOne = new Vehicle {
                VehicleId = 1, Name = "oldName", SortOrder = 0
            };
            var vehicleTwo = new Vehicle {
                VehicleId = 2, Name = "oldName", SortOrder = 1
            };
            var vehicleThree = new Vehicle {
                VehicleId = 3, Name = "oldName", SortOrder = 2
            };

            _vehicleRepo.Setup(r => r.GetVehicle(It.IsAny <int>(), 1)).Returns(vehicleOne);
            _vehicleRepo.Setup(r => r.GetVehicle(It.IsAny <int>(), 2)).Returns(vehicleTwo);
            _vehicleRepo.Setup(r => r.GetVehicle(It.IsAny <int>(), 3)).Returns(vehicleThree);

            var newOrder = new[] { 3, 2, 1 };

            var handler = new UpdateVehicleSortOrder(_vehicleRepo.Object);

            handler.Execute(UserId, newOrder);

            _vehicleRepo.Verify(r => r.Update(vehicleOne), Times.Once());
            _vehicleRepo.Verify(r => r.Update(vehicleTwo), Times.Once());
            _vehicleRepo.Verify(r => r.Update(vehicleThree), Times.Once());
        }
        public void AndRepositoryFails_ThenThrowsBusinessServicesException()
        {
            _vehicleRepo
            .Setup(r => r.GetVehicle(UserId, It.IsAny <int>()))
            .Returns(new Vehicle());

            _vehicleRepo
            .Setup(b => b.Update(It.IsAny <Vehicle>()))
            .Throws(new InvalidOperationException());

            var newOrder = new[] { 3, 2, 1 };

            var handler = new UpdateVehicleSortOrder(_vehicleRepo.Object);

            var exception = Assert.Throws <BusinessServicesException>(() => handler.Execute(UserId, newOrder));

            Assert.IsType <InvalidOperationException>(exception.InnerException);
        }