Exemplo n.º 1
0
        public void CanBindViewModelToWinformControls()
        {
            var vm   = new FakeWinformViewModel();
            var view = new FakeWinformsView()
            {
                ViewModel = vm
            };

            vm.SomeText = "Foo";
            Assert.NotEqual(vm.SomeText, view.Property3.Text);

            var disp = view.Bind(vm, x => x.SomeText, x => x.Property3.Text);

            vm.SomeText = "Bar";
            Assert.Equal(vm.SomeText, view.Property3.Text);

            view.Property3.Text = "Bar2";
            Assert.Equal(vm.SomeText, view.Property3.Text);

            var disp2 = view.Bind(vm, x => x.SomeDouble, x => x.Property3.Text);

            vm.SomeDouble = 123.4;

            Assert.Equal(vm.SomeDouble.ToString(), view.Property3.Text);
        }
Exemplo n.º 2
0
        public void SmokeTestWinformControls()
        {
            var vm   = new FakeWinformViewModel();
            var view = new FakeWinformsView {
                ViewModel = vm
            };

            var disp = new CompositeDisposable(new[]
            {
                view.Bind(vm, x => x.Property1, x => x.Property1.Text),
                view.Bind(vm, x => x.Property2, x => x.Property2.Text),
                view.Bind(vm, x => x.Property3, x => x.Property3.Text),
                view.Bind(vm, x => x.Property4, x => x.Property4.Text),
                view.Bind(vm, x => x.BooleanProperty, x => x.BooleanProperty.Checked),
            });

            vm.Property1 = "FOOO";
            Assert.Equal(vm.Property1, view.Property1.Text);

            vm.Property2 = "FOOO1";
            Assert.Equal(vm.Property2, view.Property2.Text);

            vm.Property3 = "FOOO2";
            Assert.Equal(vm.Property3, view.Property3.Text);

            vm.Property4 = "FOOO3";
            Assert.Equal(vm.Property4, view.Property4.Text);

            vm.BooleanProperty = false;
            Assert.Equal(vm.BooleanProperty, view.BooleanProperty.Checked);
            vm.BooleanProperty = true;
            Assert.Equal(vm.BooleanProperty, view.BooleanProperty.Checked);

            disp.Dispose();
        }
Exemplo n.º 3
0
        public void CanAutoBindViewModelToWinformView()
        {
            var vm   = new FakeWinformViewModel();
            var view = new FakeWinformsView()
            {
                ViewModel = vm
            };

            vm.SomeDouble = 1234.4;
            Assert.NotEqual(vm.SomeDouble.ToString(), view.SomeDouble.Text);

            view.Bind(vm, x => x.SomeDouble);
            Assert.Equal(vm.SomeDouble.ToString(), view.SomeDouble.Text);

            view.SomeDouble.Text = (2347746.44).ToString();
            Assert.Equal(vm.SomeDouble.ToString(), view.SomeDouble.Text);
        }
Exemplo n.º 4
0
        public void ShouldDisposePreviousView()
        {
            var viewLocator = new FakeViewLocator {
                LocatorFunc = t => new FakeWinformsView()
            };
            var router = new RoutingState();
            var target = new WinFormsRoutedViewHost {
                Router = router, ViewLocator = viewLocator
            };

            router.Navigate.Execute(new FakeWinformViewModel());

            FakeWinformsView currentView = target.Controls.OfType <FakeWinformsView>().Single();
            bool             isDisposed  = false;

            currentView.Disposed += (o, e) => isDisposed = true;

            // switch the viewmodel
            router.Navigate.Execute(new FakeWinformViewModel());

            Assert.True(isDisposed);
        }