public void Execute()
        {
            Assert.DoesNotThrowAsync(async() =>
            {
                var tourRepository     = new TourRepository();
                var providerRepository = new ProviderRepository();

                var apiDownloader = new Mock <IApiDownloader>();
                apiDownloader.Setup(p => p.Download()).ReturnsAsync(_availabilityResponse);
                var logger = Mock.Of <ILogger>();

                var importer = new Importer(tourRepository, providerRepository, apiDownloader.Object, logger);
                await importer.Execute(1);

                for (int index = 1; index < 3; index++)
                {
                    var tour           = await tourRepository.Get(index);
                    var availabilities = _tourAvailabilities.Where(p => p.TourId == tour.TourId).ToArray();
                    Assert.AreEqual(availabilities.Length, tour.Availabilities.Count);

                    for (var i = 0; i < availabilities.Length; i++)
                    {
                        var availability     = availabilities[i];
                        var tourAvailability = tour.Availabilities[i];

                        Assert.AreEqual(availability.AdultPrice, tourAvailability.AdultPrice);
                        Assert.AreEqual(availability.AvailabilityCount, tourAvailability.AvailabilityCount);
                        Assert.AreEqual(availability.StartDate, tourAvailability.StartDate);
                        Assert.AreEqual(availability.TourDuration, tourAvailability.TourDuration);
                        Assert.AreEqual(availability.TourId, tourAvailability.TourId);
                    }
                }
            });
        }
        public void Updates_to_existing_tours_succeed()
        {
            //TODO - check values are updated
            Assert.DoesNotThrowAsync(async() =>
            {
                var tourRepository     = new TourRepository();
                var providerRepository = new ProviderRepository();
                var logger             = new Mock <ILogger>();
                var apiDownloader      = new Mock <IApiDownloader>();

                apiDownloader.Setup(api => api.Download()).ReturnsAsync(_newUpdatesForTour1);

                var importer = new Importer(
                    tourRepository: tourRepository,
                    providerRepository: providerRepository,
                    apiDownloader: apiDownloader.Object,
                    logger: logger.Object);

                await importer.Execute(providerId: 1);

                var tour1 = tourRepository.Get(tourId: 1);
                tour1.Result.Availabilities.Count.Should().Be(_newUpdatesForTour1.Body.Count);

                var orderedResults = tour1.Result.Availabilities.OrderBy(a => a.StartDate).ToList();

                for (var i = 0; i < _newUpdatesForTour1.Body.Count; i++)
                {
                    orderedResults[i].StartDate.Should().Be(DateTime.Parse(_newUpdatesForTour1.Body[i].DepartureDate));
                    //TODO - test the pricing algorithm explicitly
                    orderedResults[i].AdultPrice.Should().Be(_newUpdatesForTour1.Body[i].Price + (_newUpdatesForTour1.Body[i].Price * 0.15m) - (_newUpdatesForTour1.Body[i].Price * 0.95m));
                    orderedResults[i].TourDuration.Should().Be(_newUpdatesForTour1.Body[i].Nights);
                    orderedResults[i].AvailabilityCount.Should().Be(_newUpdatesForTour1.Body[i].Spaces);
                }
            });
        }
示例#3
0
 private void InsertToursIntoRepository(IEnumerable <Tour> tours)
 {
     using (ITourRepository repository = new TourRepository(DatabaseSourceDefinitor.ConnectionString))
     {
         repository.InsertTours(tours.ToArray());
     }
 }
示例#4
0
 private Tour[] GetToursOfLeague(int leagueId)
 {
     using (ITourRepository repository = new TourRepository(DatabaseSourceDefinitor.ConnectionString))
     {
         return(repository.GetToursInLeague(leagueId));
     }
 }
        public ActionResult AddTour(Int32 id = -1)
        {
            if (id != -1)
            {
                var tourRepository = new TourRepository();
                Tour tour = tourRepository.GetById(id);
                if (tour != null)
                {
                    var model = new TourModel
                    {
                        Id = tour.Id,
                        Name = tour.Name,
                        StartDate = tour.StartDate,
                        EndDate = tour.EndDate,
                        PlaceCount = tour.PlaceCount,
                        Price = tour.Price,
                        Description = tour.Description
                    };

                    return View(model);
                }
            }

            return View(new TourModel());
        }
        public ActionResult Index()
        {
            TourRepository tourRepository = new TourRepository();
            List<Tour> tours = tourRepository.GetAll().Where(tour => tour.StartDate >= DateTime.Now).Where(x => x.Orders.Count() < x.PlaceCount).ToList();

            return View(tours);
        }
示例#7
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context    = context;
     Tours       = new TourRepository(context);
     Attendences = new AttendenceRepository(context);
     Followings  = new FollowingRepository(context);
     Genres      = new GenreRepository(context);
 }
示例#8
0
        private void btnBuy_Click(object sender, EventArgs e)
        {
            var service = new PaymentService();

            service.type = PaymentType.Cash;
            TourRepository repo = new TourRepository(service);

            repo.Pay(new List <Customer>(), new Tour());
        }
