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

Fixed ValidateAndExportModel for ADITest and eoursel510Test #527

Merged
merged 3 commits into from
Feb 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using UAOOI.SemanticData.BuildingErrorsHandling;
using UAOOI.SemanticData.UANodeSetValidation.XML;

namespace UAOOI.SemanticData.UANodeSetValidation.UnitTest
namespace UAOOI.SemanticData.UANodeSetValidation
{
[TestClass]
[DeploymentItem(@"XMLModels\CorrectModels", @"CorrectModels\")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.Linq;
using UAOOI.SemanticData.BuildingErrorsHandling;

namespace UAOOI.SemanticData.UANodeSetValidation.UnitTest
namespace UAOOI.SemanticData.UANodeSetValidation
{
[TestClass]
[DeploymentItem(@"XMLModels\ModelsWithErrors\", @"ModelsWithErrors\")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,47 @@ public void ADITest()
List<TraceMessage> _trace = new List<TraceMessage>();
IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z));
Uri model = _as.ImportUANodeSet(_testDataFileInfo);
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
_trace.Clear();
_as.ValidateAndExportModel(model);
IEnumerable<TraceMessage> vitalMessageserrors = _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic);
IEnumerable<TraceMessage> focusNodeClass = _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NodeClass);
Assert.IsFalse(focusNodeClass.Where<TraceMessage>(x => !x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Any<TraceMessage>());

//Assert.Inconclusive("The import returns unexpected errors.");

Assert.AreEqual<int>(6, vitalMessageserrors.Count<TraceMessage>());

Assert.AreEqual<int>(3, focusNodeClass.Count<TraceMessage>());
Debug.WriteLine(nameof(Focus.NodeClass));
foreach (TraceMessage item in focusNodeClass)
Debug.WriteLine(item.ToString());

IEnumerable<TraceMessage> focusNonCategorized = _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NonCategorized);
Assert.AreEqual<int>(2, focusNonCategorized.Count<TraceMessage>());
Debug.WriteLine(nameof(Focus.NonCategorized));
foreach (TraceMessage item in focusNonCategorized)
foreach (TraceMessage item in _trace)
Debug.WriteLine(item.ToString());
//TODO ADI model from Embedded example import fails #509
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.DataEncoding).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.DataType).Count<TraceMessage>());
Assert.AreEqual<int>(3, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Naming).Count<TraceMessage>());
Assert.AreEqual<int>(3, _trace.Where<TraceMessage>(x => x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Count<TraceMessage>());
Assert.AreEqual<int>(3, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NodeClass).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NonCategorized).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Reference).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());
}

[TestMethod]
public void eoursel510Test()
{

FileInfo _testDataFileInfo = new FileInfo(@"ProblemsToReport\eoursel510\Opc.Ua.NodeSet2.TriCycleType_V1.1.xml");
Assert.IsTrue(_testDataFileInfo.Exists);
List<TraceMessage> _trace = new List<TraceMessage>();
IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z));
Uri model = _as.ImportUANodeSet(_testDataFileInfo);
//Extensions is omitted during the import
Assert.AreEqual<int>(10, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());
List<TraceMessage> importUANodeSetXML = _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).ToList<TraceMessage>();
Assert.AreEqual<int>(1, importUANodeSetXML.Count);
Assert.AreEqual<string>("P0-0001010000", importUANodeSetXML[0].BuildError.Identifier);
Assert.IsTrue(importUANodeSetXML[0].Message.Contains("Extensions is omitted during the import"));
_trace.Clear();
_as.ValidateAndExportModel(model);
Assert.AreEqual<int>(13, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());

foreach (TraceMessage item in _trace)
Debug.WriteLine(item.ToString());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.DataEncoding).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.DataType).Count<TraceMessage>());
Assert.AreEqual<int>(3, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Naming).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NodeClass).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NonCategorized).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Reference).Count<TraceMessage>());
Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());
}
}
}
29 changes: 29 additions & 0 deletions SemanticData/UANodeSetValidation/IAddressSpaceURIRecalculate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//___________________________________________________________________________________
//
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________

