Opc.Ua.ServerTest.TranslatePathTest.VerifyPaths C# (CSharp) Method

VerifyPaths() private method

Verifies that the timestamps match the requested filter.
private VerifyPaths ( Node node, BrowsePath request, BrowsePathResult result ) : bool
node Node
request BrowsePath
result BrowsePathResult
return bool
        private bool VerifyPaths(
            Node node, 
            BrowsePath request, 
            BrowsePathResult result)
        {
            // check empty path.
            if (request.RelativePath.Elements == null || request.RelativePath.Elements.Count == 0)
            {  
                if (result.StatusCode != StatusCodes.BadBrowseNameInvalid)
                {
                    Log(
                        "Unexpected error returned during translate for Node '{0}'. NodeId = {1}, Expected = {2}, Actual = {3}",
                        node,
                        node.NodeId,
                        (StatusCode)StatusCodes.BadBrowseNameInvalid,
                        result.StatusCode);

                    return false;
                }
            }
                      
            BrowsePathResult expectedResult = new BrowsePathResult();
            GetTargets(node, request.RelativePath.Elements, 0, expectedResult);

            if (result.StatusCode == StatusCodes.BadNoMatch)
            {
                if (expectedResult.Targets.Count > 0)
                {
                    Log(
                        "Translate returned BadNoMatch when targets expected '{0}'. NodeId = {1}, Path = {2}, ExpectedCount = {3}",
                        node,
                        node.NodeId,
                        GetRelativePath(request.RelativePath.Elements),
                        expectedResult.Targets.Count);

                 
                    return false;
                }

                if (result.Targets.Count > 0)
                {
                    Log(
                        "Translate returned targets with a BadNoMatch code '{0}'. NodeId = {1}, Path = {2}, ActualCount = {3}",
                        node,
                        node.NodeId,
                        GetRelativePath(request.RelativePath.Elements),
                        result.Targets.Count);

                    return false;
                }

                return true;
            }

            if (expectedResult.Targets.Count == 0)
            {
                Log(
                    "Translate returned invalided error code when no targets exist '{0}'. NodeId = {1}, Path = {2}, StatusCode = {3}",
                    node,
                    node.NodeId,
                    GetRelativePath(request.RelativePath.Elements),
                    (StatusCode)result.StatusCode);

                return false;
            }

            // check status code.
            if (result.StatusCode != StatusCodes.Good)
            {
                Log(
                    "Translate returned an error for Node '{0}'. NodeId = {1}, Path = {2}, StatusCode = {3}",
                    node,
                    node.NodeId,
                    GetRelativePath(request.RelativePath.Elements),
                    (StatusCode)result.StatusCode);

                return false;
            }

            // check for expected targets.
            for (int ii = 0; ii < expectedResult.Targets.Count; ii++)
            {
                BrowsePathTarget expectedTarget = expectedResult.Targets[ii];

                bool found = false;

                for (int jj = 0; jj < result.Targets.Count; jj++)
                {
                    BrowsePathTarget actualTarget = result.Targets[jj];

                    if (actualTarget.TargetId != expectedTarget.TargetId)
                    {
                        continue;
                    }
                    
                    found = true;

                    if (actualTarget.RemainingPathIndex != expectedTarget.RemainingPathIndex)
                    {
                        Log(
                            "Translate did not return correct remaining path index for target Node '{0}'. NodeId = {1}, Path = {2}, Expected = {3}, Actual = {4}",
                            node,
                            node.NodeId,
                            GetRelativePath(request.RelativePath.Elements),
                            expectedTarget.RemainingPathIndex,
                            actualTarget.RemainingPathIndex);

                        return false;
                    }
                        
                    break;
                }

                if (!found)
                {
                    Log(
                        "Translate did not return expected target Node '{0}'. NodeId = {1}, Path = {2}, TargetId = {3}",
                        node,
                        node.NodeId,
                        GetRelativePath(request.RelativePath.Elements),
                        expectedTarget.TargetId);

                    return false;
                }
            }
            
            // check for unexpected targets.
            for (int ii = 0; ii < result.Targets.Count; ii++)
            {
                BrowsePathTarget actualTarget = result.Targets[ii];

                bool found = false;

                for (int jj = 0; jj < expectedResult.Targets.Count; jj++)
                {
                    BrowsePathTarget expectedTarget = expectedResult.Targets[jj];

                    if (actualTarget.TargetId == expectedTarget.TargetId)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Log(
                        "Translate returned unexpected target Node '{0}'. NodeId = {1}, Path = {2}, TargetId = {3}",
                        node,
                        node.NodeId,
                        GetRelativePath(request.RelativePath.Elements),
                        actualTarget.TargetId);

                    return false;
                }
            }

            // all ok.
            return true;
        }        
        #endregion