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 GetScootersTest() { IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); service.AddScooter("scooter2", 0.2m); int scooterAmount = service.GetScooters().Count; Assert.AreEqual(2, scooterAmount); }
public void GetNoScootersTest() { IScooterService service = new ScooterService(); Assert.ThrowsException <ScooterNotFoundException>(() => service.GetScooters()); }