[Test] public void SetBaseTypeChangesTheBaseTypeOfGeneratedProxy() { Factory.Reset(true); NotifyPropertyChangeFactory.SetBaseType <GoodBaseDifferentRaiser>("FirePropertyChanged"); VerifyProxyIsBaseType <GoodBaseDifferentRaiser>(); Factory.Reset(true); NotifyPropertyChangeFactory.SetBaseType <GoodBase>(); VerifyProxyIsBaseType <GoodBase>(); }
[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)); }
[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)); }
[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"))); }
[Test] public void SetBaseTypeChokesOnTypeDoesNotImplementINotifyPropertyChanged() { var e = Assert.Throws <ArgumentException>(() => NotifyPropertyChangeFactory.SetBaseType(typeof(NotNotifyPropertyChanged), "")); Assert.That(e.ParamName, Is.EqualTo("baseType")); }
[Test] public void SetBaseTypeChokesOnMoreThenOneOpenGenericTypeParameters() { var e = Assert.Throws <ArgumentException>(() => NotifyPropertyChangeFactory.SetBaseType(typeof(NotifyPropertyChangeBase <,>))); Assert.That(e.ParamName, Is.EqualTo("baseType")); }
[Test] public void SetBaseTypeChokesOnNullOnPropertyChangedMethod() { var e = Assert.Throws <ArgumentNullException>(() => NotifyPropertyChangeFactory.SetBaseType <GoodBase>(null)); Assert.That(e.ParamName, Is.EqualTo("onPropertyChangedMethod")); }
[Test] public void SetBaseTypeChokesOnNullBaseType() { var e = Assert.Throws <ArgumentNullException>(() => NotifyPropertyChangeFactory.SetBaseType(null, "")); Assert.That(e.ParamName, Is.EqualTo("baseType")); }