コード例 #1
0
        public void WhenMappedToInterfacesInSameAssemblyIsNull()
        {
            IUnityContainer container = new UnityContainer();

            AssertHelper.ThrowsException <ArgumentNullException>(() => container.RegisterTypes(
                                                                     AllClasses.FromAssemblies(
                                                                         Assembly.Load(new AssemblyName(RegistrationByConventionAssembly1Name)),
                                                                         Assembly.Load(new AssemblyName(RegistrationByConventionAssembly2Name))),
                                                                     (t) => WithMappings.FromAllInterfacesInSameAssembly((null)),
                                                                     WithName.TypeName,
                                                                     WithLifetime.ContainerControlled));
        }
        public void GetsAllInterfacesInSameAssembly()
        {
            WithMappings.FromAllInterfacesInSameAssembly(typeof(TypeWithoutInterfaces)).AssertHasNoItems();
            WithMappings.FromAllInterfacesInSameAssembly(typeof(DisposableType)).AssertHasNoItems();
            WithMappings.FromAllInterfacesInSameAssembly(typeof(TestObject)).AssertContainsInAnyOrder(typeof(ITestObject), typeof(IAnotherInterface));
            WithMappings.FromAllInterfacesInSameAssembly(typeof(AnotherTestObject)).AssertContainsInAnyOrder(typeof(ITestObject), typeof(IAnotherInterface));

            // Generics
            WithMappings.FromAllInterfacesInSameAssembly(typeof(GenericTestObject <,>)).AssertContainsExactly(typeof(IGenericTestObject <,>));
            WithMappings.FromAllInterfacesInSameAssembly(typeof(GenericTestObjectAlt <,>)).AssertHasNoItems();
            WithMappings.FromAllInterfacesInSameAssembly(typeof(GenericTestObject <>)).AssertHasNoItems();
            WithMappings.FromAllInterfacesInSameAssembly(typeof(GenericTestObject)).AssertContainsExactly(typeof(IGenericTestObject <string, int>));
        }