public void Constructors_NoSelection() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } // Act var vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); // Assert Assert.IsNull(vm.TableSelectionThreeState); }
public void SelectTables_Null([Values(true, false)] bool hasTables) { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); ITableInformationViewModel[] tt = null; if (hasTables) { tt = GetTestViewModels(); foreach (var table in tt) { table.IsSelected = false; vm.Tables.Add(table); } } // Act vm.SelectTables(null); // Assert if (hasTables) { CollectionAssert.AreEqual(tt, vm.Tables); Assert.IsTrue(vm.Tables.All(m => m.IsSelected == false)); } else { Assert.IsEmpty(vm.Tables); } }
public void GetResults_WithTables_PartialSelection() { // Arrange ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); mock.SetupGet(g => g.Columns).Returns(new ObservableCollection <IColumnInformationViewModel>()); return(mock.Object); } IColumnInformationViewModel CreateColumnInformationViewModelMockObject() { var mock = new Mock <IColumnInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModelMockObject, CreateColumnInformationViewModelMockObject); var tt = GetTestViewModels(); var c = tt.Select(m => new SerializationTableModel(m.Name, m.ObjectType, m.Columns.Select(co => co.Name))).ToArray(); foreach (var table in tt) { vm.Tables.Add(table); } // Act var result = vm.GetResult(); // Assert Assert.IsNotNull(result); Assert.AreEqual(5, result.Length); AreTableEqual(c[1], result[0], false); AreTableEqual(c[2], result[1], false); AreTableEqual(c[3], result[2], false); AreTableEqual(c[4], result[3], false); AreTableEqual(c[5], result[4], false); }
public void CancelCommand_Executed() { // Arrange var closeRequested = false; bool?dialogResult = null; var vm = new PickTablesViewModel(CreateObjectTreeViewModelMock().Object); vm.CloseRequested += (sender, args) => { closeRequested = true; dialogResult = args.DialogResult; }; // Act vm.CancelCommand.Execute(null); // Assert Assert.IsTrue(closeRequested); Assert.IsFalse(dialogResult); }
public void Constructors_CollectionsInitialized() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } // Act var vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); // Assert Assert.IsNotNull(vm.Tables); Assert.IsNotNull(vm.FilteredTables); }
public void SearchText_FilterAfterDelay() { // Arrange ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IColumnInformationViewModel CreateColumnInformationViewModelMockObject() { var mock = new Mock <IColumnInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModelMockObject, CreateColumnInformationViewModelMockObject); var tt = GetTestViewModels(); foreach (var table in tt) { vm.Tables.Add(table); } var preFilter = vm.FilteredTables.OfType <ITableInformationViewModel>().ToArray(); // Act vm.SearchText = "dbo"; // Assert Assert.AreEqual(tt.Length, preFilter.Length); Assert.That(() => { var postFilter = vm.FilteredTables.OfType <ITableInformationViewModel>().ToArray(); return(postFilter.Length < tt.Length && postFilter.All(m => m.Name.Contains("dbo"))); }, Is.True.After(1500, 200)); }
public void Update_TableSelectionThreeState_OnTableSelectionChanged_NoTablesSelected() { // Arrange // Test relies on PropertyChanged, so we rely on the real view model here ITableInformationViewModel CreateTableInformationViewModel() => new TableInformationViewModel(); IColumnInformationViewModel CreateColumnInformationViewModel() => new ColumnInformationViewModel(); IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModel, CreateColumnInformationViewModel); var tt = GetTestViewModels(); vm.AddTables(tt.Select(m => new TableModel(m.Name, m.HasPrimaryKey, m.ObjectType, new List <ColumnModel>()))); // Act foreach (var table in vm.Tables) { table.IsSelected = false; } // Assert Assert.IsFalse(vm.TableSelectionThreeState); }
public void AddTables_Null() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); // Act vm.AddTables(null); // Assert Assert.IsEmpty(vm.Tables); }
public void CancelCommand_Executed() { // Arrange var closeRequested = false; bool?dialogResult = null; var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } var vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); vm.CloseRequested += (sender, args) => { closeRequested = true; dialogResult = args.DialogResult; }; var tt = GetTestViewModels(); foreach (var tvm in tt) { vm.Tables.Add(tvm); } // Act vm.CancelCommand.Execute(null); // Assert Assert.IsTrue(closeRequested); Assert.IsFalse(dialogResult); Assert.IsEmpty(vm.Tables); }
public void CancelCommand_CanExecute() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } var vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); // Act var canExecute = vm.CancelCommand.CanExecute(null); // Assert Assert.IsTrue(canExecute); }
public void LoadedCommand_Executed() { // Arrange ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IColumnInformationViewModel CreateColumnInformationViewModelMockObject() { var mock = new Mock <IColumnInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } var vm = new PickTablesViewModel(CreateTableInformationViewModelMockObject, CreateColumnInformationViewModelMockObject); var tt = GetTestViewModels(); foreach (var tvm in tt) { vm.Tables.Add(tvm); } // Act vm.LoadedCommand.Execute(null); // Assert Assert.IsFalse(tt[0].IsSelected); Assert.IsFalse(tt[1].IsSelected); Assert.IsFalse(tt[2].IsSelected); Assert.IsFalse(tt[3].IsSelected); Assert.IsTrue(tt[4].IsSelected); Assert.IsTrue(tt[5].IsSelected); }
public void SearchText_NoDirectFilter() { // Arrange ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IColumnInformationViewModel CreateColumnInformationViewModelMockObject() { var mock = new Mock <IColumnInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModelMockObject, CreateColumnInformationViewModelMockObject); var tt = GetTestViewModels(); foreach (var table in tt) { vm.Tables.Add(table); } var preFilter = vm.FilteredTables.OfType <ITableInformationViewModel>().ToArray(); // Act vm.SearchText = "dbo"; // Assert Assert.AreEqual(tt.Length, preFilter.Length); var postFilter = vm.FilteredTables.OfType <ITableInformationViewModel>().ToArray(); Assert.AreEqual(tt.Length, postFilter.Length); }
public void GetResults_NoTables() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); // Act var result = vm.GetResult(); // Assert Assert.IsNotNull(result); Assert.IsEmpty(result); }
public void Update_TableSelectionThreeState_OnTableSelectionChanged_NoTablesSelected() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); // Test relies on PropertyChanged, so we rely on the real view model here ITableInformationViewModel CreateTableInformationViewModel() => new TableInformationViewModel(); IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModel); var tt = GetTestViewModels(); vm.AddTables(tt.Select(m => m.Model)); // Act foreach (var table in vm.Tables) { table.IsSelected = false; } // Assert Assert.IsFalse(vm.TableSelectionThreeState); }
public void Update_TableSelectionThreeState_OnCollectionChanged_UnselectedTable() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); var tt = GetTestViewModels(); // Act vm.Tables.Add(tt[0]); // Assert Assert.IsFalse(vm.TableSelectionThreeState); }
public void Update_TableSelectionThreeState_OnTableSelectionChanged_MixedTableSelection() { // Arrange // Test relies on PropertyChanged, so we rely on the real view model here ITableInformationViewModel CreateTableInformationViewModel() => new TableInformationViewModel(); IColumnInformationViewModel CreateColumnInformationViewModel() => new ColumnInformationViewModel(); IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModel, CreateColumnInformationViewModel); var tt = GetTestViewModels(); vm.AddTables(tt.Select(m => new TableModel(m.Name, m.HasPrimaryKey, m.ObjectType, m.Columns.Select(co => new ColumnModel(co.Name, true))))); // Act for (var i = 0; i < vm.Tables.Count; i++) { var table = vm.Tables[i]; table.IsSelected = i % 2 == 0; } // Assert Assert.IsNull(vm.TableSelectionThreeState); }
public void AddTables_Collection() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModelMockObject); var tt = GetTestViewModels(); var c = tt.Select(m => m.Model).ToArray(); // Act vm.AddTables(c); // Assert Assert.IsNotEmpty(vm.Tables); Assert.AreEqual(tt.Length, vm.Tables.Count); Assert.AreSame(tt[0].Model, vm.Tables[0].Model); Assert.IsFalse(vm.Tables[0].IsSelected); Assert.AreSame(tt[1].Model, vm.Tables[1].Model); Assert.IsFalse(vm.Tables[1].IsSelected); Assert.AreSame(tt[2].Model, vm.Tables[2].Model); Assert.IsFalse(vm.Tables[2].IsSelected); Assert.AreSame(tt[3].Model, vm.Tables[3].Model); Assert.IsFalse(vm.Tables[3].IsSelected); Assert.AreSame(tt[4].Model, vm.Tables[4].Model); Assert.IsFalse(vm.Tables[4].IsSelected); Assert.AreSame(tt[5].Model, vm.Tables[5].Model); Assert.IsFalse(vm.Tables[5].IsSelected); }
public void Update_TableSelectionThreeState_OnTableSelectionChanged_MixedTableSelection() { // Arrange var osa = Mock.Of <IOperatingSystemAccess>(); var fsa = Mock.Of <IFileSystemAccess>(); // Test relies on PropertyChanged, so we rely on the real view model here ITableInformationViewModel CreateTableInformationViewModel() => new TableInformationViewModel(); IPickTablesViewModel vm = new PickTablesViewModel(osa, fsa, CreateTableInformationViewModel); var tt = GetTestViewModels(); vm.AddTables(tt.Select(m => m.Model)); // Act for (var i = 0; i < vm.Tables.Count; i++) { var table = vm.Tables[i]; table.IsSelected = i % 2 == 0; } // Assert Assert.IsNull(vm.TableSelectionThreeState); }
public void TableSelectionThreeState_NullSelected() { // Arrange ITableInformationViewModel CreateTableInformationViewModelMockObject() { var mock = new Mock <ITableInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IColumnInformationViewModel CreateColumnInformationViewModelMockObject() { var mock = new Mock <IColumnInformationViewModel>(); mock.SetupAllProperties(); return(mock.Object); } IPickTablesViewModel vm = new PickTablesViewModel(CreateTableInformationViewModelMockObject, CreateColumnInformationViewModelMockObject); var tt = GetTestViewModels(); foreach (var table in tt) { vm.Tables.Add(table); } vm.SearchText = "foo"; // Act vm.TableSelectionThreeState = null; // Assert Assert.IsFalse(vm.Tables.All(m => m.IsSelected)); Assert.IsFalse(vm.Tables.All(m => !m.IsSelected)); Assert.AreEqual("foo", vm.SearchText); }