public void ListHashSetPairs(IHashSet hashSet) { if (hashSet == null) { throw new ArgumentNullException(nameof(hashSet)); } IHashPair[] hashPairArray = null; //由于加载的哈希集可能较大,使用等待对话框; var loadingDialog = DialogService.Current.CreateLoadingDialog(); loadingDialog.IsProgressVisible = false; loadingDialog.WindowTitle = LanguageService.FindResourceString(Constants.WindowTitle_LoadingHashPairs); loadingDialog.DoWork += delegate { try { hashSet.BeginOpen(); hashPairArray = hashSet.GetAllHashPairs().ToArray(); } catch (Exception ex) { LoggerService.WriteException(ex); } finally { hashSet.EndOpen(); } }; loadingDialog.RunWorkerCompleted += delegate { if (hashPairArray == null) { return; } var window = new ListHashValuesDialog(); var vm = new ListHashValuesDialogViewModel(hashPairArray); window.DataContext = vm; if (ShellService.Current.Shell is Window shell && shell.IsLoaded) { window.ShowInTaskbar = false; window.Owner = shell; } window.ShowDialog(); window.DataContext = null; #if DEBUG for (int i = 0; i < 2; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } #endif }; loadingDialog.ShowDialog(); }
public void AddHashPairTest() { //查看在BeginEdit前进行调用是否会抛出异常; var ex = Assert.ThrowsException <InvalidOperationException>(() => { AddHashPairTestCore(); }); Assert.IsNotNull(ex); _hashSet.BeginEdit(); _hashSet.Clear(); AddHashPairTestCore(); _hashSet.EndEdit(); _hashSet.BeginOpen(); var allPairs = _hashSet.GetAllHashPairs(); Assert.AreEqual(allPairs.Count(), 1); Assert.IsNotNull(allPairs.FirstOrDefault(p => p.Name == TestName)); _hashSet.EndOpen(); }