Esempio n. 1
0
 public void RegisteringNullAssemblyThrows()
 {
     AssertExtensions.AssertException <ArgumentException>(() =>
     {
         AllClasses.FromAssemblies(true, typeof(object).GetTypeInfo().Assembly, (Assembly)null);
     });
 }
Esempio n. 2
0
 public void CreatingInjectionParameterWithNullValueThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         new InjectionParameter(null);
     });
 }
Esempio n. 3
0
 public void RegisteringNullAssembliesListThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         AllClasses.FromAssemblies(null, true);
     });
 }
        public void OverridingNewMappingWithDifferentMappingThrowsByDefault()
        {
            var container = new UnityContainer();

            AssertExtensions.AssertException <DuplicateTypeMappingException>(
                () => container.RegisterTypes(new[] { typeof(string), typeof(int) }, t => new[] { typeof(object) }));
        }
 public void CreatingATypeOverrideForANullOverrideThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         new TypeBasedOverride(typeof(object), null);
     });
 }
 public void CreatingATypeOverrideForANullTypeThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         new TypeBasedOverride(null, new PropertyOverride("ignored", 10));
     });
 }
 public void CreatingAPropertyOverrideForANullValueThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         new PropertyOverride("ignored", null);
     });
 }
Esempio n. 8
0
 public void RegisteringNullAssembliesArrayThrows()
 {
     AssertExtensions.AssertException <ArgumentNullException>(() =>
     {
         AllClasses.FromAssemblies(true, (Assembly[])null);
     });
 }
Esempio n. 9
0
 public void Then_ConstructorsThatDoNotMatchThrowAnException()
 {
     AssertExtensions.AssertException <InvalidOperationException>(() =>
     {
         section.Configure(container, "invalidConstructor");
     });
 }
        public void ResovingObjectWithPrivateSetterGivesUsefulException()
        {
            IUnityContainer container = new UnityContainer();

            AssertExtensions.AssertException <ResolutionFailedException>(
                () => { container.Resolve <ObjectWithPrivateSetter>(); },
                (e) => { AssertExtensions.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException)); });
        }
Esempio n. 11
0
 public void CannotConfigureMethodWithOutParams()
 {
     AssertExtensions.AssertException <InvalidOperationException>(() =>
     {
         new UnityContainer().RegisterType <OutParams>(
             new InjectionMethod("InjectMe", 12));
     });
 }
Esempio n. 12
0
        public void InjectionConstructorThrowsIfNoMatchingConstructor()
        {
            InjectionConstructor ctor = new InjectionConstructor(typeof(double));
            var context = new MockBuilderContext();

            AssertExtensions.AssertException <InvalidOperationException>(
                () => ctor.AddPolicies(typeof(GuineaPig), context.PersistentPolicies));
        }
        public void ResolvingOpenGenericGivesInnerInvalidOperationException()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(List <>), new InjectionConstructor(10));

            AssertExtensions.AssertException <ResolutionFailedException>(
                () => { container.Resolve(typeof(List <>)); },
                (e) => { AssertExtensions.IsInstanceOfType(e.InnerException, typeof(ArgumentException)); });
        }
Esempio n. 14
0
        public void OverridingExistingMappingWithDifferentMappingThrowsByDefault()
        {
            var container = new UnityContainer();

            container.RegisterType <object, string>();

            AssertExtensions.AssertException <global::Unity.RegistrationByConvention.Exceptions.DuplicateTypeMappingException>(
                () => container.RegisterTypes(new[] { typeof(int) }, t => new[] { typeof(object) }));
        }
Esempio n. 15
0
 public void CannotConfigureGenericInjectionMethod()
 {
     AssertExtensions.AssertException <InvalidOperationException>(() =>
     {
         new UnityContainer()
         .RegisterType <OpenGenericInjectionMethod>(
             new InjectionMethod("InjectMe"));
     });
 }
 public void ContainerThrowsWhenConfiguringStaticMethodForInjection()
 {
     AssertExtensions.AssertException <InvalidOperationException>(() =>
     {
         IUnityContainer container = new UnityContainer()
                                     .RegisterType <GuineaPig>(
             new InjectionMethod("ShouldntBeCalled"));
     });
 }
        public void ShouldThrowIfAttemptsToResolveUnregisteredInterface()
        {
            IUnityContainer container = new UnityContainer();

            AssertExtensions.AssertException <ResolutionFailedException>(() =>
            {
                container.Resolve <ILogger>();
            });
        }
        public void GetReasonableExceptionWhenRegisteringNullInstance()
        {
            IUnityContainer container = new UnityContainer();

            AssertExtensions.AssertException <ArgumentNullException>(() =>
            {
                container.RegisterInstance <SomeType>(null);
            });
        }
 public void AppropriateExceptionIsThrownWhenNoMatchingConstructorCanBeFound()
 {
     AssertExtensions.AssertException <InvalidOperationException>(() =>
     {
         new UnityContainer()
         .RegisterType(typeof(ClassWithOneGenericParameter <>),
                       new InjectionConstructor(new GenericResolvedArrayParameter("T")));
     });
 }
