Esempio n. 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();
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void GetNoScootersTest()
        {
            IScooterService service = new ScooterService();

            Assert.ThrowsException <ScooterNotFoundException>(() => service.GetScooters());
        }