Skip to content

Commit

Permalink
Wrong default path after opening solution in the debug environment #62
Browse files Browse the repository at this point in the history
- fixes #62
- Cleanup code - only unimportant changes
- Fixed some problems related to: Removed dependency of the CAS.UA.Model.Designer.Wrappers on using System.Windows.Forms #38
- Improved some unit tests
- Ready to make next pre-release.
- UT 👍
  • Loading branch information
mpostol committed Nov 24, 2019
1 parent 3de6a36 commit a1a58e7
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///___________________________________________________________________________________
//___________________________________________________________________________________
//
// Copyright (C) 2019, Mariusz Postol LODZ POLAND.
//
Expand All @@ -15,6 +15,7 @@ namespace CAS.CommServer.UA.ModelDesigner.Configuration.UnitTests
[TestClass]
public class ServerSelectorUnitTest
{

[TestMethod]
public void ServerSelectorCreatorTest()
{
Expand Down Expand Up @@ -67,6 +68,8 @@ public void EmptyServerDescriptorTest()
_nss.ServerConfiguration = new ServerSelector.ServerDescriptor() { codebase = String.Empty, configuration = String.Empty };
Assert.IsFalse(_ui.WarningCalled);
}

#region Instrumentation
private class OpenFileDialog4UnitTest : IFileDialog
{
private string m_DefaultExt;
Expand Down Expand Up @@ -220,9 +223,8 @@ public Func<IFolderBrowserDialog> OpenFolderBrowserDialogFunc
return () => new FolderBrowserDialog();
}
}

public Func<string, string, bool> MessageBoxShowWarningAskYN => throw new NotImplementedException();

public bool UseWaitCursor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
private void MessageBoxShowMethod(string text, string caption)
{
WarningCalled = true;
Expand All @@ -231,6 +233,7 @@ private void MessageBoxShowMethod(string text, string caption)
}

}
#endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void ServerWrapperConstructorTest()
Assert.IsNotNull(_sw);
Assert.IsTrue(_configurationChanged);
}
//private instrumentation

#region instrumentation
private class GraphicalUserInterface : IGraphicalUserInterface
{
public Action<string, string> MessageBoxShowError
Expand Down Expand Up @@ -100,9 +101,12 @@ public Func<IFileDialog> SaveFileDialogFuc
throw new NotImplementedException();
}
}

public Func<string, string, bool> MessageBoxShowWarningAskYN => throw new NotImplementedException();
public bool UseWaitCursor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

}
private const string _dataPath = "Plugin";
#endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public Func<IFileDialog> SaveFileDialogFuc
throw new NotImplementedException();
}
}

public Func<string, string, bool> MessageBoxShowWarningAskYN => throw new NotImplementedException();
public bool UseWaitCursor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

}
public object AssemblyHelper { get; private set; }
}

}
17 changes: 4 additions & 13 deletions ModelDesigner.Configuration/ServerSelector.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//<summary>
// Title : PropertyGrid wrapper to select a server plug-in.
// System : Microsoft Visual C# .NET 2008
// $LastChangedDate$
// $Rev$
// $LastChangedBy$
// $URL$
// $Id$
//___________________________________________________________________________________
//
// Copyright (C)2009, CAS LODZ POLAND.
// TEL: +48 (42) 686 25 47
// mailto://[email protected]
// http://www.cas.eu
//</summary>
// Copyright (C) 2019, Mariusz Postol LODZ POLAND.
//
//___________________________________________________________________________________

