Пример #1
0
 public void TestThatUserDoesRemoveCarFromServiceLocatorWhenBooked()
 {
     ServiceLocator serviceLocator = new ServiceLocator();
     var carToBook = new Car(5);
     var remainingCar = new Car(7);
     serviceLocator.AddCar(carToBook);
     serviceLocator.AddCar(remainingCar);
     typeof(ServiceLocator).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).SetValue(serviceLocator, serviceLocator);
     var target = new User("Bob");
     target.book(carToBook);
     Assert.AreEqual(1, ServiceLocator.Instance.AvailableCars.Count);
     Assert.AreSame(remainingCar, ServiceLocator.Instance.AvailableCars[0]);
 }
Пример #2
0
        public void TestThatServiceLocatorAvailableCarsReturnsExpectedCars()
        {
            var firstCar = new Car(5);
            var secondCar = new Car(4);
            var locator = new ServiceLocator();

            locator.AddCar(firstCar);
            locator.AddCar(secondCar);

            Assert.AreSame(firstCar, locator.AvailableCars[0]);
            Assert.AreSame(secondCar, locator.AvailableCars[1]);
            Assert.AreEqual(2, locator.AvailableCars.Count);
        }
Пример #3
0
        public void TestThatServiceLocatorAvailableDiscountsReturnsExpectedDiscounts()
        {
            var firstDiscount = new Discount(0.05, 1000);
            var secondDisctount = new Discount(0.10, 1750);
            var locator = new ServiceLocator();

            locator.AddDiscount(firstDiscount);
            locator.AddDiscount(secondDisctount);

            Assert.AreSame(firstDiscount, locator.AvailableDiscounts[0]);
            Assert.AreSame(secondDisctount, locator.AvailableDiscounts[1]);
            Assert.AreEqual(2, locator.AvailableDiscounts.Count);
        }
Пример #4
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);
        }
Пример #5
0
 public void TestThatUserDoesRemovveFlightFromServiceLocatorWhenBooked()
 {
     ServiceLocator serviceLocator = new ServiceLocator();
     var flightToBook = new Flight(new DateTime(2009, 11, 1), new DateTime(2009, 11, 30), 750);
     var remainingFlight = new Flight(new DateTime(2009, 11, 2), new DateTime(2009, 11, 28), 500);
     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]);
 }
Пример #6
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]);
 }
Пример #7
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]);
 }
Пример #8
0
        public void TestThatUserDoesRemoveFlightFromSerivceLocatorWhenBooked()
        {
            ServiceLocator serviceloc = new ServiceLocator();
            var flightToBook = new Flight(new DateTime(2009, 11, 1), new DateTime(2009, 11, 30), 100);
            var remainingFlight = new Flight(new DateTime(2009, 12, 1), new DateTime(2009, 12, 30), 1000);
            serviceloc.AddFlight(flightToBook);
            serviceloc.AddFlight(remainingFlight);

            typeof(ServiceLocator).GetField("_instance", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(serviceloc, serviceloc);

            var target = new User("Bobby");
            target.book(flightToBook);

            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Пример #9
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]);
        }
Пример #10
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]);
        }
Пример #11
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();

            var flightToBook = ObjectMother.CoupleOfDaysFlight();
            var remainingFlight = ObjectMother.LotsOfDaysFlight();
            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

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

            var target = new User("Alice");
            target.book(flightToBook);

            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Пример #12
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            System.DateTime arrive = new System.DateTime(13, 12, 10);
            System.DateTime depart = new System.DateTime(13, 12, 14);
            ServiceLocator serviceLocator = new ServiceLocator();
            var flightToBook = new Flight(arrive, depart, 4);
            var remainingFlight = new Flight(new System.DateTime(14, 11, 19),new System.DateTime(14, 11, 24),50);

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

            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Пример #13
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();
            var flightToBook = new Flight(DateTime.Now, DateTime.Now.AddDays(5), 1000);
            var remainingFlight1 = new Flight(DateTime.Now.AddDays(2), DateTime.Now.AddDays(15), 1300);
            var remainingFlight2 = new Flight(DateTime.Now.AddDays(5), DateTime.Now.AddDays(18), 700);
            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight1);
            serviceLocator.AddFlight(remainingFlight2);

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

            var target = new User("Shawn");
            target.book(flightToBook);

            Assert.AreEqual(2, ServiceLocator.Instance.AvailableFlights.Count);
              			Assert.AreSame(remainingFlight1, ServiceLocator.Instance.AvailableFlights[0]);
            Assert.AreSame(remainingFlight2, ServiceLocator.Instance.AvailableFlights[1]);
        }
Пример #14
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);
        }
Пример #15
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();
            DateTime startDateForFirstFlight = new DateTime(2012, 03, 26);
            DateTime endDateForFirstFlight = new DateTime(2012, 05, 30);
            int milesForFirstFlight = 900;
            DateTime startDateForSecondFlight = new DateTime(2012, 07, 01);
            DateTime endDateForSecondFlight = new DateTime(2012, 07, 05);
            int milesForSecondFlight = 510;
            var flightToBook = new Flight(startDateForFirstFlight, endDateForFirstFlight, milesForFirstFlight);
            var remainingFlight = new Flight(startDateForSecondFlight, endDateForSecondFlight, milesForSecondFlight);
            serviceLocator.AddFlight(flightToBook);
            serviceLocator.AddFlight(remainingFlight);

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

            var target = new User("Sriram");
            target.book(flightToBook);

            Assert.AreEqual(1, ServiceLocator.Instance.AvailableFlights.Count);
            Assert.AreSame(remainingFlight, ServiceLocator.Instance.AvailableFlights[0]);
        }
Пример #16
0
        public void TestThatUserDoesRemoveFlightFromServiceLocatorWhenBooked()
        {
            ServiceLocator serviceLocator = new ServiceLocator();
            DateTime startDate1 = new DateTime(2012, 11, 1);
            DateTime endDate1 = new DateTime(2012, 11, 4);

            DateTime startDate2 = new DateTime(2013, 5, 12);
            DateTime endDate2 = new DateTime(2013, 5, 28);

            var flightToBook = new Flight(startDate1, endDate1, 5000);
            var remainingFlight= new Flight(startDate2, endDate2, 8000);
            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(serviceLocator.AvailableFlights.Count, 1);
            Assert.AreSame(remainingFlight, serviceLocator.AvailableFlights[0]);
        }
Пример #17
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);
        }
Пример #18
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]);
 }
Пример #19
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]);
 }