Skip to content

Commit

Permalink
UANodeSetValidation.Extensions.GetObject - object reference not set #624
Browse files Browse the repository at this point in the history


- Added anchors
- Working on UT - in progress
  • Loading branch information
mpostol committed Aug 9, 2021
1 parent a83877f commit ea07336
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
</AdditionalFiles>
<Compile Include="UANodeContextUnitTest.cs" />
<Compile Include="UAReferenceContextTestClass.cs" />
<Compile Include="ValidatorUnitTest.cs" />
<Compile Include="XMLModelsProblemsToReportUnitTest.cs" />
<Compile Include="XMLModelsCorrectModelsUnitTest.cs" />
<Compile Include="XMLModelsModelsWithErrorsUnitTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//__________________________________________________________________________________________________
//
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions
//__________________________________________________________________________________________________

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Collections.Generic;
using UAOOI.SemanticData.BuildingErrorsHandling;
using UAOOI.SemanticData.InformationModelFactory;
using UAOOI.SemanticData.UANodeSetValidation.Diagnostic;
using UAOOI.SemanticData.UANodeSetValidation.XML;

namespace UAOOI.SemanticData.UANodeSetValidation
{
[TestClass]
public class ValidatorUnitTest
{
[TestMethod]
public void ConstructorTest()
{
Mock<IAddressSpaceBuildContext> addressSpaceBuildContextMock = new Mock<IAddressSpaceBuildContext>();
Mock<IBuildErrorsHandling> buildErrorsHandlingNock = new Mock<IBuildErrorsHandling>();
Validator _i2t = new Validator(addressSpaceBuildContextMock.Object, buildErrorsHandlingNock.Object);
}

[TestMethod]
public void UAMethodTest()
{
Mock<IAddressSpaceBuildContext> addressSpaceBuildContextMock = new Mock<IAddressSpaceBuildContext>();
Mock<IBuildErrorsHandling> buildErrorsHandlingNock = new Mock<IBuildErrorsHandling>();
Validator _i2t = new Validator(addressSpaceBuildContextMock.Object, buildErrorsHandlingNock.Object);
UAVariable inputParameter = new UAVariable()
{
NodeId = "ns=2;i=1031",
BrowseName = "InputArguments",
ParentNodeId = "ns=2;i=7001",
DataType = "i=296",
ValueRank = 1,
ArrayDimensions = "0",
DisplayName = new LocalizedText[] { new LocalizedText() { Value = "InputArguments" } },
Description = new LocalizedText[] { new LocalizedText() { Value = "the definition of the input argument of method 1:MethodSet.2:Start" } },

References = new Reference[]
{
new Reference() { ReferenceType= "i=46", IsForward=false, Value = "ns=2;i=7001" }
}
};
UAMethod method = new UAMethod()
{
NodeId = "ns=2;i=7001",
BrowseName = "2:Start",
ParentNodeId = "ns=2;i=5002",
DisplayName = new LocalizedText[] { new LocalizedText() { Value = "Start" } },
References = new Reference[] { }
};
List<TraceMessage> traceBuffer = new List<TraceMessage>();
UANodeContext nodeContext = new UANodeContext(DataSerialization.NodeId.Parse(method.NodeId), addressSpaceBuildContextMock.Object, x => traceBuffer.Add(x));
nodeContext.Update(method, x => { });
Mock<INodeContainer> nodeContainerMock = new Mock<INodeContainer>();
Mock<IMethodInstanceFactory> methodInstanceFactory = new Mock<IMethodInstanceFactory>();
nodeContainerMock.Setup(x => x.AddNodeFactory<IMethodInstanceFactory>()).Returns(methodInstanceFactory.Object);
//TODO UANodeSetValidation.Extensions.GetObject - object reference not set #624
Assert.Inconclusive("UANodeSetValidation.Extensions.GetObject - object reference not set #624");
_i2t.ValidateExportNode(nodeContext, nodeContainerMock.Object);
Assert.AreEqual<int>(0, traceBuffer.Count);
}
}
}
2 changes: 2 additions & 0 deletions SemanticData/UANodeSetValidation/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ internal static XML.LocalizedText[] Truncate(this XML.LocalizedText[] localizedT

internal static List<DataSerialization.Argument> GetParameters(this XmlElement xmlElement)
{
//TODO UANodeSetValidation.Extensions.GetObject - object reference not set #624
ListOfExtensionObject _wrapper = xmlElement.GetObject<ListOfExtensionObject>();
Debug.Assert(_wrapper != null);
if (_wrapper.ExtensionObject.AsEnumerable<ExtensionObject>().Where<ExtensionObject>(x => !((string)x.TypeId.Identifier).Equals("i=297")).Any())
Expand Down Expand Up @@ -337,6 +338,7 @@ private static type GetObject<type>(this XmlElement xmlElement)
{
XmlWriterSettings _settings = new XmlWriterSettings() { ConformanceLevel = ConformanceLevel.Fragment };
using (XmlWriter wrt = XmlWriter.Create(_memoryBuffer, _settings))
//TODO UANodeSetValidation.Extensions.GetObject - object reference not set #624
xmlElement.WriteTo(wrt);
_memoryBuffer.Flush();
_memoryBuffer.Position = 0;
Expand Down
5 changes: 3 additions & 2 deletions SemanticData/UANodeSetValidation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void ValidateExportNode(IUANodeBase nodeContext, INodeContainer exportFac
/// <param name="nodeContext">The node context to be validated and exported.</param>
/// <param name="exportFactory">A model export factory.</param>
/// <param name="parentReference">The reference to parent node.</param>
/// <exception cref="ApplicationException">In {nameof(ValidateExportNode)}</exception>
public void ValidateExportNode(IUANodeBase nodeContext, INodeContainer exportFactory, UAReferenceContext parentReference)
{
Debug.Assert(nodeContext != null, "Validator.ValidateExportNode the argument nodeContext is null.");
Expand Down Expand Up @@ -205,8 +204,9 @@ private void Update(IMethodInstanceFactory nodeDesign, UAMethod nodeSet, UARefer
nodeDesign.UserExecutable = !nodeSet.UserExecutable ? nodeSet.UserExecutable : new Nullable<bool>();
nodeDesign.MethodDeclarationId = nodeSet.MethodDeclarationId;
nodeDesign.ReleaseStatus = nodeSet.ReleaseStatus.ConvertToReleaseStatus();
//TODO UANodeSetValidation.Extensions.GetObject - object reference not set #624
nodeDesign.AddInputArguments(x => GetParameters(x));
nodeDesign.AddOutputArguments(x => GetParameters(x));
//nodeDesign.AddOutputArguments(x => GetParameters(x));
}

private void Update(IViewInstanceFactory nodeDesign, UAView nodeSet)
Expand Down Expand Up @@ -321,6 +321,7 @@ private static void CreateModelDesignStub(INodeContainer factory)
private Parameter[] GetParameters(XmlElement arguments)
{
List<Parameter> _parameters = new List<Parameter>();
//TODO UANodeSetValidation.Extensions.GetObject - object reference not set #624
foreach (DataSerialization.Argument _item in arguments.GetParameters())
_parameters.Add(m_AddressSpace.ExportArgument(_item));
return _parameters.ToArray();
Expand Down

0 comments on commit ea07336

Please sign in to comment.