Beispiel #1
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();
        }
Beispiel #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 : 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();
        }