Example #1
0
        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();
            }
        }
Example #2
0
        public void RemoveRentedScooterTest()
        {
            IScooterService service = new ScooterService();

            service.AddScooter("scooter1", 0.2m);
            service.GetScooterById("scooter1").IsRented = true;
            Assert.ThrowsException <CantRemoveRentedScooterException>(() => service.RemoveScooter("scooter1"));
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        public void GetNotExistingScooterByIdTest()
        {
            IScooterService service = new ScooterService();

            Assert.ThrowsException <ScooterNotFoundException>(() => service.GetScooterById("scooter1"));
        }