public void TravelDateRepositoryOperations()
        {
            IDataAccessor dataAccessor = new DataAccessor(false, "Data Source=TravelDateRepositoryTest.db");

            using (var dbContext = dataAccessor.GetNewDatabaseContext())
            {
                dbContext.Database.EnsureDeleted();
                dbContext.Database.EnsureCreated();
            }
            ITravelDateRepository travelDateRepository = new TravelDateRepository(dataAccessor);

            travelDateRepository.Add("Oda", new DateTime(2020, 11, 9));
            travelDateRepository.Add("Vissza", new DateTime(2020, 11, 9));
            var result  = travelDateRepository.Get(1);
            var results = travelDateRepository.GetAll();

            Assert.IsTrue(results.Count == 2);
            Assert.IsTrue(result.TravelName == "Oda");
            Assert.IsTrue(result.TravelerTravelDateReferences.Count == 0);

            travelDateRepository.Remove(1);
            travelDateRepository.Remove(2);
            results = travelDateRepository.GetAll();
            Assert.IsTrue(results.Count == 0);
        }
        public void TravelDateRepositoryUpdate()
        {
            IDataAccessor dataAccessor = new DataAccessor(false, "Data Source=TravelDateRepositoryUpdateTest.db");

            using (var dbContext = dataAccessor.GetNewDatabaseContext())
            {
                dbContext.Database.EnsureDeleted();
                dbContext.Database.EnsureCreated();
            }
            var travelDateRepository = new TravelDateRepository(dataAccessor);

            travelDateRepository.Add("First Travel", DateTime.MinValue);
            travelDateRepository.Add("Second Travel", DateTime.MaxValue);

            var allTravelDates = travelDateRepository.GetAll();
            var travelDate2    = allTravelDates[1];

            Assert.IsTrue(travelDate2.TravelerTravelDateReferences.Count == 0);

            Assert.IsTrue(allTravelDates.Count == 2);
            Assert.IsTrue(travelDate2.TravelName == "Second Travel");

            travelDate2.TravelName = "Modified Second Travel";
            travelDateRepository.Update(travelDate2);

            var modifiedAllTravelers = travelDateRepository.GetAll();
            var modifiedTraveler2    = modifiedAllTravelers[1];

            Assert.IsTrue(modifiedTraveler2.TravelName == "Modified Second Travel");
            Assert.IsTrue(allTravelDates.Count == 2);
        }
Beispiel #3
0
        public void TravelerTravelDateReferenceRepositoryOperations()
        {
            IDataAccessor dataAccessor = new DataAccessor(false, "Data Source=TravelerTravelDateRepositoryTest.db");

            using (var dbContext = dataAccessor.GetNewDatabaseContext())
            {
                dbContext.Database.EnsureDeleted();
                dbContext.Database.EnsureCreated();
            }
            ITravelerTravelDateReferenceRepository travelerTravelDateReferenceRepository = new TravelerTravelDateReferenceRepository(dataAccessor);
            ITravelerRepository   travelerRepository   = new TravelerRepository(dataAccessor);
            ITravelDateRepository travelDateRepository = new TravelDateRepository(dataAccessor);

            travelerRepository.Add("Zoltan", "Zoltan", "+3655555", "Ada", "Bregenz", true, 500);
            travelerRepository.Add("Zoltan", "Zoltan", "+3655555", "Ada", "Bregenz", true, 500);

            travelDateRepository.Add("Oda", new DateTime(2020, 11, 9));
            travelDateRepository.Add("Vissza", new DateTime(2020, 11, 9));

            travelerTravelDateReferenceRepository.Add(1, 1);
            travelerTravelDateReferenceRepository.Add(1, 2);
            travelerTravelDateReferenceRepository.Add(2, 1);
            travelerTravelDateReferenceRepository.Add(2, 2);
            var results1 = travelerTravelDateReferenceRepository.GetAll();

            Assert.IsTrue(results1.Count == 4);

            travelerTravelDateReferenceRepository.Remove(1, 1);
            var results2 = travelerTravelDateReferenceRepository.GetAll();

            Assert.IsTrue(results2.Count == 3);

            travelDateRepository.Remove(2);
            var results3 = travelerTravelDateReferenceRepository.GetAll();

            Assert.IsTrue(results3.Count == 1);

            travelerRepository.Remove(2);
            var results4 = travelerTravelDateReferenceRepository.GetAll();

            Assert.IsTrue(results4.Count == 0);
        }