コード例 #1
0
        public void AndExceptionThrown_ThenWrapsException()
        {
            _vehicleRepo
            .Setup(vr => vr.GetVehicle(It.IsAny <int>(), It.IsAny <int>()))
            .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            var ex = Assert.Throws <BusinessServicesException>(() => handler.Execute(UserId, DefaultVehicleId));

            Assert.IsType <InvalidOperationException>(ex.InnerException);
        }
コード例 #2
0
        public void AndVehicleDoesNotExist_ThenThrows()
        {
            // this is the same test as FromOtherUser_ThenThrows

            // the repo throws an exception when it can't find a match with both the user and the vehicle
            _vehicleRepo
            .Setup(vr => vr.GetVehicle(UserId, It.IsAny <int>()))
            .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            Assert.Throws <BusinessServicesException>(() => handler.Execute(UserId, DefaultVehicleId));
        }
コード例 #3
0
        public void FromOtherUser_ThenThrows()
        {
            const int someOtherUserId = 12;

            // the repo throws an exception when it can't find a match with both the user and the vehicle
            _vehicleRepo
            .Setup(vr => vr.GetVehicle(someOtherUserId, DefaultVehicleId))
            .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            Assert.Throws <BusinessServicesException>(() => handler.Execute(someOtherUserId, DefaultVehicleId));
        }
コード例 #4
0
        public void ThenDelegatesToVehicleRepository()
        {
            var vehicle = new Model.Vehicle {
                VehicleId = DefaultVehicleId, Name = "Name"
            };

            _vehicleRepo
            .Setup(vr => vr.GetVehicle(UserId, DefaultVehicleId))
            .Returns(vehicle);

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            handler.Execute(UserId, DefaultVehicleId);

            _vehicleRepo.Verify(r => r.Delete(DefaultVehicleId), Times.Once());
        }
コード例 #5
0
 public void DeleteVehicle(int vehicleId)
 {
     deleteVehicle.Execute(1, vehicleId);
 }