Esempio n. 1
0
        public void WithFailUnregisteredResolutionActions_FailResolveContainer()
        {
            var container = new DependencyContainer();

            var resolveOptions = new DependencyContainerResolveOptions
            {
                UnregisteredResolutionAction = DependencyContainerUnregisteredResolutionActions.Fail
            };

            Assert.IsFalse(container.CanResolve <Shark>(parameters: new Dictionary <string, object>(), options: resolveOptions));
        }
Esempio n. 2
0
        public void WithInstanceAndRegister_ResolveContainer(string registerName, string resolveName)
        {
            var container = new DependencyContainer();

            var resolveOptions = new DependencyContainerResolveOptions
            {
                NamedResolutionFailureAction = DependencyContainerNamedResolutionFailureActions.AttemptUnnamedResolution
            };

            container.Register <IAnimal>(new Human("George"), registerName);

            Assert.IsTrue(container.CanResolve <IAnimal>(resolveName, null, resolveOptions));
        }
Esempio n. 3
0
        public void WithRegisterAndAttemptUnnamedResolution_ResolveContainer()
        {
            var container = new DependencyContainer();

            container.Register(typeof(Shark));

            var resolveOptions = new DependencyContainerResolveOptions
            {
                NamedResolutionFailureAction = DependencyContainerNamedResolutionFailureActions.AttemptUnnamedResolution,
            };

            Assert.IsTrue(container.CanResolve(typeof(Shark), new Shark().Name, resolveOptions));
        }
Esempio n. 4
0
        public void WithRegisterAndAttemptUnnamedResolution_ResolveContainer()
        {
            var container = new DependencyContainer();

            container.Register(typeof(Shark));

            var resolveOptions = new DependencyContainerResolveOptions
            {
                NamedResolutionFailureAction = DependencyContainerNamedResolutionFailureActions.AttemptUnnamedResolution
            };

            Assert.IsNotNull(container.Resolve(
                                 typeof(Shark), new Shark().GetName(), new Dictionary <string, object>(), resolveOptions));
        }
Esempio n. 5
0
        public void WithInvalidTypeAndAttemptUnnamedResolution_ThrowsDependencyContainerResolutionException()
        {
            var container = new DependencyContainer();

            container.Register(typeof(Human));

            var resolveOptions = new DependencyContainerResolveOptions
            {
                NamedResolutionFailureAction = DependencyContainerNamedResolutionFailureActions.AttemptUnnamedResolution
            };

            Assert.Throws <DependencyContainerResolutionException>(() =>
                                                                   container.Resolve(typeof(Human), "B. B. King", new Dictionary <string, object>(), resolveOptions));
        }