using System;

namespace UAOOI.SemanticData.UANodeSetValidation
{
/// <summary>
/// Interface IAddressSpaceURIRecalculate is used to recalculate indexes in the imported model
/// </summary>
internal interface IAddressSpaceURIRecalculate
{
/// <summary>
/// Searches for an index that matches the <paramref name="URI"/>, and returns the zero-based index of the first occurrence within the namespace table.
/// </summary>
/// <param name="URI">The URI to be glistered in the namespace table.</param>
/// <returns>
/// The zero-based index of the first occurrence of <paramref name="URI"/>
/// </returns>
/// <exception cref="System.ArgumentNullException">URI is null.</exception>
ushort GetURIIndexOrAppend(Uri URI);

void UpadateModelOrAppend(IModelTableEntry model);
}
}
2 changes: 1 addition & 1 deletion SemanticData/UANodeSetValidation/UANodeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public bool Equals(IUANodeBase other)
return false;
//TODO ADI model from Embedded example import fails #509
if (this.BrowseName != other.BrowseName) //1:TransitionNumber vs TransitionNumber; 1:StateNumber vs StateNumber
throw new ArgumentOutOfRangeException("The browse name of compared nodes musty be equal.");
return false; // throw new ArgumentOutOfRangeException("The browse name of compared nodes musty be equal.");
return
this.UANode.Equals(other.UANode);
}
Expand Down
56 changes: 56 additions & 0 deletions SemanticData/UANodeSetValidation/XML/ModelTableEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//___________________________________________________________________________________
//
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________

using System;

namespace UAOOI.SemanticData.UANodeSetValidation.XML
{
/// <summary>
/// Class ModelTableEntry.
/// Implements the <see cref="UAOOI.SemanticData.UANodeSetValidation.IModelTableEntry" />
/// </summary>
/// <seealso cref="UAOOI.SemanticData.UANodeSetValidation.IModelTableEntry" />
public partial class ModelTableEntry : IModelTableEntry
{
/// <summary>
/// Gets or sets the required model. A list of dependencies for the model. If the model requires a minimum version the PublicationDate shall be specified.
/// Tools which attempt to resolve these dependencies may accept any PublicationDate after this date.
/// </summary>
/// <value>The required model.</value>
IModelTableEntry[] IModelTableEntry.RequiredModel => RequiredModel;

/// <summary>
/// Gets or sets the role permissions. The list of default RolePermissions for all Nodes in the model.
/// </summary>
/// <value>The role permissions.</value>
IRolePermission[] IModelTableEntry.RolePermissions => RolePermissions;

/// <summary>
/// Gets or sets the access restrictions. The default <c>AccessRestrictions</c> that apply to all <c>Nodes</c> in the model.
/// </summary>
/// <value>The access restrictions.</value>
byte IModelTableEntry.AccessRestrictions => AccessRestrictions;

/// <summary>
/// Gets or sets the model URI. The URI for the model. This URI should be one of the entries in the <see cref="NamespaceTable" /> table.
/// </summary>
/// <value>The model URI.</value>
Uri IModelTableEntry.ModelUri => new Uri(ModelUri);

/// <summary>
/// Gets or sets the publication date. When the model was published. This value is used for comparisons if the model is defined in multiple UANodeSet files.
/// </summary>
/// <value>The publication date.</value>
DateTime? IModelTableEntry.PublicationDate => this.PublicationDateSpecified ? PublicationDate : new Nullable<DateTime>();

/// <summary>
/// Gets or sets the version. The version of the model defined in the UANodeSet. This is a human readable string and not intended for programmatic comparisons.
/// </summary>
/// <value>The version.</value>
string IModelTableEntry.Version => Version;
}
}