Beispiel #1
0
        public void BookPlaceAsyncWithValidParametersExpectPlaceBooked()
        {
            UzContext      context        = _uzClient.GetUZContextAsync().Result;
            TrainsResponse trainsResponse = GetTrains(context, KievStationId, LvovStatinId, DateTime.Today.AddDays(DaysOffset));

            TrainsResponse.Train train          = trainsResponse.Trains.First();
            WagonsResponse       wagonsResponse = _uzClient.GetWagonsAsync(context, KievStationId, LvovStatinId, train.StationFrom.DateTime, train.TrainNumber, train.TrainType, train.Wagons.First().TypeCode).Result;

            WagonsResponse.Wagon wagon          = wagonsResponse.Wagons.First();
            PlacesResponse       placesResponse = GetPlaces(context, KievStationId, LvovStatinId, train.StationFrom.DateTime, train.TrainNumber, wagon.Number, wagon.CoachClass, wagon.CoachType);

            BookPlacesResponse bookPlaceResult = BookPlace(context,
                                                           KievStationId,
                                                           LvovStatinId,
                                                           DateTime.Today.AddDays(DaysOffset),
                                                           train.TrainNumber,
                                                           wagon.Number,
                                                           wagon.CoachClass,
                                                           wagon.TypeCode,
                                                           placesResponse.Places.First(),
                                                           placesResponse.PlaceType,
                                                           "Валера",
                                                           "Топор");

            Assert.IsFalse(bookPlaceResult.IsError);
        }
Beispiel #2
0
        private Train ConvertToResultedTrain(TrainsResponse.Train train, ICollection <ResponseWagonWithPlaceInfo> wagons, string wagonTypeCode)
        {
            string wagonTypeDescription = train.Wagons.First(wagon => wagon.TypeCode == wagonTypeCode).TypeDescription;

            List <Wagon> resultedWagons = (from wagon in wagons
                                           where wagon.TypeCode == wagonTypeCode
                                           let wagonType = wagonTypeDescription
                                                           select new Wagon {
                Number = wagon.Number,
                Price = wagon.Price,
                TypeDescription = wagonTypeDescription,
                PlaceType = wagon.PlaceType,
                Places = wagon.Places,
                CoachClass = wagon.CoachClass,
                TypeCode = wagon.TypeCode
            }).ToList();

            return(new Train {
                StationFrom = train.StationFrom,
                StationTo = train.StationTo,
                TrainNumber = train.TrainNumber,
                TravelTime = train.TravelTime,
                Wagons = resultedWagons
            });
        }
Beispiel #3
0
        public void GetWagonsAsyncWithInvalidTrainNumberExpectNoWagons()
        {
            UzContext      context        = _uzClient.GetUZContextAsync().Result;
            TrainsResponse trainsResponse = GetTrains(context, KievStationId, LvovStatinId, DateTime.Today.AddDays(DaysOffset));

            TrainsResponse.Train train = trainsResponse.Trains.First();

            WagonsResponse wagonsResponse = GetWagons(context,
                                                      KievStationId,
                                                      LvovStatinId,
                                                      train.StationFrom.DateTime,
                                                      "invalid_train",
                                                      train.TrainType,
                                                      train.Wagons.First().TypeCode);

            CollectionAssert.IsEmpty(wagonsResponse.Wagons);
        }
Beispiel #4
0
        public void GetPlacesAsyncWithInvalidCoachTypeExpectNoPlaces()
        {
            UzContext      context        = _uzClient.GetUZContextAsync().Result;
            TrainsResponse trainsResponse = GetTrains(context, KievStationId, LvovStatinId, DateTime.Today.AddDays(DaysOffset));

            TrainsResponse.Train train          = trainsResponse.Trains.First();
            WagonsResponse       wagonsResponse = _uzClient.GetWagonsAsync(context, KievStationId, LvovStatinId, train.StationFrom.DateTime, train.TrainNumber, train.TrainType, train.Wagons.First().TypeCode).Result;

            WagonsResponse.Wagon wagon = wagonsResponse.Wagons.First();

            PlacesResponse placesResponse = GetPlaces(context,
                                                      KievStationId,
                                                      LvovStatinId,
                                                      DateTime.Now.AddDays(-1),
                                                      train.TrainNumber,
                                                      wagon.Number,
                                                      wagon.CoachClass,
                                                      int.MaxValue);

            CollectionAssert.IsEmpty(placesResponse.Places);
        }
Beispiel #5
0
        public void GetPlacesAsyncWithValidParametersExpectPlaces()
        {
            UzContext      context        = _uzClient.GetUZContextAsync().Result;
            TrainsResponse trainsResponse = GetTrains(context, KievStationId, LvovStatinId, DateTime.Today.AddDays(DaysOffset));

            TrainsResponse.Train train          = trainsResponse.Trains.First();
            WagonsResponse       wagonsResponse = _uzClient.GetWagonsAsync(context, KievStationId, LvovStatinId, train.StationFrom.DateTime, train.TrainNumber, train.TrainType, train.Wagons.First().TypeCode).Result;

            WagonsResponse.Wagon wagon = wagonsResponse.Wagons.First();

            PlacesResponse placesResponse = GetPlaces(context,
                                                      KievStationId,
                                                      LvovStatinId,
                                                      train.StationFrom.DateTime,
                                                      train.TrainNumber,
                                                      wagon.Number,
                                                      wagon.CoachClass,
                                                      wagon.CoachType);

            Assert.IsFalse(string.IsNullOrWhiteSpace(placesResponse.PlaceType));
            CollectionAssert.IsNotEmpty(placesResponse.Places);
        }
Beispiel #6
0
 private async Task <PlacesResponse> GetPlacesAsync(UzContext uzContext, TrainsResponse.Train train, WagonsResponse.Wagon wagon, Request request)
 {
     return(await _uzClient.GetPlacesAsync(uzContext, train.StationFrom.Id, train.StationTo.Id,
                                           train.StationFrom.DateTime,
                                           train.TrainNumber, wagon.Number, wagon.CoachClass, wagon.CoachType));
 }
Beispiel #7
0
        private async Task <ICollection <ResponseWagonWithPlaceInfo> > FilterWagonsByAvailablePlaces(UzContext uzContext, TrainsResponse.Train train, WagonsResponse wagonsResponse, Request request)
        {
            var wagons = new List <ResponseWagonWithPlaceInfo>();

            foreach (WagonsResponse.Wagon wagon in wagonsResponse.Wagons)
            {
                PlacesResponse placesResponse = await GetPlacesAsync(uzContext, train, wagon, request);

                bool isPlaceAvailable = IsPlaceAvailable(placesResponse, request);
                if (isPlaceAvailable)
                {
                    ResponseWagonWithPlaceInfo wagonWithPlaceInfo = ExtendResponseWagonWithPlaceInfo(wagon, placesResponse, request);
                    wagons.Add(wagonWithPlaceInfo);
                }
            }
            return(wagons);
        }
Beispiel #8
0
        private async Task <ICollection <ResponseWagonWithPlaceInfo> > GetWagons(UzContext uzContext, TrainsResponse.Train train, string wagonTypeId, Request request)
        {
            WagonsResponse wagonsResponse =
                await _uzClient.GetWagonsAsync(uzContext, train.StationFrom.Id,
                                               train.StationTo.Id,
                                               train.StationFrom.DateTime,
                                               train.TrainNumber, train.TrainType, wagonTypeId);

            return(await FilterWagonsByAvailablePlaces(uzContext, train, wagonsResponse, request));
        }