Beispiel #1
0
        public void RegisterInstance_ShouldNotThrowIfTryingToRegisterTwiceForTheSameInterfaceAndImplementation()
        {
            //---------------Set up test pack-------------------
            var container = new WindsorContainer();
            var instance  = new DependencyForSingleInstance();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            container.RegisterInstance <IDependencyForSingleInstance>(instance);

            Expect(() =>
                   container.RegisterInstance <IDependencyForSingleInstance>(instance)
                   )
            .To.Throw <ComponentRegistrationException>();
            //---------------Test Result -----------------------
        }
Beispiel #2
0
        public void RegisterInstance_ShouldRegisterSingleProvidedInstanceForResolution()
        {
            //---------------Set up test pack-------------------
            var container = new WindsorContainer();
            var instance  = new DependencyForSingleInstance();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            container.RegisterInstance <IDependencyForSingleInstance>(instance);
            var result1 = container.Resolve <IDependencyForSingleInstance>();
            var result2 = container.Resolve <IDependencyForSingleInstance>();

            //---------------Test Result -----------------------
            Expect(result1).Not.To.Be.Null();
            Expect(result2).Not.To.Be.Null();
            Expect(result1).To.Equal(result2);
            Expect(result1).To.Equal(instance);
            Expect(result2).To.Equal(instance);
        }
Beispiel #3
0
        RegisterInstance_ShouldRegisterSingleProvidedInstanceForResolutionOnMultipleAttemptsWithDifferentInterface()
        {
            //---------------Set up test pack-------------------
            var container = new WindsorContainer();
            var instance  = new DependencyForSingleInstance();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            container.RegisterInstance <IDependencyForSingleInstance>(instance);
            container.RegisterInstance <IDependencyForSingleInstanceBase>(instance);
            var result1 = container.Resolve <IDependencyForSingleInstance>();
            var result2 = container.Resolve <IDependencyForSingleInstanceBase>();

            //---------------Test Result -----------------------
            Expect(result1).Not.To.Be.Null();
            Expect(result2).Not.To.Be.Null();
            Expect(result1).To.Equal(result2 as IDependencyForSingleInstance);
            Expect(result1).To.Equal(instance);
            Expect(result2).To.Equal(instance);
        }