Exemplo n.º 1
0
        public void RentalRegistrationTest_WithInvalidDashboardMileage_ThrowsException()
        {
            var dependencies = new DependencyBuilder()
                               .Begin()
                               .WithProductionDependencies()
                               .Build();

            var sut           = dependencies.Resolve <CarRentalApplication>();
            var rentalRequest = new RentalRequestBuilder()
                                .Begin()
                                .WithInvalidDashboardMileage()
                                .Build();

            var bookingException = Assert.Throws <DashboardMileageCannotBeNegative>(() => sut.RentVehicle(rentalRequest));

            Assert.Equal(typeof(DashboardMileageCannotBeNegative), bookingException.GetType());
        }
Exemplo n.º 2
0
        public void RentalRegistrationTest_WithUnderAgeDriver_ThrowsException()
        {
            var dependencies = new DependencyBuilder()
                               .Begin()
                               .WithProductionDependencies()
                               .Build();

            var sut           = dependencies.Resolve <CarRentalApplication>();
            var rentalRequest = new RentalRequestBuilder()
                                .Begin()
                                .WithUnderAgeCustomer()
                                .Build();

            var bookingException = Assert.Throws <CustomerToYoungException>(() => sut.RentVehicle(rentalRequest));

            Assert.Equal(typeof(CustomerToYoungException), bookingException.GetType());
        }
Exemplo n.º 3
0
        public void RentalRegistrationTest_WithRentalStartTimePassed_ThrowsException()
        {
            var dependencies = new DependencyBuilder()
                               .Begin()
                               .WithProductionDependencies()
                               .Build();

            var sut           = dependencies.Resolve <CarRentalApplication>();
            var rentalRequest = new RentalRequestBuilder()
                                .Begin()
                                .WithRentalStartTimePassed()
                                .Build();

            var bookingException = Assert.Throws <RentalStartTimeHasPassedException>(() => sut.RentVehicle(rentalRequest));

            Assert.Equal(typeof(RentalStartTimeHasPassedException), bookingException.GetType());
        }
Exemplo n.º 4
0
        public void RentalRegistrationTest(VehicleCategoryEnum vehicleCategoryEnum)
        {
            var dependencies = new DependencyBuilder()
                               .Begin()
                               .WithProductionDependencies()
                               .Build();

            var sut           = dependencies.Resolve <CarRentalApplication>();
            var rentalRequest = new RentalRequestBuilder()
                                .Begin()
                                .With(vehicleCategoryEnum)
                                .Build();

            var bookingReference = sut.RentVehicle(rentalRequest);

            Assert.True(bookingReference.IsConfirmed);
            Assert.Equal(rentalRequest.CustomerBirthday, bookingReference.Customer.Birthday);
            Assert.Equal(rentalRequest.DashboardMileage, bookingReference.Vehicle.DashboardMileage);
            Assert.Equal(rentalRequest.StartOfRental, bookingReference.Booking.StartDate);
            Assert.Equal(rentalRequest.VehicleCategory.ToString(), bookingReference.Vehicle.GetType().Name);
        }
Exemplo n.º 5
0
        public void CarReturnedTests(Type vehicleType, int startDashboardMileage, int endDashboardMileage, int numberOfRentDays, decimal expectedAmount)
        {
            var previouslyBookedVehicle = new RentalRegistration(
                new Customer(DateTime.Parse("1980-01-01")),
                (Vehicle)Activator.CreateInstance(vehicleType, startDashboardMileage),
                new Booking(Guid.NewGuid(), DateTime.UtcNow.AddDays(2)));

            var dependencies = new DependencyBuilder()
                               .Begin()
                               .WithProductionDependencies()
                               .WithMock <IRentalStorage>(new RentalRepoMock(previouslyBookedVehicle))
                               .Build();

            var sut = dependencies.Resolve <CarRentalApplication>();

            var result = sut.ReturnVehicle(previouslyBookedVehicle.Booking.Id.Value,
                                           previouslyBookedVehicle.Booking.StartDate.AddDays(numberOfRentDays),
                                           endDashboardMileage);

            Assert.Equal(expectedAmount, result.AmountToPay);
            Assert.Equal(previouslyBookedVehicle.Booking.StartDate, result.RentalPeriod.Start);
            Assert.Equal(numberOfRentDays, result.RentalPeriod.NumberOfDays);
            Assert.Equal(endDashboardMileage - startDashboardMileage, result.DrivenKilometers);
        }