Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ContainsEmptyListOrNullTest sproadic failures #14946

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/GraphNodeManagerViewExtension/GraphNodeManagerView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Dynamo.GraphNodeManager.ViewModels;

Expand All @@ -8,7 +12,7 @@ namespace Dynamo.GraphNodeManager
/// <summary>
/// Interaction logic for GraphNodeManagerView.xaml
/// </summary>
public partial class GraphNodeManagerView : UserControl
public partial class GraphNodeManagerView : UserControl, IDisposable
{
/// <summary>
/// A persistent handle of the currently selected row
Expand All @@ -25,6 +29,9 @@ public partial class GraphNodeManagerView : UserControl
/// </summary>
private bool mouseHandled = false;

private GraphNodeManagerViewModel viewModel;
private bool disposedValue;

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -33,7 +40,38 @@ public GraphNodeManagerView(GraphNodeManagerViewModel viewModel)
{
InitializeComponent();

this.viewModel = viewModel;
this.DataContext = viewModel;

viewModel.PropertyChanged += ViewModel_OnPropertyChanged;
viewModel.RequestExportGraph += ViewModel_RequestExportGraph;
}

private void ViewModel_RequestExportGraph(object parameter)
{
if (parameter == null) return;
var type = parameter.ToString();
var promptName = System.IO.Path.GetFileNameWithoutExtension(viewModel.CurrentWorkspace.FileName);

var filteredNodes = NodesInfoDataGrid.ItemsSource.Cast<GridNodeViewModel>().ToArray();

switch (type)
{
case "CSV":
Utilities.Utilities.ExportToCSV(filteredNodes, promptName);
break;
case "JSON":
Utilities.Utilities.ExportToJson(filteredNodes, promptName);
break;
}
}

private void ViewModel_OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(GraphNodeManagerViewModel.IsAnyFilterOn))
{
CollectionViewSource.GetDefaultView(NodesInfoDataGrid.ItemsSource).Refresh();
}
}

/// <summary>
Expand Down Expand Up @@ -118,5 +156,22 @@ private void ExportButton_OnClick(object sender, RoutedEventArgs e)
e.Handled = true;
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
viewModel.PropertyChanged -= ViewModel_OnPropertyChanged;
viewModel.RequestExportGraph -= ViewModel_RequestExportGraph;

disposedValue = true;
}
}

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
16 changes: 6 additions & 10 deletions src/GraphNodeManagerViewExtension/GraphNodeManagerViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ private void MenuItemCheckHandler(object sender, RoutedEventArgs e)
{
AddToSidebar();
}

/// <summary>
/// Close the Extension
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuItemUnCheckedHandler(object sender, RoutedEventArgs e)
{
this.Dispose();
viewLoadedParamsReference.CloseExtensioninInSideBar(this);
}

