public void SetUp() { _startDate = DateTime.UtcNow.Date; _endDate = DateTime.UtcNow.Date.AddDays(2); car = new Car { Price = new Price { DailyPrice = 100 } }; CarRepository.FindById(0).Returns(car); BookingRepository.GetBooking(car, _startDate, _endDate).Returns(new List <CarBooking>()); BookCarUseCase.Book(0, _startDate, _endDate); }
static int Main(int carId, DateTime startDate, DateTime endDate) { var connectionStringBuilder = new SqlConnectionStringBuilder { DataSource = "localhost", InitialCatalog = "Rental", IntegratedSecurity = true }; using var rentalDbContext = new RentalDbContext(connectionStringBuilder.ToString()); try { var useCase = new BookCarUseCase(new CarRepositoryAdapter(rentalDbContext), new BookingRepositoryAdapter(rentalDbContext)); useCase.Book(carId, startDate, endDate); } catch (CarDoesNotExistsException e) { Console.Error.WriteLine($"Car is not found: {carId}"); return(1); } return(0); }
public BookingController(ILogger <BookingController> logger, BookCarUseCase bookCarUseCase) { _logger = logger; _bookCarUseCase = bookCarUseCase; }
public void Given() { BookingRepository = Substitute.For <IBookingRepository>(); CarRepository = Substitute.For <ICarRepository>(); BookCarUseCase = new BookCarUseCase(CarRepository, BookingRepository); }
public void it_should_throw_exception() { Assert.Throws <CarIsAlreadyBookedException>(() => BookCarUseCase.Book(0, _startDate, _endDate)); }