public void TestMethod4b() { var dependencyResolver = new Leos.DependencyResolver.DependencyResolver(new Logger()); dependencyResolver.Bind<IAnimal>().To<Dog>().When<AnimalType>().IsEqualTo(AnimalType.Dog); dependencyResolver.Bind<IAnimal>().To<Cat>().When<AnimalType>().IsEqualTo(AnimalType.Cat); var animalCage = new AnimalCage(); animalCage.AnimalType = AnimalType.Dog; dependencyResolver.ResolveDependencies(animalCage); Assert.IsTrue(animalCage.Animal is Dog); animalCage.GreetAnimal(); animalCage.AnimalType = AnimalType.Cat; dependencyResolver.ResolveDependencies(animalCage); Assert.IsTrue(animalCage.Animal is Cat); animalCage.GreetAnimal(); animalCage.AnimalType = AnimalType.Rabbit; try { dependencyResolver.ResolveDependencies(animalCage); } catch (ServiceNotFoundException) { // correct! There is no binding for IAnimal when 'AnimalType = Rabbit' } }
public void TestMethod2b() { var dependencyResolver = new Leos.DependencyResolver.DependencyResolver("DependencyResolverTests_Tutorial02b", new Logger()); var animalCage = new AnimalCage(); animalCage.AnimalType = AnimalType.Dog; dependencyResolver.ResolveDependencies(animalCage); Assert.IsTrue(animalCage.Animal is Dog); animalCage.GreetAnimal(); animalCage.AnimalType = AnimalType.Cat; dependencyResolver.ResolveDependencies(animalCage); Assert.IsTrue(animalCage.Animal is Cat); animalCage.GreetAnimal(); }
public void TestMethod1b() { var dependencyResolver = new Leos.DependencyResolver.DependencyResolver("DependencyResolverTests_Tutorial01b", new Logger()); var animalCage = new AnimalCage(); dependencyResolver.ResolveDependencies(animalCage); Assert.IsNotNull(animalCage.Animal, "Dependency could not be resolved"); animalCage.GreetAnimal(); }