using CAS.CommServer.UA.Common;
using CAS.CommServer.UA.ModelDesigner.Configuration.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ public Func<IFolderBrowserDialog> OpenFolderBrowserDialogFunc
/// </summary>
/// <value>The message box show warning ask yn.</value>
public Func<string, string, bool> MessageBoxShowWarningAskYN => (x, y) => MessageBox.Show(x, y, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes;
#endregion
/// <summary>
/// Gets or sets whether the wait cursor is used for all open forms of the application.
/// </summary>
/// <value><c>true</c> is the wait cursor is used for all open forms; otherwise, <c>false</c>.</value>
public bool UseWaitCursor { get => Application.UseWaitCursor; set => Application.UseWaitCursor = value; }
#endregion

#region private
private class OpenFileDialogWrapper : FileDialogWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public interface IGraphicalUserInterface
/// <value>The message box show action.</value>
Action<string, string> MessageBoxShowWarning { get; }
/// <summary>
/// Gets or sets the exclamation message box show delegate.
/// Gets the exclamation message box show delegate.
/// </summary>
/// <value>The message box show.</value>
/// <value>The message box show action.</value>
Action<string, string> MessageBoxShowExclamation { get; }
/// <summary>
/// Gets or sets the error message box show delegate.
Expand All @@ -50,5 +50,11 @@ public interface IGraphicalUserInterface
/// </summary>
/// <value>The message box show warning ask yn.</value>
Func<string, string, bool> MessageBoxShowWarningAskYN { get; }
/// <summary>
/// Gets or sets whether the wait cursor is used for all open forms of the application.
/// </summary>
/// <value><c>true</c> is the wait cursor is used for all open forms; otherwise, <c>false</c>.</value>
bool UseWaitCursor { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace CAS.CommServer.UA.ModelDesigner.DesignStudio.UnitTest.Controls
{

[TestClass]
public class BaseTreeNodeControlUnitTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,35 @@ public void DefaultFileNameTest()
Assert.IsFalse(String.IsNullOrEmpty(_newItem.DefaultDirectory));
Assert.IsFalse(_newItem.ChangesArePresent);
_IFileDialogMock.Verify(x => x.FileName, Times.Never);
_IFileDialogMock.VerifySet(x => x.FileName = @"c:\\folder\file.name", Times.Never);
_IFileDialogMock.VerifySet(x => x.FileName =It.IsAny<string>(), Times.Never);
_IFileDialogMock.Verify(x => x.InitialDirectory, Times.Never);
}
private class ConfigurationManagementFixture : ConfigurationManagement
[TestMethod]
public void ShowOpenDialogTestMethod()
{
public override ConfigurationType ConfigurationType => throw new NotImplementedException();
const string DefaultExt = "uamdsl";
const string FileName = "UAModelDesignerSolution";
const string Filter = "UA Model Designer Solution File (* .uamdsl)|*.uamdsl|UA Model Designer Solution File (* .xml)|*.xml|All files(*.*)|*.*";
const string Title = "UA Model Designer Solution Open/Save dialog window";
string _defPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), FileName);
Mock<IFileDialog> _IFileDialogMock = new Mock<IFileDialog>();
_IFileDialogMock.SetupProperty(x => x.FileName);
_IFileDialogMock.SetupProperty(x => x.DefaultExt);
_IFileDialogMock.SetupProperty(x => x.Filter);
_IFileDialogMock.SetupProperty(x => x.Title);
_IFileDialogMock.Setup(x => x.ShowDialog()).Returns(true);
ConfigurationManagementFixture _newItem = new ConfigurationManagementFixture(_IFileDialogMock.Object, _defPath);
_newItem.ShowOpenDialog();
_IFileDialogMock.VerifySet(x => x.DefaultExt = DefaultExt);
_IFileDialogMock.VerifySet(x => x.Filter = Filter);
_IFileDialogMock.VerifySet(x => x.Title = Title);
Assert.AreEqual<string>(FileName, Path.GetFileName(_IFileDialogMock.Object.FileName));
}

#region instrumentation
private class ConfigurationManagementFixture : ConfigurationManagement
{
protected override ConfigurationType Configuration => ConfigurationType.Solution;
public ConfigurationManagementFixture(IFileDialog mock, string fileName) : base(new GraphicalUserInterfaceFixture(mock), fileName) { }
internal void SignalChanges()
{
Expand All @@ -77,6 +99,10 @@ public override bool Open()
{
throw new NotImplementedException();
}
internal void ShowOpenDialog()
{
this.ShowDialogOpenFileDialog();
}
}
private class GraphicalUserInterfaceFixture : IGraphicalUserInterface
{
Expand All @@ -93,13 +119,10 @@ public GraphicalUserInterfaceFixture(IFileDialog mock)
public Func<IFileDialog> SaveFileDialogFuc => () => mock;
public Func<IFolderBrowserDialog> OpenFolderBrowserDialogFunc => throw new NotImplementedException();
public Func<string, string, bool> MessageBoxShowWarningAskYN => throw new NotImplementedException();
public bool UseWaitCursor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

}
// TODO Wrong default path after opening solution in the debug environment #62 - add to test
private const string DefaultExt = "xml";
private const string FileName = "UAAddressSpaceModel";
private const string Filter = "XML Configuration File (* .xml)|*.xml|All files(*.*)|*.*";
private const string Title = "UA Address Space Model";
#endregion

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void ConstructorTest()
}
private class GraphicalUserInterface : IGraphicalUserInterface
{

private readonly IFileDialog m_Mock;
public GraphicalUserInterface(IFileDialog @object)
{
Expand All @@ -47,6 +48,8 @@ public GraphicalUserInterface(IFileDialog @object)
public Func<IFileDialog> SaveFileDialogFuc => () => m_Mock;
public Func<IFolderBrowserDialog> OpenFolderBrowserDialogFunc => throw new NotImplementedException();
public Func<string, string, bool> MessageBoxShowWarningAskYN => throw new NotImplementedException();
public bool UseWaitCursor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

}
}
}
25 changes: 12 additions & 13 deletions ModelDesigner.DesignStudio/IO/ConfigurationManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal enum ConfigurationType
{
Project, Solution
}

