Пример #1
0
        private void runTestItem(XElement testLine, Model.DomainResource resource)
        {
            var  expression = testLine.Element("expression");
            var  output     = testLine.Elements("output");
            bool hasInvalid;

            string invalid = expression.TryGetAttribute("invalid", out hasInvalid);

            if (hasInvalid)
            {
                ErrorType errorType;

                if (invalid == "syntax")
                {
                    errorType = ErrorType.Syntax;
                }
                else if (invalid == "semantic")
                {
                    errorType = ErrorType.Semantics;
                }
                else
                {
                    throw new ArgumentException("unknown error type");
                }

                testInvalid(resource, errorType, expression.Value);
            }
            else
            {
                // Still need to check the types (and values)
                test(resource, expression.Value, output);
            }
        }
        private void runTests(string pathToTest)
        {
            // Read the test file, then execute each of them
            var doc = XDocument.Load(pathToTest);

            foreach (var item in doc.Descendants("test"))
            {
                string groupName  = item.Parent.Attribute("name").Value;
                string name       = item.Attribute("name")?.Value ?? "(no name)";
                string inputfile  = item.Attribute("inputfile").Value;
                var    mode       = item.Attribute("mode");
                string expression = item.Element("expression").Value;

                if (mode != null && mode.Value == "strict")
                {
                    continue;                                         // don't do 'strict' tests yet
                }
                // Now perform this unit test
                Model.DomainResource resource = null;
                string basepath = Path.Combine(TestData.GetTestDataBasePath(), "fhirpath", "input");

                if (!_cache.ContainsKey(inputfile))
                {
                    _cache.Add(inputfile, (Model.DomainResource)(new FhirXmlParser().Parse <Model.DomainResource>(
                                                                     File.ReadAllText(Path.Combine(basepath, inputfile)))));
                }
                resource = _cache[inputfile];

                try
                {
                    totalTests += 1;
                    runTestItem(item, resource);
                }


                catch (XunitException afe) // (AssertFailedException afe)
                {
                    output.WriteLine("FAIL: {0} - {1}: {2}", groupName, name, expression);
                    output.WriteLine("   " + afe.Message);
                    numFailed += 1;
                }
                catch (InvalidOperationException ioe)
                {
                    output.WriteLine("FAIL: {0} - {1}: {2}", groupName, name, expression);
                    output.WriteLine("   " + ioe.Message);
                    numFailed += 1;
                }
                catch (FormatException fe)
                {
                    output.WriteLine("FAIL: {0} - {1}: {2}", groupName, name, expression);
                    output.WriteLine("   " + fe.Message);
                    numFailed += 1;
                }
                catch (Exception e)
                {
                    output.WriteLine("FAIL: {0} - {1}: {2}", groupName, name, expression);
                    throw e;
                }
            }
        }
Пример #3
0
        private void put(IKey key, int level, DomainResource resource)
        {
            BsonIndexDocumentBuilder builder = new BsonIndexDocumentBuilder(key);
            builder.WriteMetaData(key, level, resource);

            var matches = definitions.MatchesFor(resource);
            foreach (Definition definition in matches)
            {
                definition.Harvest(resource, builder.InvokeWrite);
            }

            BsonDocument document = builder.ToDocument();
            store.Save(document);
        }
Пример #4
0
 private void AddContainedResources(DomainResource resource, IndexValue parent)
 {
     parent.Values.AddRange(resource.Contained.Where(c => c is DomainResource).Select(
         c => {
             IKey containedKey = c.ExtractKey();
             //containedKey.ResourceId = key.ResourceId + "#" + c.Id;
             return IndexResourceRecursively((c as DomainResource), containedKey, "contained");
             }));
 }