Esempio n. 20
0
        public void RegisterTypeThrowsIfTypeIsNull()
        {
            IUnityContainer container = new UnityContainer();

            AssertExtensions.AssertException <ArgumentNullException>(() =>
            {
                container.RegisterType(null);
            });
        }
Esempio n. 21
0
        public void ConfiguringInjectionConstructorThatDoesNotExistThrows()
        {
            IUnityContainer container = new UnityContainer();

            AssertExtensions.AssertException <InvalidOperationException>(() =>
            {
                container.RegisterType <GuineaPig>(
                    new InjectionConstructor(typeof(string), typeof(string)));
            });
        }
Esempio n. 22
0
        public void RegisteringTheSameLifetimeManagerTwiceThrows()
        {
            LifetimeManager singleton = new ContainerControlledLifetimeManager();

            AssertExtensions.AssertException <InvalidOperationException>(() =>
            {
                GetContainer()
                .RegisterType <IService, Service>(singleton)
                .RegisterType <IService, OtherService>("special", singleton);
            });
        }
Esempio n. 23
0
        public void AccessViolationExceptionOnx64()
        {
            var container1 = new UnityContainer();

            container1.RegisterType <InnerX64Class>();
            // SomeProperty is static, this should throw here
            AssertExtensions.AssertException <InvalidOperationException>(() =>
            {
                container1.RegisterType <OuterX64Class>(new InjectionProperty("SomeProperty"));
            });
        }
        public void RegisteringTheSameLifetimeManagerTwiceThrows()
        {
            LifetimeManager singleton = new ContainerControlledLifetimeManager();

            AssertExtensions.AssertException <InvalidOperationException>(() =>
            {
                new UnityContainer()
                .RegisterType <ILogger, MockLogger>(singleton)
                .RegisterType <ILogger, SpecialLogger>("special", singleton);
            });
        }
Esempio n. 25
0
        public void CreatingResolvedArrayParameterWithValuesOfNonCompatibleType()
        {
            ILogger logger2 = new SpecialLogger();

            AssertExtensions.AssertException <InvalidOperationException>(() =>
            {
                new ResolvedArrayParameter <ILogger>(
                    new ResolvedParameter <ILogger>("log1"),
                    typeof(int),
                    logger2);
            });
        }
Esempio n. 26
0
        public void ResolvingOpenGenericWithConstructorParameterAmbiguityThrows()
        {
            var container = new UnityContainer();

            container.RegisterType(
                typeof(GenericTypeWithMultipleGenericTypeParameters <,>),
                new InjectionConstructor(new GenericParameter("T", "instance")));
            container.RegisterInstance("instance", "the string");

            AssertExtensions.AssertException <ResolutionFailedException>(
                () => container.Resolve <GenericTypeWithMultipleGenericTypeParameters <string, string> >(),
                e => { });
        }
Esempio n. 27
0
        public void Then_DeserializingWithParametersAndValueChildrenThrows()
        {
            var elementXml = @"
                <param name=""connectionString"" value=""northwind2"">
                    <value value=""northwind"" />
                </param>";

            var reader  = new XmlTextReader(new StringReader(elementXml));
            var result  = reader.MoveToContent();
            var element = new ParameterElement();

            AssertExtensions.AssertException <ConfigurationErrorsException>(() =>
            {
                element.Deserialize(reader);
            });
        }
Esempio n. 28
0
        public void ResolvingOpenGenericWithMethodAmbiguityThrows()
        {
            var container = new UnityContainer();

            container.RegisterType(
                typeof(GenericTypeWithMultipleGenericTypeParameters <,>),
                new InjectionMethod("Set", new GenericParameter("T", "instance")));
            container.RegisterInstance("instance", "the string");

            //// equivalent to doing the following, which would be rejected by the compiler
            //new GenericTypeWithMultipleGenericTypeParameters<string, string>().Set(container.Resolve<string>("instance"));

            AssertExtensions.AssertException <ResolutionFailedException>(
                () => container.Resolve <GenericTypeWithMultipleGenericTypeParameters <string, string> >(),
                e => { });
        }
Esempio n. 29
0
        public void Then_DeserializingMultipleInjectionValueChildrenThrows()
        {
            var elementXml = @"
                <property name=""connectionString"">
                    <value value=""northwind"" />
                    <value value=""northwind"" />
                </property>";

            var reader  = new XmlTextReader(new StringReader(elementXml));
            var result  = reader.MoveToContent();
            var element = new PropertyElement();

            AssertExtensions.AssertException <ConfigurationErrorsException>(() =>
            {
                element.Deserialize(reader);
            });
        }
Esempio n. 30
0
 public void GettigTypesFromAssembliesLoadedFromApplicationFolderWithoutSkippingErrorsThrows()
 {
     AssertExtensions.AssertException <AggregateException>(
         () => AllClasses.FromApplication(skipOnError: false),
         ae => Assert.IsTrue(ae.InnerException is BadImageFormatException || ae.InnerException is System.IO.FileNotFoundException));
 }