Example #1
0
        public void AddScooterTwiceTest()
        {
            IScooterService service = new ScooterService();

            service.AddScooter("scooter1", 0.2m);
            Assert.ThrowsException <ScooterExistsException>(() => service.AddScooter("scooter1", 0.2m));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
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 #5
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 #6
0
        private ICalculations GetCalculations()
        {
            IScooterService scooterService = new ScooterService();

            _calculations = new Calculations(20, scooterService);

            return(_calculations);
        }
Example #7
0
        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"));
        }
Example #8
0
        private IRentalCompany GetRentalCompany(string name)
        {
            IScooterService scooterService = new ScooterService();
            ICalculations   calculations   = new Calculations(20, scooterService);

            _rentalCompany = new RentalCompany(name, scooterService, calculations);

            return(_rentalCompany);
        }
Example #9
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);
        }
Example #10
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 #11
0
        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"));
        }
Example #12
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 #13
0
        public void GetNoScootersTest()
        {
            IScooterService service = new ScooterService();

            Assert.ThrowsException <ScooterNotFoundException>(() => service.GetScooters());
        }
Example #14
0
        public void RemoveNotExistingScooterTest()
        {
            IScooterService service = new ScooterService();

            Assert.ThrowsException <CantRemoveException>(() => service.RemoveScooter("scooter1"));
        }
Example #15
0
        public void GetNotExistingScooterByIdTest()
        {
            IScooterService service = new ScooterService();

            Assert.ThrowsException <ScooterNotFoundException>(() => service.GetScooterById("scooter1"));
        }
Example #16
0
        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);
        }