public void CalculateThisYearAllIncomeTest() { var name = "my company"; IScooterService service = new ScooterService(); var date = DateTime.UtcNow; var rentals = new List <RentedScooter> { new RentedScooter { RentalStart = date, RentalEnd = date.AddMinutes(5), ScooterId = "scooter1", PricePerMinute = 0.2m }, new RentedScooter { RentalStart = date, RentalEnd = date.AddDays(5), ScooterId = "scooter2", PricePerMinute = 0.5m }, new RentedScooter { RentalStart = date.AddDays(-2), RentalEnd = null, ScooterId = "scooter3", PricePerMinute = 1.0m } }; IRentalCompany company = new RentalCompany(name, service, new RentalPriceCalculator(renatlCalculatorMaxPrice), rentals); Assert.AreEqual(181.0m, company.CalculateIncome(2020, true)); }
public void CalculateTotalFinishedRentIncomeTest() { var name = "my company"; IScooterService service = new ScooterService(); var date = new DateTime(2019, 12, 30); var rentals = new List <RentedScooter> { new RentedScooter { RentalStart = date, RentalEnd = date.AddMinutes(5), ScooterId = "scooter1", PricePerMinute = 0.2m }, new RentedScooter { RentalStart = date, RentalEnd = date.AddDays(5), ScooterId = "scooter2", PricePerMinute = 0.5m }, new RentedScooter { RentalStart = DateTime.UtcNow.AddDays(-1), RentalEnd = null, ScooterId = "scooter3", PricePerMinute = 1.0m } }; IRentalCompany company = new RentalCompany(name, service, new RentalPriceCalculator(renatlCalculatorMaxPrice), rentals); Assert.AreEqual(101.0m, company.CalculateIncome(null, false)); }
static void Main(string[] args) { // Create all services for dependency injection. var services = new ServiceCollection() .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Warning)) .AddSingleton <ScooterService>() .AddRentalCompany("IfRentalCompany"); string id = "MuScooterId001"; using (ServiceProvider provider = services.BuildServiceProvider()) { try { // Create rental company with dependency injection services. RentalCompany rentalCompany = provider.GetService <RentalCompany>(); string name = rentalCompany.Name; ScooterService scooterService = provider.GetService <ScooterService>(); scooterService.AddScooter(id, 100.10m); scooterService.AddScooter("hi999", 10.10m); scooterService.SetRentalStatus(id, true); var allScooters = scooterService.GetScooters(); var scooter = scooterService.GetScooterById(id); } catch (Exception ex) { Console.WriteLine($"Exception in service: {ex.Message}"); } Console.ReadLine(); } }
public void StartNotExistingScooterRentalTest() { var name = "my company"; IScooterService service = new ScooterService(); IRentalCompany company = new RentalCompany(name, service, new RentalPriceCalculator(renatlCalculatorMaxPrice), new List <RentedScooter>()); Assert.ThrowsException <ScooterNotFoundException>(() => company.StartRent("scooter1")); }
public void EndNotStartedRentalTest() { var name = "my company"; IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); IRentalCompany company = new RentalCompany(name, service, new RentalPriceCalculator(renatlCalculatorMaxPrice), new List <RentedScooter>()); Assert.ThrowsException <ScooterIsNotRentedException>(() => company.EndRent("scooter1")); }
public void StartRentalTest() { var name = "my company"; IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); IRentalCompany company = new RentalCompany(name, service, new RentalPriceCalculator(renatlCalculatorMaxPrice), new List <RentedScooter>()); company.StartRent("scooter1"); var scooter = service.GetScooterById("scooter1"); Assert.IsTrue(scooter.IsRented); }
public static void Main() { var rentalCompany = new RentalCompany<Car>(); var car1 = rentalCompany.RentCar(); car1.CustomerID = 58; Console.WriteLine( "Car 1 rented on {0:MM/dd/yyyy hh:mm:ss.fff tt} by customer with ID: {1}", car1.RentedAt, car1.CustomerID); Thread.Sleep(2000); var car2 = rentalCompany.RentCar(); car2.CustomerID = 40; Console.WriteLine( "Car 2 rented on {0:MM/dd/yyyy hh:mm:ss.fff tt} by customer with ID: {1}", car2.RentedAt, car2.CustomerID); Thread.Sleep(2000); var car3 = rentalCompany.RentCar(); car3.CustomerID = 43; Console.WriteLine( "Car 3 rented on {0:MM/dd/yyyy hh:mm:ss.fff tt} by customer with ID: {1}", car3.RentedAt, car3.CustomerID); Thread.Sleep(2000); try { var car4 = rentalCompany.RentCar(); car4.CustomerID = 66; Console.WriteLine( "Car 4 rented on {0:MM/dd/yyyy hh:mm:ss.fff tt} by customer with ID: {1}", car4.RentedAt, car4.CustomerID); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } Thread.Sleep(2000); rentalCompany.FreeCar(car1); var car5 = rentalCompany.RentCar(); car5.CustomerID = 81; Console.WriteLine( "Car 5 rented on {0:MM/dd/yyyy hh:mm:ss.fff tt} by customer with ID: {1}", car5.RentedAt, car5.CustomerID); }
public RentalCompanyTests() { _rentalCompany = new RentalCompany(_mockLogger.Object, _mockScooterService.Object, _name); }
public RentalCompanyTests() { _rentalCompany = new RentalCompany("test", _rentalServiceMock.Object, _scooterServiceMock.Object, _rentalCalculatorMock.Object); }