Expand All @@ -80,16 +80,11 @@ private void MenuItemUnCheckedHandler(object sender, RoutedEventArgs e)
/// </summary>
private void AddToSidebar()
{
// Use late initialization for the GraphNodeManagerViewModel
this.ViewModel ??= new GraphNodeManagerViewModel(this.viewLoadedParamsReference, UniqueId, MessageLogged);
// initialise the ViewModel and View for the window
this.ViewModel = new GraphNodeManagerViewModel(this.viewLoadedParamsReference, UniqueId, MessageLogged);
this.ManagerView = new GraphNodeManagerView(this.ViewModel);

if (this.ManagerView == null)
{
return;
}

this.ViewModel.GraphNodeManagerView = this.ManagerView;
// Use late initialization for the GraphNodeManagerView
this.ManagerView ??= new GraphNodeManagerView(this.ViewModel);

this.viewLoadedParamsReference?.AddToExtensionsSideBar(this, this.ManagerView);
}
Expand All @@ -114,6 +109,7 @@ public override void Shutdown()
/// </summary>
public override void Dispose()
{
this.ManagerView?.Dispose();
this.ViewModel?.Dispose();
this.ManagerView = null;
this.ViewModel = null;
Expand Down
32 changes: 5 additions & 27 deletions src/GraphNodeManagerViewExtension/GraphNodeManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GraphNodeManagerViewModel : NotificationObject, IDisposable
private bool isAnyFilterOn = false;
private Action<Logging.ILogMessage> logMessage;

private HomeWorkspaceModel CurrentWorkspace
internal HomeWorkspaceModel CurrentWorkspace
{
get
{
Expand Down Expand Up @@ -112,8 +112,6 @@ public string SearchText
}
}

public GraphNodeManagerView GraphNodeManagerView;

public string searchBoxPrompt = "Search..";
/// <summary>
/// Search Box Prompt binding
Expand Down Expand Up @@ -318,34 +316,16 @@ internal void ClearAllFilters(object obj)
/// Export the current graph to CSV or JSON
/// </summary>
/// <param name="parameter"></param>
/// <exception cref="NotImplementedException"></exception>
internal void ExportGraph(object parameter)
{
if (parameter == null) return;
var type = parameter.ToString();
var promptName = System.IO.Path.GetFileNameWithoutExtension(currentWorkspace.FileName);

var filteredNodes = FilteredNodesArray();

switch (type)
{
case "CSV":
Utilities.Utilities.ExportToCSV(filteredNodes, promptName);
break;
case "JSON":
Utilities.Utilities.ExportToJson(filteredNodes, promptName);
break;
}
RequestExportGraph?.Invoke(parameter);
}

/// <summary>
/// Helper method to return an Array of the currently active Nodes
/// This action is called on the export graph command.
/// </summary>
/// <returns></returns>
private GridNodeViewModel [] FilteredNodesArray()
{
return GraphNodeManagerView.NodesInfoDataGrid.ItemsSource.Cast<GridNodeViewModel>().ToArray();
}
/// <param name="parameter"></param>
internal event Action<object> RequestExportGraph;

/// <summary>
/// On changing a condition that affects the filter
Expand All @@ -354,7 +334,6 @@ internal void NodesCollectionFilter_Changed()
{
// Refresh the view to apply filters.
RaisePropertyChanged(nameof(IsAnyFilterOn));
CollectionViewSource.GetDefaultView(GraphNodeManagerView.NodesInfoDataGrid.ItemsSource).Refresh();
}

/// <summary>
Expand Down Expand Up @@ -572,7 +551,6 @@ public void Dispose()
viewLoadedParams.CurrentWorkspaceChanged -= OnCurrentWorkspaceChanged;
viewLoadedParams.CurrentWorkspaceCleared -= OnCurrentWorkspaceCleared;
NodesCollection.Filter -= NodesCollectionViewSource_Filter;
GraphNodeManagerView = null;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ namespace DynamoCoreWpfTests
{
public class GraphNodeManagerViewExtensionTests : DynamoTestUIBase
{
private bool oldEnablePersistance = false;

private string PackagesDirectory { get { return Path.Combine(GetTestDirectory(this.ExecutingDirectory), "pkgs"); } }

protected override void GetLibrariesToPreload(List<string> libraries)
{
libraries.Add("VMDataBridge.dll");
libraries.Add("DesignScriptBuiltin.dll");
libraries.Add("DSCoreNodes.dll");
base.GetLibrariesToPreload(libraries);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are needed by some of the graphs opened during GraphNodeManagerViewExtensionTests tests



protected override DynamoModel.IStartConfiguration CreateStartConfiguration(IPathResolver pathResolver)
{
string settingDirectory = Path.Combine(GetTestDirectory(ExecutingDirectory), "settings");
Expand Down Expand Up @@ -53,13 +64,26 @@ private void LoadExtension(GraphNodeManagerViewExtension v)
#endregion

#region Tests

[SetUp]
public void Setup()
{
oldEnablePersistance = ViewModel.PreferenceSettings.EnablePersistExtensions;
ViewModel.PreferenceSettings.EnablePersistExtensions = false;
}

[TearDown]
public void Teardown()
{
ViewModel.PreferenceSettings.EnablePersistExtensions = oldEnablePersistance;
}

/// <summary>
/// Test if the Extension loads correctly
/// </summary>
[Test]
public void ViewExtensionOpenTest()
{
RaiseLoadedEvent(this.View);
var extensionManager = View.viewExtensionManager;
var viewExtension = extensionManager.ViewExtensions
.FirstOrDefault(x => x as GraphNodeManagerViewExtension != null)
Expand All @@ -82,7 +106,6 @@ public void ViewExtensionOpenTest()
[Test]
public void CorrectNumberNodeItemsTest()
{
RaiseLoadedEvent(this.View);
var extensionManager = View.viewExtensionManager;
var viewExt = extensionManager.ViewExtensions
.FirstOrDefault(x => x as GraphNodeManagerViewExtension != null)
Expand All @@ -102,7 +125,6 @@ public void CorrectNumberNodeItemsTest()
Open(@"pkgs\Dynamo Samples\extra\ZoomNodeColorStates.dyn");

hwm = this.ViewModel.CurrentSpace as HomeWorkspaceModel;
Utility.DispatcherUtil.DoEvents();

int loadedGraphNodes = hwm.Nodes.Count();
int loadedExtensionNodes = dataGridItems.Count;
Expand All @@ -121,13 +143,13 @@ public void CorrectNumberNodeItemsTest()
Assert.AreEqual(loadedGraphNodes, loadedExtensionNodes);
Assert.AreEqual(deleteGraphNodes, deleteExtensionNodes);
}

/// <summary>
/// Test if using the IsFrozen filter yields correct results
/// </summary>
[Test]
public void FilterFrozenItemsTest()
{
RaiseLoadedEvent(this.View);
var extensionManager = View.viewExtensionManager;
var viewExt = extensionManager.ViewExtensions
.FirstOrDefault(x => x as GraphNodeManagerViewExtension != null)
Expand All @@ -137,7 +159,6 @@ public void FilterFrozenItemsTest()
LoadExtension(viewExt);

Open(@"pkgs\Dynamo Samples\extra\ZoomNodeColorStates.dyn");
Utility.DispatcherUtil.DoEvents();

// Get number of frozen Nodes in the graph
var hwm = this.ViewModel.CurrentSpace as HomeWorkspaceModel;
Expand Down Expand Up @@ -174,30 +195,25 @@ public void FilterFrozenItemsTest()
[Test]
public void ContainsEmptyListOrNullTest()
{
RaiseLoadedEvent(this.View);
var extensionManager = View.viewExtensionManager;
var viewExt = extensionManager.ViewExtensions
.FirstOrDefault(x => x as GraphNodeManagerViewExtension != null)
as GraphNodeManagerViewExtension;

var hwm = this.ViewModel.CurrentSpace as HomeWorkspaceModel;

// Arrange
LoadExtension(viewExt);

var view = viewExt.ManagerView;

Open(@"pkgs\Dynamo Samples\extra\GraphNodeManagerTestGraph_NullsEmptyLists.dyn");

hwm = this.ViewModel.CurrentSpace as HomeWorkspaceModel;
hwm.Run();
OpenAndRun(@"pkgs\Dynamo Samples\extra\GraphNodeManagerTestGraph_NullsEmptyLists.dyn");

Utility.DispatcherUtil.DoEvents();

var view = viewExt.ManagerView;

var images = WpfUtilities.ChildrenOfType<Image>(view.NodesInfoDataGrid);

int nullNodesImageCount = GetImageCount(images, "Null");
int emptyListNodesImageCount = GetImageCount(images, "EmptyList");
int emptyListNodesImageCount = GetImageCount(images, "EmptyList");

var hwm = this.ViewModel.CurrentSpace;

int nullNodesCount = hwm.Nodes.Count(ContainsAnyNulls);
int emptyListNodesCount = hwm.Nodes.Count(ContainsAnyEmptyLists);
Expand All @@ -214,7 +230,6 @@ public void ContainsEmptyListOrNullTest()
[Test]
public void ViewExtensionOpensWithDynamoWhenRememberedTest()
{
RaiseLoadedEvent(this.View);
ViewModel.PreferenceSettings.EnablePersistExtensions = true;

//assert that option is enabled
Expand Down Expand Up @@ -247,7 +262,6 @@ public void ViewExtensionOpensWithDynamoWhenRememberedTest()
[Test]
public void ViewExtensionDoesNotOpensWithDynamoWhenClosedTest()
{
RaiseLoadedEvent(this.View);
ViewModel.PreferenceSettings.EnablePersistExtensions = true;

//assert that option is enabled
Expand Down Expand Up @@ -284,7 +298,6 @@ public void ViewExtensionDoesNotOpensWithDynamoWhenClosedTest()
[Test]
public void ViewExtensionDoesNotOpenWhenNotRememberedTest()
{
RaiseLoadedEvent(this.View);
ViewModel.PreferenceSettings.EnablePersistExtensions = false;

//assert that option is disabled
Expand Down
Loading