Esempio n. 1
0
        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>());
        }
Esempio n. 2
0
        public void ReferringToNestedClass()
        {
            var needs = new Needs().ReferChildren(typeof(ParentClass));

            Assert.IsInstanceOf <ParentClass.ImplementationX>(needs.Get <IInterfaceX>());
            Assert.IsInstanceOf <ParentClass.ImplementationY>(needs.Get <IInterfaceY>());
        }
Esempio n. 3
0
            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);
            }
Esempio n. 4
0
            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());
            }
Esempio n. 5
0
        public void DeferringToAnotherNeeds()
        {
            var needs0 = new Needs().Add <ISomeInterface>(new SomeImplementation());
            var needs1 = new Needs().Defer(needs0);

            Assert.IsInstanceOf <SomeImplementation>(needs1.Get <ISomeInterface>());
        }
Esempio n. 6
0
        public void ImplementationNotAvailableInDeferredNeeds()
        {
            var needs0 = new Needs();
            var needs1 = new Needs().Defer(needs0);

            Expect.Error <ImplementationUnresolvedException>(() => needs1.Get <ISomeInterface>());
        }
Esempio n. 7
0
        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>());
        }
Esempio n. 8
0
        public void DeferringToArbitraryBackup()
        {
            var needs = new Needs().Defer(_ => new SomeImplementation());

            Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>());
        }
Esempio n. 9
0
        public void AddingImplementingTypeAsTypeParameter()
        {
            var needs = new Needs().Add <ISomeInterface>(typeof(SomeImplementation));

            Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>());
        }
Esempio n. 10
0
        public void AddingInstance()
        {
            var needs = new Needs().Add <ISomeInterface>(new SomeImplementation());

            Assert.IsInstanceOf <SomeImplementation>(needs.Get <ISomeInterface>());
        }
Esempio n. 11
0
        public void ImplementationWithMultipleConstructors()
        {
            var needs = new Needs().ReferChildren(typeof(DependencyInjection));

            Expect.Error <MultipleConstructorsException>(() => needs.Get <IBlahInterface>());
        }
Esempio n. 12
0
        public void MultiUseCantDependOnSingleUse()
        {
            var needs = new Needs().ReferChildren(typeof(DependencyInjection));

            Expect.Error <ImplementationReliabilityException>(() => needs.Get <IAnotherInterface>());
        }
Esempio n. 13
0
        public void ImplementationNotAvailable()
        {
            var needs = new Needs();

            Expect.Error <ImplementationUnresolvedException>(() => needs.Get <ISomeInterface>());
        }
Esempio n. 14
0
 public void NoImplAvailable()
 {
     var needs = new Needs();
     Expect.None(needs.Get<IOtherInterface>());
 }
Esempio n. 15
0
 public void MultipleDefaultImplsLookup()
 {
     var needs = new Needs();
     Expect.Error(() => needs.Get<IMyInterface>());
 }
Esempio n. 16
0
 public void DefaultImplOfLookup()
 {
     var needs = new Needs();
     var thing = needs.Get<ISomeInterface>().OrElseThrow(() => new Exception("No impl found"));
     Assert.IsInstanceOf<SomeImplementation>(thing);
 }