Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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]);
 }