public void TestExpandChild()
        {
            var qStructDef = _testSource.GetStructureDefinition("http://hl7.org/fhir/StructureDefinition/Questionnaire");

            Assert.IsNotNull(qStructDef);
            Assert.IsNotNull(qStructDef.Snapshot);

            var nav = new ElementNavigator(qStructDef.Snapshot.Element);

            nav.JumpToFirst("Questionnaire.telecom");
            Assert.IsTrue(SnapshotGenerator.ExpandElement(nav, _testSource));
            Assert.IsTrue(nav.MoveToChild("period"), "Did not move into complex datatype ContactPoint");

            nav.JumpToFirst("Questionnaire.group");
            Assert.IsTrue(SnapshotGenerator.ExpandElement(nav, _testSource));
            Assert.IsTrue(nav.MoveToChild("title"), "Did not move into internally defined backbone element Group");
        }
        private void TestExpandElement(string srcProfileUrl, string expandElemPath)
        {
            const string Indent = "  ";

            // Prepare...
            var sd = _testSource.GetStructureDefinition(srcProfileUrl);

            Assert.IsNotNull(sd);
            Assert.IsNotNull(sd.Snapshot);

            var elems = sd.Snapshot.Element;

            Assert.IsNotNull(elems);

            Debug.WriteLine("Input:");
            Debug.WriteLine(string.Join(Environment.NewLine, elems.Where(e => e.Path.StartsWith(expandElemPath)).Select(e => Indent + e.Path)));

            var elem = elems.FirstOrDefault(e => e.Path == expandElemPath);

            Assert.IsNotNull(elem);

            // Test...
            var generator = new SnapshotGenerator(_testSource, _settings);
            var result    = generator.ExpandElement(elems, elem);

            // Verify results
            Debug.WriteLine("\r\nOutput:");
            Debug.WriteLine(string.Join(Environment.NewLine, result.Where(e => e.Path.StartsWith(expandElemPath)).Select(e => Indent + e.Path)));

            Assert.IsNotNull(elem.Type);
            var elemType = elem.Type.FirstOrDefault();
            var nameRef  = elem.NameReference;

            if (elemType != null)
            {
                // Validate type profile expansion
                var elemTypeCode = elemType.Code.Value;
                Assert.IsNotNull(elemTypeCode);
                var elemProfile = elemType.Profile.FirstOrDefault();
                var sdType      = elemProfile != null
                    ? _testSource.GetStructureDefinition(elemProfile)
                    : _testSource.GetStructureDefinitionForCoreType(elemTypeCode);

                Assert.IsNotNull(sdType);
                Assert.IsNotNull(sdType.Snapshot);

                Debug.WriteLine("\r\nType:");
                Debug.WriteLine(string.Join(Environment.NewLine, sdType.Snapshot.Element.Select(e => Indent + e.Path)));

                sdType.Snapshot.Rebase(expandElemPath);
                var typeElems = sdType.Snapshot.Element;

                Assert.IsTrue(result.Count == elems.Count + typeElems.Count - 1);
                Assert.IsTrue(result.Where(e => e.Path.StartsWith(expandElemPath)).Count() == typeElems.Count);

                var startPos = result.IndexOf(elem);
                for (int i = 0; i < typeElems.Count; i++)
                {
                    var path = typeElems[i].Path;
                    Assert.IsTrue(result[startPos + i].Path.EndsWith(path, StringComparison.OrdinalIgnoreCase));
                }
            }
            else if (nameRef != null)
            {
                // Validate name reference expansion
                var nav = new ElementNavigator(elems);
                Assert.IsTrue(nav.JumpToNameReference(nameRef));
                var prefix = nav.Path;
                Assert.IsTrue(nav.MoveToFirstChild());
                var pos = result.IndexOf(elem);

                Debug.WriteLine("\r\nName Reference:");
                do
                {
                    Debug.WriteLine(Indent + nav.Path);
                    var srcPath = nav.Path.Substring(prefix.Length);
                    var tgtPath = result[++pos].Path.Substring(expandElemPath.Length);
                    Assert.AreEqual(srcPath, tgtPath);
                } while (nav.MoveToNext());
            }
        }