public void ReferringToAssembly() { var needs = new Needs().Refer(typeof(DependencyInjection).Assembly); Assert.IsInstanceOf <ParentClass.ImplementationX>(needs.Get <IInterfaceX>()); Assert.IsInstanceOf <ParentClass.ImplementationY>(needs.Get <IInterfaceY>()); }
public void ReferringToNestedClass() { var needs = new Needs().ReferChildren(typeof(ParentClass)); Assert.IsInstanceOf <ParentClass.ImplementationX>(needs.Get <IInterfaceX>()); Assert.IsInstanceOf <ParentClass.ImplementationY>(needs.Get <IInterfaceY>()); }
public void ImplementationsCanBeDeterminedByNewType() { var needs = new Needs(); needs.Add(new PearVariant(new SomeImplementation())); needs.Add(new PlumVariant(new SomeImplementation())); Assert.AreNotEqual(needs.Get <PearVariant>().Value, needs.Get <PlumVariant>().Value); }
public void SimpleMultiUseDecoration() { var needs = new Needs(); needs.Add <IFacility, BasicFacility>(); Assert.AreEqual(1, needs.Get <IFacility>().Facilitate()); needs.Decorate <IFacility, AdvancedFacility>(); Assert.AreEqual(2, needs.Get <IFacility>().Facilitate()); // Decorator can be re-applied/re-wrapped multiple times needs.Decorate <IFacility, AdvancedFacility>(); Assert.AreEqual(3, needs.Get <IFacility>().Facilitate()); }
public void DeferringToAnotherNeeds() { var needs0 = new Needs().Add <ISomeInterface>(new SomeImplementation()); var needs1 = new Needs().Defer(needs0); Assert.IsInstanceOf <SomeImplementation>(needs1.Get <ISomeInterface>()); }
public void ImplementationNotAvailableInDeferredNeeds() { var needs0 = new Needs(); var needs1 = new Needs().Defer(needs0); Expect.Error <ImplementationUnresolvedException>(() => needs1.Get <ISomeInterface>()); }
public void LookupAllExplicit() { var x = new WS(); var y = new DbW(); var z = new DbR(); var w = new UI(); var needs = new Needs(); needs.Set<IWebService>(x); needs.Set<IDatabaseCommand>(y); needs.Set<IDatabaseQuery>(z); needs.Set<IUserInterface>(w); Expect.Some(z, needs.Get<IDatabaseQuery>()); Expect.Some(y, needs.Get<IDatabaseCommand>()); Expect.Some(w, needs.Get<IUserInterface>()); Expect.Some(x, needs.Get<IWebService>()); }
public void DeferringToArbitraryBackup() { var needs = new Needs().Defer(_ => new SomeImplementation()); Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>()); }
public void AddingImplementingTypeAsTypeParameter() { var needs = new Needs().Add <ISomeInterface>(typeof(SomeImplementation)); Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>()); }
public void AddingInstance() { var needs = new Needs().Add <ISomeInterface>(new SomeImplementation()); Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>()); }
public void ImplementationWithMultipleConstructors() { var needs = new Needs().ReferChildren(typeof(DependencyInjection)); Expect.Error <MultipleConstructorsException>(() => needs.Get <IBlahInterface>()); }
public void MultiUseCantDependOnSingleUse() { var needs = new Needs().ReferChildren(typeof(DependencyInjection)); Expect.Error <ImplementationReliabilityException>(() => needs.Get <IAnotherInterface>()); }
public void ImplementationNotAvailable() { var needs = new Needs(); Expect.Error <ImplementationUnresolvedException>(() => needs.Get <ISomeInterface>()); }
public void NoImplAvailable() { var needs = new Needs(); Expect.None(needs.Get<IOtherInterface>()); }
public void MultipleDefaultImplsLookup() { var needs = new Needs(); Expect.Error(() => needs.Get<IMyInterface>()); }
public void DefaultImplOfLookup() { var needs = new Needs(); var thing = needs.Get<ISomeInterface>().OrElseThrow(() => new Exception("No impl found")); Assert.IsInstanceOf<SomeImplementation>(thing); }