Ejemplo n.º 1
0
        public void OverridingPropertyTest()
        {
            Assert.True(typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(POCOViewModel)));
            Assert.True(typeof(ISupportParentViewModel).IsAssignableFrom(typeof(POCOViewModel)));
            Assert.False(typeof(IPOCOViewModel).IsAssignableFrom(typeof(POCOViewModel)));
            Assert.False(typeof(IDataErrorInfo).IsAssignableFrom(typeof(POCOViewModel)));
            var viewModel = POCOViewModel.Create();

            Assert.Equal(viewModel.GetType(), viewModel.GetType().GetProperty("Property1").DeclaringType);

            CheckBindableProperty(viewModel, x => x.Property1, (vm, x) => vm.Property1 = x, "x", "y");
            CheckBindableProperty(viewModel, x => x.Property2, (vm, x) => vm.Property2 = x, "m", "n");
            CheckBindableProperty(viewModel, x => x.Property3, (vm, x) => vm.Property3 = x, "a", "b");
            CheckBindableProperty(viewModel, x => x.Property4, (vm, x) => vm.Property4 = x, 1, 2);
            CheckBindableProperty(viewModel, x => x.Property5, (vm, x) => vm.Property5 = x, new Point(1, 1), new Point(2, 2));
            CheckBindableProperty(viewModel, x => x.Property6, (vm, x) => vm.Property6 = x, 5, null);
            CheckBindableProperty(viewModel, x => x.ProtectedSetterProperty, (vm, x) => vm.SetProtectedSetterProperty(x), "x", "y");
            Assert.Null(viewModel.GetType().GetProperty("ProtectedSetterProperty").GetSetMethod());
            CheckBindableProperty(viewModel, x => x.ProtectedInternalSetterProperty, (vm, x) => vm.ProtectedInternalSetterProperty = x, "x", "y");
            Assert.Null(viewModel.GetType().GetProperty("ProtectedInternalSetterProperty").GetSetMethod());
            CheckBindableProperty(viewModel, x => x.InternalSetterProperty, (vm, x) => vm.InternalSetterProperty = x, "x", "y");

            CheckNotBindableProperty(viewModel, x => x.NotVirtualProperty, (vm, x) => vm.NotVirtualProperty = x, "x", "y");
            CheckNotBindableProperty(viewModel, x => x.NotVirtualPropertyWithPrivateSetter, (vm, x) => vm.NotVirtualPropertyWithPrivateSetter = x, "x", "y");
            CheckNotBindableProperty(viewModel, x => x.NotPublicProperty, (vm, x) => vm.NotPublicProperty                   = x, "x", "y");
            CheckNotBindableProperty(viewModel, x => x.ProtectedGetterProperty, (vm, x) => vm.ProtectedGetterProperty       = x, "x", "y");
            CheckNotBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");
        }
Ejemplo n.º 2
0
        public void GetSetParentViewModel()
        {
            var viewModel = POCOViewModel.Create();

            Assert.Null(viewModel.GetParentViewModel <Type>());
            var type = GetType();

            Assert.Same(viewModel, viewModel.SetParentViewModel(type));
            Assert.Equal(type, viewModel.GetParentViewModel <Type>());
            Assert.Null(viewModel.OldParentViewModel);
            type = typeof(object);
            Assert.Same(viewModel, viewModel.SetParentViewModel(type));
            Assert.Equal(type, viewModel.GetParentViewModel <Type>());
            Assert.Same(GetType(), viewModel.OldParentViewModel);
        }
Ejemplo n.º 3
0
        public void RaisePropertyChangedImplementation()
        {
            var    viewModel    = POCOViewModel.Create();
            string propertyName = null;

            ((INotifyPropertyChanged)viewModel).PropertyChanged += (o, e) => propertyName = e.PropertyName;
            viewModel.RaisePropertyChangedInternal(x => x.Property1);
            Assert.Equal("Property1", propertyName);

            viewModel.RaisePropertyChangedInternal(x => x.Property5);
            Assert.Equal("Property5", propertyName);

            viewModel.RaisePropertiesChanged();
            Assert.Equal(string.Empty, propertyName);

            viewModel.RaisePropertyChanged(x => x.Property1);
            Assert.Equal("Property1", propertyName);
        }
Ejemplo n.º 4
0
 public void SupportServicesPOCOModel()
 {
     CheckServicesImplementation(POCOViewModel.Create());
 }