/// <summary>
/// Class to save and restore data to/from external file.
/// This is base class and now it provides only common menu and file dialogs.
Expand All @@ -28,14 +29,18 @@ internal abstract class ConfigurationManagement
/// </summary>
public ConfigurationManagement(IGraphicalUserInterface graphicalUserInterface, string fileName)
{
m_GraphicalUserInterface = graphicalUserInterface;
GraphicalUserInterface = graphicalUserInterface;
InitializeComponent();
DefaultFileName = fileName;
}
#endregion

#region public
public abstract ConfigurationType ConfigurationType { get; }
/// <summary>
/// Gets the type of the configuration.
/// </summary>
/// <value>The type of the configuration defined in <see cref="ConfigurationType"/>.</value>
protected abstract ConfigurationType Configuration { get; }
public string DefaultDirectory => Path.GetDirectoryName(DefaultFileName);
/// <summary>
/// Gets or sets the default name of the file.
Expand Down Expand Up @@ -105,7 +110,7 @@ public void SetChangesArePresent()
public bool TestIfChangesArePresentDisplayWindowAndReturnTrueIfShouldBeContinued()
{
if (ChangesArePresent)
return m_GraphicalUserInterface.MessageBoxShowWarningAskYN(
return GraphicalUserInterface.MessageBoxShowWarningAskYN(
Resources.ConfigurationManagementQuestionAboutContinuationIfChangesArePresent,
Resources.ConfigurationManagementQuestionAboutContinuationIfChangesArePresentTitle);
else
Expand All @@ -115,26 +120,20 @@ public bool TestIfChangesArePresentDisplayWindowAndReturnTrueIfShouldBeContinued

#region private
//var
private IGraphicalUserInterface m_GraphicalUserInterface;
//private System.Windows.Forms.ToolStripMenuItem m_TSMI_Open;
//private System.Windows.Forms.ToolStripMenuItem m_TSMI_Save;
//private System.Windows.Forms.ToolStripMenuItem m_TSMI_SaveAs;
//private System.Windows.Forms.ContextMenuStrip m_ContextMenuStrip;
//private System.Windows.Forms.ToolStripMenuItem m_TSMI_New;
protected IGraphicalUserInterface GraphicalUserInterface { get; private set; }
private void RaiseChangesArePresentHasChanged()
{
ChangesArePresentHasChanged?.Invoke(this, EventArgs.Empty);
}
private bool m_ChangesArePresent = false;
private string m_FileName;

private void RaiseDefaultFileNameHasChanged()
{
DefaultFileNameHasChanged?.Invoke(this, EventArgs.Empty);
}
protected bool ShowDialogOpenFileDialog()
{
using (IFileDialog _dialog = m_GraphicalUserInterface.OpenFileDialogFunc())
using (IFileDialog _dialog = GraphicalUserInterface.OpenFileDialogFunc())
{
SetupFileDialog(_dialog);
bool _ret = _dialog.ShowDialog();
Expand All @@ -145,7 +144,7 @@ protected bool ShowDialogOpenFileDialog()
}
protected bool ShowDialogSaveFileDialog()
{
using (IFileDialog _dialog = m_GraphicalUserInterface.SaveFileDialogFuc())
using (IFileDialog _dialog = GraphicalUserInterface.SaveFileDialogFuc())
{
SetupFileDialog(_dialog);
bool _ret = _dialog.ShowDialog();
Expand All @@ -157,7 +156,7 @@ protected bool ShowDialogSaveFileDialog()
private void SetupFileDialog(IFileDialog _dialog)
{
_dialog.FileName = this.DefaultFileName;
switch (ConfigurationType)
switch (Configuration)
{
case ConfigurationType.Project:
_dialog.DefaultExt = Resources.Project_FileDialogDefaultExt;
Expand Down
Loading

0 comments on commit a1a58e7

Please sign in to comment.