示例#1
0
        public void IsValidContainer_InvalidContainer()
        {
            var helper = new UnityHelper();

            var container = new object();
            Assert.IsFalse(helper.IsValidContainer(container));
        }
示例#2
0
        public void IsValidContainer_ValidContainer()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            Assert.IsTrue(helper.IsValidContainer(container));
        }
示例#3
0
        public void GetRegistrationInfo_ContainerWithoutTypeRegistered()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            Assert.IsNull(helper.GetRegistrationInfo(container, typeof(ITestInterface)));
        }
示例#4
0
        public void GetRegistrationInfo_InterfaceTypeNull()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.GetRegistrationInfo(container, null));
        }
示例#5
0
        public void GetRegistrationInfo_InvalidContainer()
        {
            var helper = new UnityHelper();

            var container = new object();
            ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => helper.GetRegistrationInfo(container, typeof(ITestInterface)));
        }
示例#6
0
        public void GetRegistrationInfo_ContainerWithSingletonTypeRegistered()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            container.RegisterType<ITestInterface, TestClass1>(new ContainerControlledLifetimeManager());

            var registrationInfo = helper.GetRegistrationInfo(container, typeof(ITestInterface));

            Assert.AreEqual(typeof(ITestInterface), registrationInfo.DeclaringType);
            Assert.AreEqual(RegistrationType.Singleton, registrationInfo.RegistrationType);
        }
示例#7
0
        public void ResolveType_ContainerNull()
        {
            var helper = new UnityHelper();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.ResolveType(null, typeof(ITestInterface)));
        }
示例#8
0
        public void GetRegistrationInfo_ContainerNull()
        {
            var helper = new UnityHelper();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.GetRegistrationInfo(null, typeof(ITestInterface)));
        }
示例#9
0
        public void RegisterType_InvalidContainer()
        {
            var helper = new UnityHelper();

            var container = new object();
            ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => helper.RegisterType(container, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton));
        }
示例#10
0
        public void ResolveType_Transient()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            container.RegisterType<ITestInterface, TestClass1>(new TransientLifetimeManager());

            var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance1);
            Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1));

            var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance2);
            Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1));

            Assert.IsFalse(ReferenceEquals(resolvedInstance1, resolvedInstance2));
        }
示例#11
0
        public void RegisterType_Valid()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            Assert.IsFalse(container.IsRegistered(typeof(ITestInterface)));

            helper.RegisterType(container, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton);
            Assert.IsTrue(container.IsRegistered(typeof(ITestInterface)));
        }
示例#12
0
        public void ResolveType_ContainerWithoutTypeRegistered()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
示例#13
0
        public void RegisterInstance_ContainerNull()
        {
            var helper = new UnityHelper();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.RegisterInstance(null, typeof(ITestInterface), new TestClass1()));
        }
示例#14
0
        public void RegisterType_ImplementingTypeNull()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.RegisterType(container, typeof(ITestInterface), null, RegistrationType.Singleton));
        }
示例#15
0
        public void ResolveType_InvalidContainer()
        {
            var helper = new UnityHelper();

            var container = new object();
            ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
示例#16
0
        public void RegisterInstance_InterfaceTypeNull()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.RegisterInstance(container, null, new TestClass1()));
        }
示例#17
0
        public void RegisterInstance_Valid()
        {
            var helper = new UnityHelper();
            var instance = new TestClass1() { Name = "test" };

            var container = new UnityContainer();
            Assert.IsFalse(container.IsRegistered(typeof(ITestInterface)));

            helper.RegisterInstance(container, typeof(ITestInterface), instance);
            Assert.IsTrue(container.IsRegistered(typeof(ITestInterface)));
            Assert.AreEqual(instance, container.Resolve<ITestInterface>());
        }
示例#18
0
        public void RegisterInstance_InvalidContainer()
        {
            var helper = new UnityHelper();

            var container = new object();
            ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => helper.RegisterInstance(container, typeof(ITestInterface), new TestClass1()));
        }
示例#19
0
        public void RegisterInstance_InstanceNull()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.RegisterInstance(container, typeof(ITestInterface), null));
        }
示例#20
0
 public void IsValidContainer_Null()
 {
     var helper = new UnityHelper();
     
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.IsValidContainer(null));
 }
示例#21
0
        public void ResolveType_InterfaceTypeNull()
        {
            var helper = new UnityHelper();

            var container = new UnityContainer();
            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.ResolveType(container, null));
        }
示例#22
0
        public void RegisterType_ContainerNull()
        {
            var helper = new UnityHelper();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => helper.RegisterType(null, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton));
        }