예제 #1
0
        public void UpdateFlight()
        {
            // This test checks if the repository is able of updating an entity
            // that was updated outside of the repository (for example,
            // an updated entity sent to the service)

            // The instance created here has the same values as the DB entity
            Flight flight = new Flight {
                FlightId = 3, FlightNumber = "BY002"
            };

            // Update the flight number
            flight.FlightNumber = "BY002_updated";

            //TODO: Lab 02 Exercise 2, Task 4.1 : Implement the UpdateFlight Method
            FlightRepository repository;

            using (repository = new FlightRepository())
            {
                repository.Edit(flight);
                repository.Save();
            }

            using (repository = new FlightRepository())
            {
                Flight updatedFlight = repository.FindBy(f => f.FlightNumber == "BY002_updated").FirstOrDefault();
                Assert.IsNotNull(updatedFlight);
            }
        }
예제 #2
0
        public void UpdateUsingTwoRepositories()
        {
            LocationRepository locationRepository = new LocationRepository();
            FlightRepository   flightRepository = new FlightRepository();
            Flight             flight, flightFromDb;
            Location           location;

            using (TransactionScope scope = new TransactionScope())
            {
                // Update flight and location
                flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single();
                flight.FlightNumber = "BY001_updated";
                // Since the flight was retrieved using the current repository,
                // we don't need to call the Edit method
                flightRepository.Save();

                location      = locationRepository.FindBy(l => l.City == "Rome").Single();
                location.City = "Rome_updated";
                // Since the location was retrieved using the current repository,
                // we don't need to call the Edit method
                locationRepository.Save();

                //TODO: Lab 02, Exercise 2 Task 5.2 : Get flight to check is updated

                //TODO : Revert transaction
            }


            //TODO: Lab 02, Exercise 2 Task 5.4 : Check that update flight has been reverted

            locationRepository.Dispose();
            flightRepository.Dispose();
        }
예제 #3
0
        public void UpdateUsingTwoRepositories()
        {
            LocationRepository locationRepository = new LocationRepository();
            FlightRepository   flightRepository = new FlightRepository();
            Flight             flight, flightFromDb;
            Location           location;

            using (TransactionScope scope = new TransactionScope())
            {
                // Update flight and location
                flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single();
                flight.FlightNumber = "BY001_updated";
                // Since the flight was retrieved using the current repository,
                // we don't need to call the Edit method
                flightRepository.Save();

                location      = locationRepository.FindBy(l => l.City == "Rome").Single();
                location.City = "Rome_updated";
                // Since the location was retrieved using the current repository,
                // we don't need to call the Edit method
                locationRepository.Save();

                //TODO: Lab 02, Exercise 2 Task 5.2 : Review the query for the updated flight that is inside the transaction scope
                flightFromDb = (from f in flightRepository.GetAll()
                                where f.Source.City == "Rome_updated"
                                select f).FirstOrDefault();

                Assert.IsNotNull(flightFromDb);
                Assert.AreEqual(flightFromDb.FlightNumber, "BY001_updated");

                // Do not commit the transaction
                //scope.Complete();
            }


            //TODO: Lab 02, Exercise 2 Task 5.4 : Review the query for the updated flight that is outside the transaction scope
            flightFromDb = (from f in flightRepository.GetAll()
                            where f.Source.City == "Rome_updated"
                            select f).FirstOrDefault();

            Assert.IsNull(flightFromDb);

            locationRepository.Dispose();
            flightRepository.Dispose();
        }
예제 #4
0
        public void DeleteFlight()
        {
            FlightRepository repository;

            using (repository = new FlightRepository())
            {
                Flight flight = repository.FindBy(f => f.FlightNumber == "BY004").Single();
                repository.Delete(flight);

                repository.Save();
            }

            using (repository = new FlightRepository())
            {
                Flight flight = repository.FindBy(f => f.FlightNumber == "BY004").FirstOrDefault();
                Assert.IsNull(flight);
            }
        }