示例#9
0
 public TravelService(DbSettings dbSettings)
 {
     TravelRepository   = new TravelRepository(dbSettings);
     LocationRepository = new LocationRepository(dbSettings);
     FlightRepository   = new FlightRepository(dbSettings);
     HotelRepository    = new HotelRepository(dbSettings);
     CityWalkRepository = new CityWalkRepository(dbSettings);
     PoiRepository      = new PoiRepository(dbSettings);
     DayPlanRepository  = new DayPlanRepository(dbSettings);
     TourRepository     = new TourRepository(dbSettings);
     ListsRepository    = new ListsRepository(dbSettings);
     HotelsApiClient    = new HotelsApiClient();
     TriposoApiClient   = new TriposoApiClient();
 }
        public void Can_handle_no_updates()
        {
            //TODO - also check the actual objects themselves are the same
            Assert.DoesNotThrowAsync(async() =>
            {
                var tourRepository     = new TourRepository();
                var providerRepository = new ProviderRepository();
                var logger             = new Mock <ILogger>();
                var apiDownloader      = new Mock <IApiDownloader>();

                apiDownloader.Setup(api => api.Download()).ReturnsAsync(_emptyAvailabilityResponse);

                var importer = new Importer(
                    tourRepository: tourRepository,
                    providerRepository: providerRepository,
                    apiDownloader: apiDownloader.Object,
                    logger: logger.Object);

                await importer.Execute(1);
            });
        }
        public async void AddTour_MemoryDb_ShouldBePresentInDb()
        {
            string tourName = "Tour1";
            var    options  = new DbContextOptionsBuilder <ExploreDb>().UseInMemoryDatabase(databaseName: "Add_writes_to_database").Options;

            using (var context = new ExploreDb(options))
            {
                var tourRepo    = new TourRepository(context);
                var unit        = new UnitOfWork(context, tourRepo, new ReservationRepository(context));
                var tourService = new TourService(unit);
                var tour        = new TourDto()
                {
                    Name = tourName
                };

                await tourService.AddTourAsync(tour);

                var result = await context.Tours.SingleAsync();

                Assert.Equal(result.Name, tourName);
            }
        }
        public ActionResult AddTour(TourModel model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    model.ImageMimeType = image.ContentType;
                    model.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(model.ImageData, 0, image.ContentLength);
                }

                Tour tour = new Tour
                {
                    Name = model.Name,
                    StartDate = model.StartDate.Value,
                    EndDate = model.EndDate.Value,
                    PlaceCount = model.PlaceCount,
                    Price = model.Price,
                    Description = model.Description,
                    Image = model.ImageData
                };

                var tourRepository = new TourRepository();

                if (model.Id.HasValue)
                {
                    tour.Id = model.Id.Value;
                    tourRepository.UpdateTour(tour);
                }
                else
                {
                    tourRepository.AddNewTour(tour);
                }

                return RedirectToAction("Index", "Home");
            }
            return View(model);
        }
        public static void Register(IUnityContainer container)
        {
            var sessionFactory       = container.Resolve <ISessionFactory>();
            var playerRepository     = new PlayerRepository(sessionFactory);
            var gameRepository       = new GameRepository(sessionFactory);
            var courseRepository     = new CourseRepository(sessionFactory);
            var statisticsRepository = new StatisticsRepository(sessionFactory);
            var scoreRepository      = new ScoreRepository(sessionFactory);
            var tourRepository       = new TourRepository(sessionFactory);

            container.RegisterType <IPlayerRepository, PlayerRepository>();
            container.RegisterType <IGameRepository, GameRepository>();
            container.RegisterType <ICourseRepository, CourseRepository>();
            container.RegisterType <IStatisticsRepository, StatisticsRepository>();
            container.RegisterType <IScoreRepository, ScoreRepository>();
            container.RegisterType <ITourRepository, TourRepository>();

            container.RegisterInstance(playerRepository);
            container.RegisterInstance(gameRepository);
            container.RegisterInstance(courseRepository);
            container.RegisterInstance(statisticsRepository);
            container.RegisterInstance(scoreRepository);
            container.RegisterInstance(tourRepository);
        }
        public ActionResult Orders()
        {
            TourRepository tourRepository = new TourRepository();
            List<Tour> tours = tourRepository.GetAll().ToList();

            return View(tours);
        }
        public ActionResult OrderTour(int id)
        {
            TourRepository tourRepository = new TourRepository();
            List<Tour> tours = tourRepository.GetAll().Where(t => t.StartDate >= DateTime.Now).Where(x => x.Orders.Count() < x.PlaceCount).ToList();
            ViewBag.Tours = new SelectList(tours, "Id", "Name", id);

            var tour = tours.First(x => x.Id == id);
            var number = Enumerable.Range(1, tour.PlaceCount - tour.Orders.Sum(x => x.PlaceCount));
            ViewBag.Number = new SelectList(number);

            return View();
        }
示例#16
0
 public TourController(TourRepository repository)
 {
     this.repository = repository;
 }
        public ActionResult OrderTour(int id, int placeNumber)
        {
            UserRepository userRepository = new UserRepository();
            OrderRepository orderRepository = new OrderRepository();
            TourRepository tourRepository = new TourRepository();

            Tour tour = tourRepository.GetById(id);

            if (tour != null)
            {
                Order order = new Order();
                order.Date = DateTime.Now;
                order.PlaceCount = placeNumber;
                order.Tour = tour;
                order.User = userRepository.GetBy(x => x.Email == User.Identity.Name);

                orderRepository.AddOrder(order);
            }

            return Redirect("/Tour/Orders");
        }
 public ActionResult RemomeTour(Int32 id)
 {
     var tourRepository = new TourRepository();
     tourRepository.DeleteTourById(id);
     return RedirectToAction("AllTours");
 }
 public ActionResult AllTours()
 {
     var tourRepository = new TourRepository();
     List<Tour> model = tourRepository.GetAll().ToList();
     return View(model);
 }
 public ActionResult Tour(int id)
 {
     TourRepository tourRepository = new TourRepository();
     Tour tour = tourRepository.GetById(id);
     return View(tour);
 }