Exemplo n.º 1
0
        public void TestThatServiceLocatorAvailableFlightsReturnsExpectedFlights()
        {
            var firstFlight  = new Flight(DateTime.Today, DateTime.Today.AddDays(1), 500);
            var secondFlight = new Flight(DateTime.Today, DateTime.Today.AddDays(3), 200);
            var locator      = new ServiceLocator();

            locator.AddFlight(firstFlight);
            locator.AddFlight(secondFlight);

            Assert.AreSame(firstFlight, locator.AvailableFlights[0]);
            Assert.AreSame(secondFlight, locator.AvailableFlights[1]);
            Assert.AreEqual(2, locator.AvailableFlights.Count);
        }
Exemplo n.º 2
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flightToBook    = new Flight(new DateTime(2009, 11, 1), new DateTime(2009, 11, 30), 100);
            var            remainingFlight = new Flight(new DateTime(2009, 11, 1), new DateTime(2009, 11, 15), 200);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);
            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);
            var target = new User("Bob");

            target.book(flightToBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 3
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flighttoBook    = new Flight(StartDate, EndDate, 12);
            var            flightRemaining = new Flight(StartDate, new DateTime(2010, 12, 12), 16);

            serviceLocator.AddFlight(flighttoBook);
            serviceLocator.AddFlight(flightRemaining);
            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);
            var target = new User("Bob");

            target.book(flighttoBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(flightRemaining, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 4
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();
            var            flightToBook   = new Flight(DateTime.Now, DateTime.Now.AddDays(5), 0);
            var            otherFlight    = new Flight(DateTime.Now, DateTime.Now.AddDays(10), 0);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(otherFlight);
            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);
            var target = new User("Bob");

            target.book(flightToBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(otherFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 5
0
        public void TestThatUserDoesRemoveCarFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            FlightToBook    = new Flight(System.DateTime.MinValue, System.DateTime.MaxValue, 20);
            var            remainingFlight = new Flight(System.DateTime.MinValue, System.DateTime.MaxValue, 15);

            serviceLocator.AddFlight(FlightToBook);
            serviceLocator.AddFlight(remainingFlight);
            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);
            var target = new User("Bob");

            target.book(FlightToBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 6
0
        public void TestThatFlightIsRemovedFromServiceLocator()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flightToBook    = ObjectMother.FlightToChicago();
            var            remainingFlight = ObjectMother.FlightToChicago();

            serviceLocator = new ServiceLocator();
            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);
            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);
            var target = new User("Bob");

            target.book(flightToBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 7
0
        public void TestThatUserDoesRemoveFlightsWhichAreBookedFromListOfAvailableFlightsInServiceLocatorSinceBookedFlightsHaveNoMoreRoomOnThemForOtherPeopleToBuyTicketsToFlyOnThem()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flightToBook    = new Flight(new DateTime(2011, 4, 15), new DateTime(2011, 4, 20), 1000);
            var            remainingFlight = new Flight(new DateTime(2011, 4, 5), new DateTime(2011, 4, 10), 1000);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).SetValue(serviceLocator, serviceLocator);

            var target = new User("Bob");

            target.book(flightToBook);

            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 8
0
        public void TestThatServiceLocatorRemovesFlightWhenBooked()
        {
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flightToBook    = new Flight(new DateTime(2000, 01, 01), new DateTime(2000, 01, 07), 5);
            var            remainingFlight = new Flight(new DateTime(2000, 01, 01), new DateTime(2000, 01, 07), 6);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(serviceLocator, serviceLocator);

            var target = new User("Jimbo");

            target.book(flightToBook);
            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Exemplo n.º 9
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            DateTime       StartDate       = new DateTime(2009, 11, 1);
            DateTime       EndDate         = new DateTime(2009, 11, 30);
            DateTime       StartDate2      = new DateTime(2009, 5, 1);
            DateTime       EndDate2        = new DateTime(2009, 5, 21);
            ServiceLocator serviceLocator  = new ServiceLocator();
            var            flightToBook    = new Flight(StartDate, EndDate, 500);
            var            remainingFlight = new Flight(StartDate2, EndDate2, 200);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).SetValue(serviceLocator, serviceLocator);

            var target = new User("Tom");

            target.book(flightToBook);

            Assert.AreEqual(serviceLocator.AvailableFlights.Count, 1);
            Assert.AreSame(serviceLocator.AvailableFlights[0], remainingFlight);
        }
Exemplo n.º 10
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();
            DateTime       startDate      = new DateTime();
            DateTime       endDate        = startDate;

            var flightToBook    = new Flight(startDate, endDate, 10);
            var remainingFlight = new Flight(startDate, endDate, 10);

            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

            typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).SetValue(serviceLocator, serviceLocator);

            var target = new User("Bro");

            target.book(flightToBook);

            var availableFlights = ServiceLocator.Instance.AvailableFlights.Count;
            var flightRemaining  = ServiceLocator.Instance.AvailableFlights[0];

            Assert.AreEqual(availableFlights, 1);
            Assert.AreSame(flightRemaining, remainingFlight);
        }