Esempio n. 1
0
        private static void TicketServiceTest()
        {
            customerService = Container.Resolve <ICustomerService>();
            ticketService   = Container.Resolve <ITicketService>();
            stationService  = Container.Resolve <IStationService>();
            routeService    = Container.Resolve <IRouteService>();
            vehicleService  = Container.Resolve <IVehicleService>();

            Console.WriteLine("Testing ticket and route service");
            routeService.CreateRoute(new RouteDTO
            {
                Name = "Tylova-Ceska"
            }, companyId);

            stationService.CreateStation(new StationDTO
            {
                Name = "Ceska",
                Town = "Brno"
            });
            stationService.CreateStation(new StationDTO
            {
                Name = "Tylova",
                Town = "Brno"
            });

            var stations = stationService.GetAllStationsByTown("Brno");
            var routeId  = routeService.ListAllRoutes().FirstOrDefault().ID;

            foreach (var station in stations)
            {
                if (station.Name.Equals("Ceska"))
                {
                    routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO
                    {
                        DepartFromFirstStation      = null,
                        DistanceFromPreviousStation = 0,
                        TimeFromFirstStation        = new TimeSpan(0, 0, 0),
                        TimeToNextStation           = new TimeSpan(0, 5, 0),
                    });
                }
                else
                {
                    routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO
                    {
                        DepartFromFirstStation      = null,
                        DistanceFromPreviousStation = 2,
                        TimeFromFirstStation        = new TimeSpan(0, 5, 0),
                        TimeToNextStation           = new TimeSpan(0, 0, 0),
                    });
                }
            }

            vehicleService.CreateVehicle(new VehicleDTO
            {
                LicencePlate = "a",
                VehicleType  = VehicleType.Bus,
                SeatCount    = 2
            }, companyId);

            routeService.CreateSpecificRoute(routeId, DateTime.Now, vehicleService.GetVehicleIdByLicencePlate("a"));

            var listRouteStations = routeService.GetRouteStationsByRoute(routeId);

            int[] listRouteStationsForTicket = new int[2];
            int   i = 0;

            foreach (var routeStation in listRouteStations)
            {
                if (routeStation.DepartFromFirstStation != null)
                {
                    listRouteStationsForTicket[i] = routeStation.ID;
                    i++;
                }
            }
            customerService.CreateCustomer(new CustomerDTO
            {
                FirstName = "Josef",
                LastName  = "Kosta",
                Email     = "*****@*****.**"
            });
            var customerDto = customerService.GetCustomerByEmail("*****@*****.**");

            ticketService.CreateTicket(customerDto.ID, companyId, new TicketDTO {
                Departure = DateTime.Now + (new TimeSpan(2, 0, 0)), RouteName = "Ceska"
            }, routeService.ListEmptyProgramsOfRouteStations(listRouteStationsForTicket).First());

            var ticketId = ticketService.ListAllTickets().FirstOrDefault().ID;

            ticketService.TicketReservation(ticketId);

            Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 4 ? "OK: Ticket reservation works... sorry deadline in 1 hour and I managed to create ticket 10 minutes ago so no time for clever tests" : "NOK:Ticket does not work");

            discountService = Container.Resolve <IDiscountService>();
            discountService.CreateDiscount(new DiscountDTO
            {
                Value        = 50,
                DiscountType = DiscountType.Student
            }, companyId);

            var discountId = discountService.ListDiscountsOfCompany(null, companyId).First().ID;

            ticketService.ClaimDiscount(ticketId, discountId, false, null);
            Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 2 ? "OK: Ticket claim discount works... 10 min to deadline...." : "NOK:Ticket does not work");
            ticketService.TicketRefund(ticketId);

            Console.WriteLine(ticketService.GetTicketById(ticketId).IsRefunded ? "OK: Ticket refund works... idk if this is worth 2 credits :/" : "NOK:Ticket does not work");
            routeService.DeleteRoute(routeId);
            foreach (var station in stations)
            {
                stationService.DeleteStation(station.ID);
            }
            customerService.DeleteCustomer(customerDto.ID);
        }
Esempio n. 2
0
 public void CreateSpecificRoute(int routeId, DateTime departTime, int vehicleId)
 {
     routeService.CreateSpecificRoute(routeId, departTime, vehicleId);
 }