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 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); }