private void AddProjectsNodes(IEnumerable <UAModelDesignerProject> configuration) { if (configuration == null) { return; } List <ProjectTreeNode> _nodes = new List <ProjectTreeNode>(); foreach (UAModelDesignerProject _project in configuration) { ProjectTreeNode _newProject = null; try { _newProject = new ProjectTreeNode(this, _project); _nodes.Add(_newProject); } catch (FileNotFoundException _ex) { this.MessageBoxHandling.Show(string.Format(Resources.ProjectFileNotFound_Info, _ex.Message), Resources.ProjectFileNotFound_Header, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception _ex) { this.MessageBoxHandling.Show(string.Format(Properties.Resources.Project_FileOpenError, _ex.Message), Properties.Resources.Project_OpenFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.AddRange(_nodes); }
private void CheckConsistency(ProjectTreeNode _newItem) { Assert.IsNotNull(_newItem); Assert.ThrowsException <NullReferenceException>(() => _newItem.AvailiableNamespaces); Assert.AreEqual <string>("$(ProjectFileName)", _newItem.BuildOutputDirectoryName); Assert.IsTrue(_newItem.BuildOutputDirectoryPath.StartsWith(@"C:\Model_")); Assert.AreEqual <int>(1, _newItem.Count); Assert.AreEqual <string>("$(ProjectFileName).csv", _newItem.CSVFileName); Assert.IsTrue(_newItem.CSVFilePath.StartsWith(@"C:\Model_")); Assert.AreEqual <string>(@".csv", Path.GetExtension(_newItem.CSVFilePath)); Assert.IsNotNull(_newItem.ErrorList); Assert.AreEqual <int>(0, _newItem.ErrorList.Count); Assert.IsTrue(_newItem.FileName.StartsWith(@"Model_"), _newItem.FileName); Assert.IsTrue(_newItem.FileName.Contains(@".xml"), _newItem.FileName); string _absoluteModelFilePath = _newItem.CalculateEffectiveAbsoluteModelFilePath(); Assert.IsTrue(_absoluteModelFilePath.StartsWith(@"C:\Model_"), _absoluteModelFilePath); Assert.IsTrue(_absoluteModelFilePath.Contains(@".xml"), _absoluteModelFilePath); Assert.AreEqual <string>(@"", _newItem.HelpTopicName); Assert.ThrowsException <NullReferenceException>(() => _newItem.GetTargetNamespace()); Assert.IsNull(_newItem.Parent); Assert.IsNotNull(_newItem.SymbolicName); Assert.IsTrue(_newItem.Text.StartsWith(@"Model_"), _newItem.Text); Assert.IsTrue(String.IsNullOrEmpty(_newItem.ToolTipText)); CheckConsistency(_newItem.UAModelDesignerProject); object _viewModel = _newItem.Wrapper; Assert.IsNotNull(_viewModel); Assert.AreSame(_viewModel, ViewModel.Instance); object _w4pg = _newItem.Wrapper4PropertyGrid; Assert.IsNotNull(_w4pg); Assert.AreSame(_w4pg, ViewModel.Instance); }
public void SaveTest() { //preparation Mock <IProjectConfigurationManagement> _projectConfigurationMock = new Mock <IProjectConfigurationManagement>(); Mock <OPCFModelDesign> _OPCFModelDesignMock = new Mock <OPCFModelDesign>(); _projectConfigurationMock.SetupGet <OPCFModelDesign>(x => x.ModelDesign).Returns(_OPCFModelDesignMock.Object); _projectConfigurationMock.SetupGet <string>(x => x.Name).Returns("EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327"); Mock <BaseTreeNode> _parentMock = new Mock <BaseTreeNode>("ParentBaseNode"); _parentMock.SetupGet <string[]>(x => x.AvailiableNamespaces).Returns(new List <string>() { "ns1", "ns2" }.ToArray()); _parentMock.Setup(x => x.GetTargetNamespace()).Returns("GetTargetNamespace"); //create object under test ProjectTreeNode _newItem = new ProjectTreeNode(_projectConfigurationMock.Object) { Parent = _parentMock.Object }; _newItem.Save(); _projectConfigurationMock.Verify(x => x.Save(It.IsAny <OPCFModelDesign>()), Times.Once); }
public void BuildTest() { Mock <IProjectConfigurationManagement> _projectConfigurationMock = new Mock <IProjectConfigurationManagement>(); Mock <OPCFModelDesign> _OPCFModelDesignMock = new Mock <OPCFModelDesign>(); _projectConfigurationMock.SetupGet <OPCFModelDesign>(x => x.ModelDesign).Returns(_OPCFModelDesignMock.Object); _projectConfigurationMock.SetupGet <string>(x => x.Name).Returns("EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327"); //_projectConfigurationMock.Setup(x => x.Build( z => { } )); Mock <BaseTreeNode> _parentMock = new Mock <BaseTreeNode>("ParentBaseNode"); ProjectTreeNode _newItem = new ProjectTreeNode(_projectConfigurationMock.Object) { Parent = _parentMock.Object }; List <string> trace = new List <string>(); Action <string> tracer = x => trace.Add(x); _newItem.Build(tracer); _projectConfigurationMock.Verify(x => x.Build(tracer), Times.Once); Assert.AreEqual <int>(4, trace.Count); Assert.AreEqual <string>("------ Building project: EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327. ------", trace[0]); Assert.IsTrue(trace[1].StartsWith("Build started at:")); Assert.IsTrue(trace[2].StartsWith("Build ended at:")); Assert.AreEqual <string>("", trace[3]); foreach (string msg in trace) { System.Diagnostics.Debug.WriteLine(msg); } }
//TODO Error while using Save operation #129 work on the test public void CreateNewModelTest() { String _currentFolder = Directory.GetCurrentDirectory(); Mock <ISolutionDirectoryPathManagement> _directory = new Mock <ISolutionDirectoryPathManagement>(); _directory.SetupGet(x => x.BaseDirectory).Returns(@"C:\"); CheckConsistency(ProjectTreeNode.CreateNewModel(_directory.Object)); Assert.AreEqual <string>(_currentFolder, Directory.GetCurrentDirectory()); }
public void ImportNodeSet() { ProjectTreeNode node = ProjectTreeNode.ImportNodeSet(this, x => AssemblyTraceEvent.Tracer.TraceEvent(x.TraceLevel, 186, x.ToString()), IO.ImportNodeSet.Import); if (node == null) { return; } Add(node); }
public void CreateTest() { Mock <ISolutionDirectoryPathManagement> _directory = new Mock <ISolutionDirectoryPathManagement>(); _directory.SetupGet(x => x.BaseDirectory).Returns(@"C:\"); ProjectTreeNode _emptyModel = ProjectTreeNode.CreateNewModel(_directory.Object); IViewModel _viewModel = _emptyModel.Create(); Assert.IsNotNull(_viewModel); }
public void FindTest() { Mock <ISolutionDirectoryPathManagement> _directory = new Mock <ISolutionDirectoryPathManagement>(); _directory.SetupGet(x => x.BaseDirectory).Returns(@"C:\"); ProjectTreeNode _emptyModel = ProjectTreeNode.CreateNewModel(_directory.Object); XmlQualifiedName _toFind = new XmlQualifiedName("Name", "Namespace"); ITypeDesign _findReturn = _emptyModel.Find(_toFind); Assert.IsNull(_findReturn); }
public void GetTargetNamespaceTest() { Mock <ISolutionDirectoryPathManagement> _directory = new Mock <ISolutionDirectoryPathManagement>(); string _solutionDir = Path.Combine(Directory.GetCurrentDirectory(), "Temp"); Directory.CreateDirectory(_solutionDir); _directory.SetupGet(x => x.BaseDirectory).Returns(_solutionDir); ProjectTreeNode _emptyModel = ProjectTreeNode.CreateNewModel(_directory.Object); _emptyModel.Save(); string _expectedModelFileName = Path.Combine(_solutionDir, _emptyModel.FileName); Assert.IsTrue(File.Exists(_expectedModelFileName), _expectedModelFileName); }
public void AddProject(bool existing) { ProjectTreeNode _node = null; if (existing) { _node = ProjectTreeNode.ImportNodeSet(HomeDirectory, x => AssemblyTraceEvent.Tracer.TraceEvent(x.TraceLevel, 486245093, x.ToString()), OPCFModelConfigurationManagement.ReadModelDesign); } else { _node = ProjectTreeNode.CreateNewModel(HomeDirectory); } Add(_node); }
public void AddProject(bool existing) { ProjectTreeNode _node = null; if (existing) { string _DefaultFileName = Path.Combine(HomeDirectory, Resources.DefaultProjectName); _node = ProjectTreeNode.ImportNodeSet(this, x => AssemblyTraceEvent.Tracer.TraceEvent(x.TraceLevel, 186, x.ToString()), OPCFModelConfigurationManagement.ReadModelDesign); } else { _node = ProjectTreeNode.CreateNewModel(this); } Add(_node); }
public void MyTestMethod() { Mock <ISolutionDirectoryPathManagement> _directory = new Mock <ISolutionDirectoryPathManagement>(); _directory.SetupGet(x => x.BaseDirectory).Returns(@"C:\"); UAModelDesignerProject _projectDescriptor = new UAModelDesignerProject() { BuildOutputDirectoryName = string.Empty, CSVFileName = "CSVFileName", FileName = m_DemoConfigurationFilePath, Name = "TestProjectDescription", ProjectIdentifier = Guid.NewGuid().ToString() }; ProjectTreeNode _openProject = new ProjectTreeNode(_directory.Object, _projectDescriptor); }
public void ConstructorNewProjectTest() { ProjectTreeNode _newItem = new ProjectTreeNode(new BaseDirectoryProvider(), string.Empty, new Opc.Ua.ModelCompiler.ModelDesign()); object _viewModel = _newItem.Wrapper; Assert.IsNotNull(_viewModel); Assert.AreSame(_viewModel, ViewModel.Instance); Assert.IsTrue(_newItem.Name.StartsWith("Model_")); Assert.AreEqual <string>(@"$(ProjectFileName)", _newItem.BuildOutputDirectoryName); Assert.IsFalse(String.IsNullOrEmpty(_newItem.BuildOutputDirectoryPath)); Assert.AreEqual <string>("$(ProjectFileName).csv", _newItem.CSVFileName); Assert.IsFalse(String.IsNullOrEmpty(_newItem.CSVFilePath)); Assert.IsTrue(_newItem.FileName.StartsWith("Model_")); Assert.IsFalse(String.IsNullOrEmpty(_newItem.FilePath)); Assert.IsNotNull(_newItem.ProjectIdentifier); }
public void CreateNewModelTest() { //preparation Mock <IProjectConfigurationManagement> _projectConfigurationMock = new Mock <IProjectConfigurationManagement>(); Mock <OPCFModelDesign> _OPCFModelDesignMock = new Mock <OPCFModelDesign>(); _projectConfigurationMock.SetupGet <OPCFModelDesign>(x => x.ModelDesign).Returns(_OPCFModelDesignMock.Object); _projectConfigurationMock.SetupGet <string>(x => x.Name).Returns("EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327"); Mock <BaseTreeNode> _parentMock = new Mock <BaseTreeNode>("ParentBaseNode"); _parentMock.SetupGet <string[]>(x => x.AvailiableNamespaces).Returns(new List <string>() { "ns1", "ns2" }.ToArray()); _parentMock.Setup(x => x.GetTargetNamespace()).Returns("GetTargetNamespace"); //create object under test ProjectTreeNode _newItem = new ProjectTreeNode(_projectConfigurationMock.Object) { Parent = _parentMock.Object }; //test consistency Assert.IsNotNull(_newItem.Parent); Assert.AreEqual <int>(2, _newItem.AvailiableNamespaces.Length); Assert.AreEqual <int>(1, _newItem.Count); Assert.IsNotNull(_newItem.ErrorList); Assert.AreEqual <int>(0, _newItem.ErrorList.Count); Assert.AreEqual <string>(@"", _newItem.HelpTopicName); Assert.AreEqual <string>("GetTargetNamespace", _newItem.GetTargetNamespace()); Assert.IsNotNull(_newItem.SymbolicName); Assert.AreEqual <string>(@"EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327", _newItem.Text); Assert.IsTrue(String.IsNullOrEmpty(_newItem.ToolTipText)); object _viewModel = _newItem.Wrapper; Assert.IsNotNull(_viewModel); Assert.AreSame(_viewModel, ViewModel.Instance); object _w4pg = _newItem.Wrapper4PropertyGrid; Assert.IsNotNull(_w4pg); Assert.AreSame(_w4pg, ViewModel.Instance); //test behavior _projectConfigurationMock.VerifyGet(x => x.ModelDesign, Times.Once); _projectConfigurationMock.VerifyGet(x => x.Name, Times.Once); }
public void FindTest() { Mock <IProjectConfigurationManagement> _projectConfigurationMock = new Mock <IProjectConfigurationManagement>(); Mock <OPCFModelDesign> _OPCFModelDesignMock = new Mock <OPCFModelDesign>(); _projectConfigurationMock.SetupGet <OPCFModelDesign>(x => x.ModelDesign).Returns(_OPCFModelDesignMock.Object); _projectConfigurationMock.SetupGet <string>(x => x.Name).Returns("EFFF0C05 - 8406 - 4AD9 - 8725 - F00FC8295327"); Mock <BaseTreeNode> _parentMock = new Mock <BaseTreeNode>("ParentBaseNode"); _parentMock.SetupGet <string[]>(x => x.AvailiableNamespaces).Returns(new List <string>() { "ns1", "ns2" }.ToArray()); ProjectTreeNode _newItem = new ProjectTreeNode(_projectConfigurationMock.Object) { Parent = _parentMock.Object }; XmlQualifiedName _toFind = new XmlQualifiedName("Name", "Namespace"); ITypeDesign _findReturn = _newItem.Find(_toFind); Assert.IsNull(_findReturn); }
public IViewModel Create(ProjectTreeNode modelEntity) { return(ViewModel.Instance); }