public void ShouldGetDataFromJsonFile()
        {
            var             filePath = @"..\..\..\test-case.json";
            ImportTestCases test     = new ImportTestCases(filePath);
            var             data     = test.GetJsonDataIntoObject();

            Assert.IsNotNull(data);

            IReservationRepository repo = new ReservationRepository(test);
            var reservations            = repo.GetReservations();

            Assert.IsNotNull(reservations);

            ICampsiteRepository campsiteRepository = new CampsiteRepository(test);
            var campsites = campsiteRepository.GetCampsites();

            Assert.IsNotNull(campsites);

            ISearchQueryRepository searchQueryRepository = new SearchQueryRepository(test);
            var searchQuery = searchQueryRepository.GetSearchQuery();

            Assert.IsNotNull(searchQuery);

            IGapRuleRepository gapRuleRepository = new GapRuleRepository(test);
            var gapRules = gapRuleRepository.GetGapRules();

            Assert.IsNotNull(gapRules);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var filePath = @"..\..\..\test-case.json";

            if (args.Length == 0)
            {
                Console.WriteLine("No file supplied, using default \"test-case.json\" file.");
            }
            if (args.Length > 0)
            {
                if (File.Exists(args[0]))
                {
                    Console.WriteLine($"Using the specified \"{args[0]}\" file.");
                    filePath = args[0];
                }
                else
                {
                    Console.WriteLine($"Could not find the specified \"{args[0]}\" file, using default \"test-case.json\" file.");
                }
            }

            ImportTestCases       importTestCases       = new ImportTestCases(filePath);
            SearchQueryRepository searchQueryRepository = new SearchQueryRepository(importTestCases);
            IReservationEngine    engine = ReservationEngineFactory.Create(filePath);
            var availableCampsites       = engine.GetAvailableCampsitesForSearchQuery(searchQueryRepository.GetSearchQuery());

            foreach (var campsite in availableCampsites)
            {
                Console.WriteLine($"{campsite.Id} - {campsite.Name}");
            }
            Console.ReadKey();
        }
예제 #3
0
        public static IReservationEngine Create(string filename)
        {
            ImportTestCases       test = new ImportTestCases(filename);
            ReservationRepository reservationRepository = new ReservationRepository(test);
            CampsiteRepository    campsiteRepository    = new CampsiteRepository(test);
            GapRuleRepository     gapRuleRepository     = new GapRuleRepository(test);
            ReservationRuleChain  ruleChain             = new ReservationRuleChain(gapRuleRepository);
            IReservationEngine    engine = new ReservationEngine(reservationRepository, campsiteRepository, ruleChain);

            return(engine);
        }
        public void ShouldGetAvailableCampsitesForDifferentGapSize()
        {
            var                    filePath = @"..\..\..\test-case3.json";
            ImportTestCases        test     = new ImportTestCases(filePath);
            ISearchQueryRepository searchQueryRepository = new SearchQueryRepository(test);
            IReservationEngine     engine = ReservationEngineFactory.Create(filePath);

            var data = engine.GetAvailableCampsitesForSearchQuery(searchQueryRepository.GetSearchQuery()).ToList();

            Assert.IsTrue(data.Exists(x => x.Id == 1));
            Assert.IsFalse(data.Exists(x => x.Id == 2));
            Assert.IsFalse(data.Exists(x => x.Id == 3));
            Assert.IsFalse(data.Exists(x => x.Id == 4));
            Assert.IsFalse(data.Exists(x => x.Id == 5));
            Assert.IsFalse(data.Exists(x => x.Id == 6));
            Assert.IsTrue(data.Exists(x => x.Id == 7));
            Assert.IsFalse(data.Exists(x => x.Id == 8));
            Assert.IsFalse(data.Exists(x => x.Id == 9));
        }