示例#1
0
        public void GeneratedDerivedTypeIsCached()
        {
            IUnityContainer container =
                new UnityContainer()
                .AddNewExtension <Interception>()
                .RegisterType <ClassWithVirtualProperty>(new Interceptor <VirtualMethodInterceptor>());

            ClassWithVirtualProperty instanceOne = container.Resolve <ClassWithVirtualProperty>();
            ClassWithVirtualProperty instanceTwo = container.Resolve <ClassWithVirtualProperty>();

            Assert.AreSame(typeof(ClassWithVirtualProperty), instanceOne.GetType().BaseType);
            Assert.AreSame(instanceOne.GetType(), instanceTwo.GetType());
        }
示例#2
0
        public void CanAddInterceptionBehaviorsWithRequiredInterfaces()
        {
            IUnityContainer container =
                new UnityContainer()
                .AddNewExtension <Interception>()
                .RegisterType <ClassWithVirtualProperty>(
                    new Interceptor <VirtualMethodInterceptor>(),
                    new InterceptionBehavior(new NaiveINotifyPropertyChangedInterceptionBehavior()));

            ClassWithVirtualProperty instance = container.Resolve <ClassWithVirtualProperty>();

            string changedProperty = null;

            ((INotifyPropertyChanged)instance).PropertyChanged += (s, a) => changedProperty = a.PropertyName;

            instance.Property = 10;

            Assert.AreEqual("Property", changedProperty);
        }