public void EventBinderBindsToImplicitEvent() { var input = new Button(); var fixture = new CreatesCommandBindingViaEvent(); var cmd = ReactiveCommand.Create <int>(_ => { }); Assert.True(fixture.GetAffinityForObject(input.GetType(), false) > 0); var invokeCount = 0; cmd.Subscribe(_ => invokeCount += 1); var disp = fixture.BindCommandToObject(cmd, input, Observable.Return((object)5)); Assert.NotNull(disp); Assert.Equal(0, invokeCount); var automationPeer = new ButtonAutomationPeer(input); var invoker = (IInvokeProvider)automationPeer.GetPattern(PatternInterface.Invoke); invoker.Invoke(); DispatcherUtilities.DoEvents(); Assert.Equal(1, invokeCount); disp?.Dispose(); invoker.Invoke(); Assert.Equal(1, invokeCount); }
public void EventBinderBindsToExplicitEvent() { var input = new TestFixture(); var fixture = new CreatesCommandBindingViaEvent(); var wasCalled = false; var cmd = ReactiveCommand.Create <int>(x => wasCalled = true); Assert.True(fixture.GetAffinityForObject(input.GetType(), true) > 0); Assert.False(fixture.GetAffinityForObject(input.GetType(), false) > 0); var disposable = fixture.BindCommandToObject <PropertyChangedEventArgs>(cmd, input, Observable.Return((object)5), "PropertyChanged"); input.IsNotNullString = "Foo"; Assert.True(wasCalled); wasCalled = false; disposable.Dispose(); input.IsNotNullString = "Bar"; Assert.False(wasCalled); }
public void EventBinderBindsToExplicitEvent() { var input = new NonReactiveINPCObjectMadeReactive(); var fixture = new CreatesCommandBindingViaEvent(); var cmd = new ReactiveCommand(); Assert.True(fixture.GetAffinityForObject(input.GetType(), true) > 0); Assert.False(fixture.GetAffinityForObject(input.GetType(), false) > 0); bool wasCalled = false; cmd.Subscribe(_ => wasCalled = true); var disp = fixture.BindCommandToObject <PropertyChangedEventArgs>(cmd, input, Observable.Return((object)5), "PropertyChanged"); input.InpcProperty = new TestFixture(); Assert.True(wasCalled); wasCalled = false; disp.Dispose(); input.InpcProperty = new TestFixture(); Assert.False(wasCalled); }
public void EventBinderBindsToImplicitEvent() { var input = new Button(); var fixture = new CreatesCommandBindingViaEvent(); var cmd = new ReactiveCommand(); Assert.True(fixture.GetAffinityForObject(input.GetType(), false) > 0); int invokeCount = 0; cmd.Subscribe(_ => invokeCount += 1); var disp = fixture.BindCommandToObject(cmd, input, Observable.Return((object)5)); Assert.NotNull(disp); Assert.Equal(0, invokeCount); input.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); Assert.Equal(1, invokeCount); disp.Dispose(); input.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); Assert.Equal(1, invokeCount); }