Exemple #1
0
        public void empty_file_must_return_empty_list()
        {
            var inputRep = new RouteRepository("../../../stdin/no-content.csv");
            var result   = inputRep.Get();

            Assert.True(result.Count == 0);
        }
Exemple #2
0
        public void new_route_must_be_persisted_in_file()
        {
            var newFile = "../../../stdin/new- route.csv";

            try
            {
                File.Create(newFile).Close();
                var inputRep = new RouteRepository(newFile);
                var newRoute = inputRep.Save(new infra.dto.RouteData("GIG", "LAG", 150));

                Assert.True(newRoute.OriginAirport.Equals("GIG"));
                Assert.True(newRoute.DestinationAirport.Equals("LAG"));
                Assert.True(newRoute.FlightPrice.Equals(150));

                var result = inputRep.Get();
                Assert.True(result.Count == 2);
                Assert.True(result.Exists(x => x.AirportName.Equals("GIG")));
                Assert.True(result.Exists(x => x.AirportName.Equals("LAG")));
                Assert.True(result.Find(x => x.AirportName.Equals("GIG")).Connections.Exists(x => x.Airport.AirportName.Equals("LAG")));
                Assert.True(result.Find(x => x.AirportName.Equals("GIG")).Connections.Find(x => x.Airport.AirportName.Equals("LAG")).Price == 150);
            }
            finally { if (File.Exists(newFile))
                      {
                          File.Delete(newFile);
                      }
            }
        }
Exemple #3
0
        public void invalid_source_must_throw_exception()
        {
            var inputRep             = new RouteRepository("invalid-source");
            FileNotFoundException ex = Assert.Throws <FileNotFoundException>(() => inputRep.Get());

            Assert.Equal("stdin-not-found", ex.Message);
        }
Exemple #4
0
        public static string PrepareTicketResponse(string ticketRequest)
        {
            string userId = ticketRequest;

            Console.WriteLine($" Ticket input: \n" +
                              $"userId: {userId}\n");

            SaleRepository saleRepository = new SaleRepository();
            List <Sale>    saleResults    = saleRepository.GetUserSales(Convert.ToInt32(userId));

            RouteRepository routeRepository = new RouteRepository();

            string resultString = "";

            foreach (Sale sale in saleResults)
            {
                Route route = routeRepository.Get(sale.route_id);
                List <TrainConnection> result = routeRepository.SearchForTrainConnection(route.departure_date, sale.from_station, sale.to_station);
                decimal  price = 0;
                TimeSpan time  = new TimeSpan();
                TimeSpan hour  = new TimeSpan();

                foreach (TrainConnection r in result)
                {
                    if (r.travel_id == route.id)
                    {
                        price = r.total_price;
                        time  = r.total_duration;
                        hour  = r.departure_hour;
                    }
                }

                string   saleTicketNameAmountPercentage     = saleRepository.GetSaleTicketNameAmountPercentage(sale.id);
                string[] saleTicketNameAmountPercentagArray = saleTicketNameAmountPercentage.Split(',');
                var      ticketName       = saleTicketNameAmountPercentagArray[0];
                var      ticketsAmount    = saleTicketNameAmountPercentagArray[1];
                var      ticketPercentage = saleTicketNameAmountPercentagArray[2];

                var totalPrice = price * (Convert.ToInt32(ticketsAmount)) * (Convert.ToDecimal(ticketPercentage) / 100);
                //(Convert.ToInt32(ticketPercentage) / 100.0) *
                TicketResponse ticketResponse
                    = new TicketResponse(
                          route.train_name.ToString(),
                          sale.from_station,
                          sale.to_station,
                          sale.sale_date.ToString(),
                          route.departure_date.ToString(),
                          hour.ToString(),
                          totalPrice.ToString(),
                          time.ToString(),
                          sale.payment_status.ToString(),
                          ticketName,
                          ticketsAmount);
                resultString += ticketResponse.ToString() + ';';
            }

            resultString = resultString.Remove(resultString.Length - 1, 1);
            return(resultString);
        }
Exemple #5
0
        public void input_sample_route_must_have_connections()
        {
            var inputRep = new RouteRepository("../../../stdin/input-routes_sample.csv");
            var result   = inputRep.Get();

            Assert.True(result.Count == 2);
            Assert.True(result.Exists(x => x.AirportName.Equals("GRU")));
            Assert.True(result.Exists(x => x.AirportName.Equals("BRC")));
            Assert.True(result.Find(x => x.AirportName.Equals("GRU")).Connections.Exists(x => x.Airport.AirportName.Equals("BRC")));
            Assert.True(result.Find(x => x.AirportName.Equals("GRU")).Connections.Find(x => x.Airport.AirportName.Equals("BRC")).Price.Equals(10));
        }
Exemple #6
0
        public void input_route_must_remove_escaped_rows()
        {
            var inputRep = new RouteRepository("../../../stdin/escape-rows.csv");
            var result   = inputRep.Get();

            Assert.True(result.Count == 5);
            Assert.True(result.Exists(x => x.AirportName.Contains("GRU")));
            Assert.True(result.Exists(x => x.AirportName.Contains("BRC")));
            Assert.True(result.Exists(x => x.AirportName.Contains("SCL")));
            Assert.True(result.Exists(x => x.AirportName.Contains("ORL")));
            Assert.True(result.Exists(x => x.AirportName.Contains("CDG")));
        }