public void GivenAResourceWithoutSecurityLabels_WhenTryAddSecurityLabels_SecurityLabelsShouldBeAdded()
        {
            var resource = new Patient();
            var result   = new ProcessResult();

            result.AddProcessRecord(AnonymizationOperations.Redact, ElementNode.ForPrimitive(1));

            var resourceNode = ElementNode.FromElement(resource.ToTypedElement());

            _resourceProcessor.AddSecurityTag(resourceNode, result);
            Assert.Single(resourceNode.Children("meta"));

            resource = resourceNode.ToPoco <Patient>();

            Assert.Single(resource.Meta.Security);
            Assert.Equal(SecurityLabels.REDACT.Code, resource.Meta.Security.First().Code);
        }
        public override void EndVisit(ElementNode node)
        {
            if (node.IsFhirResource())
            {
                Tuple <ElementNode, ProcessResult> context = _contextStack.Pop();
                ProcessResult result = context.Item2;

                if (context.Item1 != node)
                {
                    // Should never throw exception here. In case any bug happen, we can get clear message for this exception.
                    throw new ConstraintException("Internal error: access wrong context.");
                }

                if (_contextStack.Any())
                {
                    _contextStack.Peek().Item2.Update(result);
                }

                if (AddSecurityTag && !node.IsContainedNode())
                {
                    _resourceProcessor.AddSecurityTag(node, result);
                }
            }
        }