public void TestNotifyPropertyChanged() { var vm = new SourceFieldsViewModel(); TestsHelper.TestPropertyWithNotifyPropertyChanged(vm, () => vm.SelectedProviderField); TestsHelper.TestPropertyWithNotifyPropertyChanged(vm, () => vm.Model); TestsHelper.TestPropertyWithNotifyPropertyChanged(vm, () => vm.ParentWindow); }
public void OnCancel_Test() { var model = new ProviderFieldEditList { DataPortal.CreateChild<ProviderFieldEdit>(), DataPortal.CreateChild<ProviderFieldEdit>() }; var vm = new SourceFieldsViewModel { Model = model, SelectedProviderField = model.First() }; vm.OnCancel(); Assert.AreSame(model.FirstOrDefault(), vm.SelectedProviderField); }
public void Initialize_Test() { var model = new ProviderFieldEditList(); var parentMock = Mock.Create<ITopLevelWindow>(Behavior.CallOriginal); var vm = new SourceFieldsViewModel(); vm.Initialize(model, parentMock); Assert.AreSame(model, vm.Model); Assert.AreSame(parentMock, vm.ParentWindow); }
public void SetSourceFields_Test() { var model = new ProviderFieldEditList { DataPortal.CreateChild<ProviderFieldEdit>(), DataPortal.CreateChild<ProviderFieldEdit>() }; var vm = new SourceFieldsViewModel { Model = model, SelectedProviderField = model.First() }; Assert.AreEqual(2, vm.Model.Count); var providerFields = new List<ProviderFieldInfo> { new ProviderFieldInfo(1, "name1", "type1", ESyncSourceFieldIdentityTypes.Index), new ProviderFieldInfo(2, string.Empty, "type2", ESyncSourceFieldIdentityTypes.Index), new ProviderFieldInfo(3, null, "type3", ESyncSourceFieldIdentityTypes.Index) }; vm.SetSourceFields(new ProviderFieldInfoListMock(providerFields)); Assert.AreEqual(3, vm.Model.Count); }
public void RemoveFieldCommand_Test() { var model = new ProviderFieldEditList { DataPortal.CreateChild<ProviderFieldEdit>(), DataPortal.CreateChild<ProviderFieldEdit>(), DataPortal.CreateChild<ProviderFieldEdit>() }; var parentMock = Mock.Create<ITopLevelWindow>(Behavior.CallOriginal); Action onOk = null; var popupBuilderMock = Mock.Create<PopupBuilder>(Behavior.CallOriginal); Mock.Arrange(() => popupBuilderMock.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead<Action, Func<bool>>((ok, cancel) => { onOk = ok; }).Returns(popupBuilderMock); var popupFactoryMock = Mock.Create<PopupFactory>(Behavior.CallOriginal); Mock.Arrange(() => popupFactoryMock.Popup()).Returns(popupBuilderMock); var vm = new SourceFieldsViewModel { ThePopupFactory = popupFactoryMock }; vm.Initialize(model, parentMock); vm.SelectedProviderField = null; Assert.IsFalse(vm.RemoveFieldCommand.CanExecute(new object())); vm.SelectedProviderField = model.First(); Assert.IsTrue(vm.RemoveFieldCommand.CanExecute(new object())); Assert.AreEqual(3, vm.Model.Count); vm.RemoveFieldCommand.Execute(new object()); Assert.IsNotNull(onOk); onOk(); Assert.AreEqual(2, vm.Model.Count); }
public void AddFieldCommand_Test() { var model = new ProviderFieldEditList(); var parentMock = Mock.Create<ITopLevelWindow>(Behavior.CallOriginal); var vm = new SourceFieldsViewModel(); vm.Initialize(model, parentMock); Assert.AreEqual(0, vm.Model.Count); vm.AddFieldCommand.Execute(new object()); Assert.AreEqual(1, vm.Model.Count); Assert.AreSame(vm.Model.Last(), vm.SelectedProviderField); Assert.IsFalse(string.IsNullOrEmpty(vm.SelectedProviderField.Name)); Assert.IsFalse(string.IsNullOrEmpty(vm.SelectedProviderField.SystemName)); Assert.IsFalse(string.IsNullOrEmpty(vm.SelectedProviderField.Type)); }