public void AddScooterTwiceTest() { IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); Assert.ThrowsException <ScooterExistsException>(() => service.AddScooter("scooter1", 0.2m)); }
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 RemoveRentedScooterTest() { IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); service.GetScooterById("scooter1").IsRented = true; Assert.ThrowsException <CantRemoveRentedScooterException>(() => service.RemoveScooter("scooter1")); }
public void GetScooterByIdTest() { IScooterService service = new ScooterService(); service.AddScooter("scooter1", 0.2m); var scooter = service.GetScooterById("scooter1"); Assert.AreEqual("scooter1", scooter.Id); Assert.AreEqual(0.2m, scooter.PricePerMinute); }
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 async System.Threading.Tasks.Task Test1Async() { var context = Context(); var clientService = new ClientService(context); var scooterService = new ScooterService(context); var test = " test"; var SerialNumber = 1; scooterService.AddScooter(new RequestAddScooterModel() { SerialNumber = SerialNumber, }); clientService.RentScooter(new RequestRentModel() { FirstName = test, LastName = test, }); clientService.ReturnScooter(new RequestRentModel() { FirstName = test, LastName = test, }); var getAllRentals = await context.Rentals.ToListAsync(); Assert.Single(getAllRentals); Assert.Equal(1, await scooterService.CountOfFreeScooterAsync()); clientService.ReportDefect(new RequestBrokenModel() { FirstName = test, LastName = test, AboutBroke = "Broke", }); var isBroken = await context.Scooters.Include(el => el.Defect).FirstOrDefaultAsync(); Assert.Equal(Defects.Broke, isBroken.Defect.DefectType); clientService.ReportDefect(new RequestBrokenModel() { FirstName = test, LastName = test, AboutBroke = "Broken", }); var isBroken2 = await context.Scooters.Include(el => el.Defect).FirstOrDefaultAsync(); Assert.Equal(Defects.Broke, isBroken2.Defect.DefectType); scooterService.FixScooter(new FixScooterModel() { SerialNumber = SerialNumber }); Assert.Equal(1, await scooterService.CountOfFreeScooterAsync()); var countOfBorrowLoyalClients = scooterService.CountOfBorrowOfLoyalClients(); Assert.Single(countOfBorrowLoyalClients); var TotalTimeOfRentForScooter = scooterService.TotalTimeOfRentForScooter(); Assert.Single(TotalTimeOfRentForScooter); }