コード例 #1
0
 [Test] public void SetBaseTypeChangesTheBaseTypeOfGeneratedProxy()
 {
     Factory.Reset(true);
     NotifyPropertyChangeFactory.SetBaseType <GoodBaseDifferentRaiser>("FirePropertyChanged");
     VerifyProxyIsBaseType <GoodBaseDifferentRaiser>();
     Factory.Reset(true);
     NotifyPropertyChangeFactory.SetBaseType <GoodBase>();
     VerifyProxyIsBaseType <GoodBase>();
 }
コード例 #2
0
        [Test] public void SetBaseTypeChokesONonExistentOnPropertyChangedMethod()
        {
            var e = Assert.Throws <ArgumentException>(NotifyPropertyChangeFactory.SetBaseType <NoOnPropertyChangedMethod>);

            Assert.That(e.Message, Is.StringContaining(NotifyPropertyChangeFactory.DefaultOnPropertyChangedMethodName));
            const string expected = "Anything";

            e = Assert.Throws <ArgumentException>(() => NotifyPropertyChangeFactory.SetBaseType <GoodBase>(expected));
            Assert.That(e.Message, Is.StringContaining(expected));
        }
コード例 #3
0
        [Test] public void ProxyImplementsGenericTargetProperty()
        {
            Factory.Reset(true);
            NotifyPropertyChangeFactory.SetBaseType(typeof(NotifyPropertyChangeBase <>));
            var mock  = MockRepository.GenerateStub <IFoo>();
            var proxy = NotifyPropertyChangeFactory.GetProxy(mock);

            Assert.That(proxy, Is.InstanceOf <NotifyPropertyChangeBase <IFoo> >());
            Assert.That(((NotifyPropertyChangeBase <IFoo>)proxy).Target, Is.SameAs(mock));
        }
コード例 #4
0
        [Test] public void SetEventRaiserAttributeAllowsChangingRaiser()
        {
            Factory.Reset(true);
            NotifyPropertyChangeFactory.SetBaseType <GoodBase>();
            NotifyPropertyChangeFactory.SetEventRaiserAttribute <RaiserAttribute>(a => a.OnPropertyChanged);
            var handler  = MockRepository.GenerateStub <PropertyChangedEventHandler>();
            var bar      = MockRepository.GenerateStub <IBar>();
            var barProxy = NotifyPropertyChangeFactory.GetProxy(bar);

            Assert.That(barProxy, Is.InstanceOf <GoodBase>());
            ((INotifyPropertyChanged)barProxy).PropertyChanged += handler;
            barProxy.LongProperty = 100;
            handler.AssertWasCalled(x => x(Arg <object> .Is.Same(barProxy),
                                           Arg <PropertyChangedEventArgs> .Matches(e => e.PropertyName == "LongProperty Raised")));
        }
コード例 #5
0
        [Test] public void SetBaseTypeChokesOnTypeDoesNotImplementINotifyPropertyChanged()
        {
            var e = Assert.Throws <ArgumentException>(() => NotifyPropertyChangeFactory.SetBaseType(typeof(NotNotifyPropertyChanged), ""));

            Assert.That(e.ParamName, Is.EqualTo("baseType"));
        }
コード例 #6
0
        [Test] public void SetBaseTypeChokesOnMoreThenOneOpenGenericTypeParameters()
        {
            var e = Assert.Throws <ArgumentException>(() => NotifyPropertyChangeFactory.SetBaseType(typeof(NotifyPropertyChangeBase <,>)));

            Assert.That(e.ParamName, Is.EqualTo("baseType"));
        }
コード例 #7
0
        [Test] public void SetBaseTypeChokesOnNullOnPropertyChangedMethod()
        {
            var e = Assert.Throws <ArgumentNullException>(() => NotifyPropertyChangeFactory.SetBaseType <GoodBase>(null));

            Assert.That(e.ParamName, Is.EqualTo("onPropertyChangedMethod"));
        }
コード例 #8
0
        [Test] public void SetBaseTypeChokesOnNullBaseType()
        {
            var e = Assert.Throws <ArgumentNullException>(() => NotifyPropertyChangeFactory.SetBaseType(null, ""));

            Assert.That(e.ParamName, Is.EqualTo("baseType"));
        }