Ejemplo n.º 1
0
 public void XmlAccept()
 {
     client.PreferredFormat = ResourceFormat.Xml;
     client.UseFormatParam  = false;
     client.Read <Patient>(id);
     HttpTests.AssertResourceResponseConformsTo(client, client.PreferredFormat);
 }
Ejemplo n.º 2
0
        public void HistoryForSpecificResourceId()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            var before = CreateDate.Value.AddMinutes(-1);
            var after  = before.AddHours(1);

            var history = client.History(location, before);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);
            checkSortOrder(history);
            var historySl = history.Entries.Select(entry => entry.SelfLink).ToArray();

            if (!history.Entries.All(entry => historySl.Contains(entry.SelfLink)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, after);
            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to after the last update still returns history");
            }
        }
        public void DeleteNonExistingPerson()
        {
            var rnd      = new Random();
            var location = "Patient/sprink" + rnd.Next().ToString();

            HttpTests.AssertFail(client, () => client.Delete(location), HttpStatusCode.NotFound);
        }
Ejemplo n.º 4
0
        public void UpdateTagsOnVersionUsingPost()
        {
            var identity = new ResourceIdentity(latest.SelfLink);

            var update   = new Tag(NUTAG, Tag.FHIRTAGSCHEME_GENERAL, "newVersionForVersion");
            var existing = new Tag(_otherTag, Tag.FHIRTAGSCHEME_GENERAL);

            HttpTests.AssertSuccess(client, () => client.AffixTags(identity, new List <Tag> {
                update
            }));

            var result = client.Read <Patient>(latest.Id);

            if (result.Tags.Count() != 2)
            {
                TestResult.Fail("update modified the number of tags");
            }

            if (!result.Tags.Any(t => t.Equals(existing)))
            {
                TestResult.Fail("update removed an existing but unchanged tag");
            }

            if (!result.Tags.Any(t => t.Equals(update) && t.Label == update.Label))
            {
                TestResult.Fail("update did not change the tag");
            }

            if (result.SelfLink != latest.SelfLink)
            {
                TestResult.Fail("updating the tags created a new version");
            }

            //TODO: Check whether taglists on older versions remain unchanged
        }
Ejemplo n.º 5
0
        public void VReadVersions()
        {
            foreach (var ent in history.Entries.OfType <ResourceEntry>())
            {
                var identity = new ResourceIdentity(ent.SelfLink);

                var version = client.Read <Patient>(identity);

                if (version == null)
                {
                    TestResult.Fail("Cannot find version that was present in history");
                }

                HttpTests.AssertContentLocationPresentAndValid(client);
                var selfLink = new ResourceIdentity(client.LastResponseDetails.ContentLocation);
                if (String.IsNullOrEmpty(selfLink.Id) || String.IsNullOrEmpty(selfLink.VersionId))
                {
                    TestResult.Fail("Optional Content-Location contains an invalid version-specific url");
                }
            }

            foreach (var ent in history.Entries.OfType <DeletedEntry>())
            {
                var identity = new ResourceIdentity(ent.SelfLink);

                HttpTests.AssertFail(client, () => client.Read <Patient>(identity), HttpStatusCode.Gone);
            }
        }
Ejemplo n.º 6
0
        public void DeleteTagsOnVersionUsingDelete()
        {
            var identity = new ResourceIdentity(latest.SelfLink);

            var delete   = new Tag(NUTAG, Tag.FHIRTAGSCHEME_GENERAL);
            var existing = new Tag(_otherTag, Tag.FHIRTAGSCHEME_GENERAL);

            HttpTests.AssertSuccess(client, () => client.DeleteTags(identity, new List <Tag> {
                delete
            }));

            var result = client.Read <Patient>(latest.Id);

            if (result.Tags.Count() != 1)
            {
                TestResult.Fail("delete resulted in an unexpected number of remaining tags");
            }

            if (!result.Tags.Any(t => t.Equals(existing)))
            {
                TestResult.Fail("delete removed an existing tag the should be untouched");
            }

            if (result.Tags.Any(t => t.Equals(delete)))
            {
                TestResult.Fail("delete did not remove the tag");
            }

            if (result.SelfLink != latest.SelfLink)
            {
                TestResult.Fail("deleting the tags created a new version");
            }

            //TODO: Check whether taglists on older versions remain unchanged
        }
Ejemplo n.º 7
0
        public void HistoryForResourceType()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            var before = CreateDate.Value.AddMinutes(-1);
            var after  = before.AddHours(1);

            var history = client.TypeHistory <Patient>(since: before);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);
            typeHistory = history;
            checkSortOrder(history);

            var historyLinks = history.Entries.Select(be => be.SelfLink).ToArray();

            if (!history.Entries.All(ent => historyLinks.Contains(ent.SelfLink)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, DateTimeOffset.Now.AddMinutes(1));

            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to a future moment still returns history");
            }
        }
Ejemplo n.º 8
0
        public void PageFwdThroughResourceHistory()
        {
            var pageSize = 30;
            var page     = client.TypeHistory <Patient>(pageSize: pageSize);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);

            forwardCount = 0;

            // Browse forwards
            while (page != null)
            {
                if (page.Entries.Count > pageSize)
                {
                    TestResult.Fail("Server returned a page with more entries than set by _count");
                }

                forwardCount += page.Entries.Count;
                lastPage      = page;
                HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);
                page = client.Continue(page);
            }

            //if (total.HasValue && forwardCount < total)
            //    TestResult.Fail(String.Format("Paging did not return all entries(expected at least {0}, {1} returned)",
            //                    total, forwardCount));
        }
Ejemplo n.º 9
0
        public void HistoryForWholeSystem()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }
            var    before = CreateDate.Value.AddMinutes(-1);
            Bundle history;


            history = client.WholeSystemHistory(before);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);

            HttpTests.AssertHasAllForwardNavigationLinks(history); // Assumption: system has more history than pagesize
            systemHistory = history;
            checkSortOrder(history);

            var historyLinks = history.Entries.Select(be => be.SelfLink).ToArray();

            if (!Versions.All(sl => historyLinks.Contains(sl)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, DateTimeOffset.Now.AddMinutes(1));

            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to a future moment still returns history");
            }
        }
Ejemplo n.º 10
0
        public void PageBackThroughResourceHistory()
        {
            if (forwardCount == -1)
            {
                TestResult.Skip();
            }

            var pageSize = 30;
            var page     = client.TypeHistory <Patient>(pageSize: pageSize);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);

            page = client.Continue(page, PageDirection.Last);
            var backwardsCount = 0;

            // Browse backwards
            while (page != null)
            {
                if (page.Entries.Count > pageSize)
                {
                    TestResult.Fail("Server returned a page with more entries than set by count");
                }

                backwardsCount += page.Entries.Count;
                HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);
                page = client.Continue(page, PageDirection.Previous);
            }

            if (backwardsCount != forwardCount)
            {
                TestResult.Fail(String.Format("Paging forward returns {0} entries, backwards returned {1}",
                                              forwardCount, backwardsCount));
            }
        }
Ejemplo n.º 11
0
        public void HistoryForSpecificResource()
        {
            initialize();
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            history = client.History(location);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);

            // There's one version less here, because we don't have the deletion
            int expected = Versions.Count + 1;

            if (history.Entries.Count != expected)
            {
                TestResult.Fail(String.Format("{0} versions expected after crud test, found {1}", expected, history.Entries.Count));
            }

            if (!history.Entries.OfType <ResourceEntry>()
                .All(ent => Versions.Contains(ent.SelfLink)))
            {
                TestResult.Fail("Selflinks on returned versions do not match links returned on creation" + history.Entries.Count);
            }


            checkSortOrder(history);
        }
Ejemplo n.º 12
0
 public void JsonFormat()
 {
     client.PreferredFormat = ResourceFormat.Json;
     client.UseFormatParam  = true;
     client.Read <Patient>(id);
     HttpTests.AssertResourceResponseConformsTo(client, client.PreferredFormat);
 }
Ejemplo n.º 13
0
        public void HistoryForNonExistingResource()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            HttpTests.AssertFail(client, () => client.History("Patient/3141592unlikely"), HttpStatusCode.NotFound);
        }
Ejemplo n.º 14
0
        public void TryReadUnknownResourceType()
        {
            ResourceIdentity id = ResourceIdentity.Build(client.Endpoint, "thisreallywondexist", "1");

            HttpTests.AssertFail(client, () => client.Read <Patient>(id), HttpStatusCode.NotFound);

            // todo: if the Content-Type header was not set by the server, this generates an abstract exception:
            // "The given key was not present in the dictionary";
        }
Ejemplo n.º 15
0
        public void DeleteBinary()
        {
            if (binaryId == null)
            {
                TestResult.Skip();
            }

            client.Delete(binaryId);

            HttpTests.AssertFail(client, () => client.Read <Binary>(binaryId), HttpStatusCode.Gone);
        }
Ejemplo n.º 16
0
        public void SearchPatientByNonExistingParameter()
        {
            var    nrOfAllPatients    = client.Search <Patient>().Entries.ByResourceType <Patient>().Count();
            Bundle actual             = client.Search("Patient", criteria: new string[] { "bonkers=blabla" }); //Obviously a non-existing search parameter
            var    nrOfActualPatients = actual.Entries.ByResourceType <Patient>().Count();

            HttpTests.AssertCorrectNumberOfResults(nrOfAllPatients, nrOfActualPatients, "Expected all patients ({0}) since the only search parameter is non-existing, but got {1}.");
            var outcomes = actual.Entries.ByResourceType <OperationOutcome>();

            TestResult.Assert(outcomes.Any(), "There should be an OperationOutcome.");
            TestResult.Assert(outcomes.Any(o => o.Resource.Issue.Any(i => i.Severity == OperationOutcome.IssueSeverity.Warning)), "With a warning in it.");
        }
Ejemplo n.º 17
0
        public void DeletePerson()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }
            string location = "Patient/" + CrudId;

            client.Delete(location);

            HttpTests.AssertFail(client, () => client.Read <Patient>(location), HttpStatusCode.Gone);
        }
Ejemplo n.º 18
0
        public void SearchUsingTag()
        {
            var tag = new Tag(_otherTag, Tag.FHIRTAGSCHEME_GENERAL, "dummy");

            Bundle result = null;

            HttpTests.AssertSuccess(client, () => result = client.Search <Patient>(new string[] { "_tag=" + _otherTag }));

            if (result.Entries.ByTag(_otherTag).Count() != 1)
            {
                TestResult.Fail("could not retrieve patient by its tag");
            }
        }
Ejemplo n.º 19
0
        public void SearchPatientByMalformedParameter()
        {
            var    nrOfAllPatients = client.Search <Patient>().Entries.Count();
            Bundle actual          = null;

            HttpTests.AssertFail <Bundle>(client, () => client.Search("Patient", new string[] { "...=test" }), out actual, HttpStatusCode.BadRequest);

            /* The statements below inspect the OperationOutcome in the result. But the FhirClient currently does not return any of the HttpStatusCode != OK.
             * var nrOfActualPatients = actual.Entries.ByResourceType<Patient>().Count();
             * HttpTests.AssertCorrectNumberOfResults(0, nrOfActualPatients, "Expected no patients ({0}) since the only search parameter is invalid, but got {1}.");
             * TestResult.Assert(actual.Entries.ByResourceType<OperationOutcome>().Any(), "There should be an OperationOutcome.");
             */
        }
Ejemplo n.º 20
0
        public void TestTagsOnCreateAndRead()
        {
            var tags = new List <Tag>()
            {
                new Tag(NUTAG, Tag.FHIRTAGSCHEME_GENERAL, "readTagTest")
            };
            var patient = DemoData.GetDemoPatient();

            HttpTests.AssertSuccess(client, () => latest = client.Create(patient, tags, true));

            if (latest.Tags == null)
            {
                TestResult.Fail("create did not return any tags");
            }

            var nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGSCHEME_GENERAL);

            if (nutags.Count() != 1 || nutags.First().Label != "readTagTest")
            {
                TestResult.Fail("create did not return specified tag");
            }

            var read = client.Read <Patient>(latest.Id);

            if (read.Tags == null)
            {
                TestResult.Fail("read did not return any tags");
            }

            nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGSCHEME_GENERAL);
            if (nutags.Count() != 1 || nutags.First().Label != "readTagTest")
            {
                TestResult.Fail("read did not return specified tag");
            }

            var vread = client.Read <Patient>(latest.SelfLink);

            if (vread.Tags == null)
            {
                TestResult.Fail("vread did not return any tags");
            }

            nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGSCHEME_GENERAL);
            if (nutags.Count() != 1 || nutags.First().Label != "readTagTest")
            {
                TestResult.Fail("vread did not return specified tag");
            }

            original = latest;
        }
Ejemplo n.º 21
0
        public void GetTestDataPerson()
        {
            Patient p = NewPatient("Emerald", "Caro");
            ResourceEntry <Patient> entry = client.Create(p, null, false);
            string id = entry.GetBasicId();

            var pat = client.Read <Patient>(id);

            HttpTests.AssertHttpOk(client);

            HttpTests.AssertValidResourceContentTypePresent(client);
            HttpTests.AssertLastModifiedPresent(client);
            HttpTests.AssertContentLocationPresentAndValid(client);
        }
Ejemplo n.º 22
0
        public void GetServerWideTags()
        {
            IEnumerable <Tag> tags = null;

            HttpTests.AssertSuccess(client, () => tags = client.WholeSystemTags());


            var tagStrings = tags.FilterOnFhirSchemes().Where(t => t.Term != null).Select(t => t.Term);

            if (!tagStrings.Contains(NUTAG) || !tagStrings.Contains(_otherTag))
            {
                TestResult.Fail("expected tags not found in server-wide tag list");
            }
        }
Ejemplo n.º 23
0
        public void TestTagsOnNonExisting()
        {
            // todo: tags from instance

            ResourceEntry     nep  = null; // non-existing-patient
            IEnumerable <Tag> tags = null;

            HttpTests.AssertFail(client, () => { nep = client.Read <Patient>("nonexisting"); }, HttpStatusCode.NotFound);
            TestResult.Assert(nep == null, "Non existing patient instance should be zero");

            HttpTests.AssertFail(client, () => { tags = client.Tags <Patient>("nonexisting"); }, HttpStatusCode.NotFound);

            HttpTests.AssertFail(client, () => { tags = client.Tags <Patient>("nonexisting", "nonexisting"); }, HttpStatusCode.NotFound);
        }
Ejemplo n.º 24
0
        public void PostBundleWithUpdates()
        {
            var newMasterId = "urn:oid:123.456.7.8.9";
            var doc         = postResult.Entries.OfType <ResourceEntry <DocumentReference> >().First();

            doc.Resource.MasterIdentifier.Value = newMasterId;

            var pat = postResult.Entries.OfType <ResourceEntry <Patient> >().First();

            pat.Resource.Identifier[0].Value = "3141592";

            var entries        = postResult.Entries.ToList();
            var returnedBundle = client.Transaction(postResult);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(returnedBundle);

            var entries2 = returnedBundle.Entries.ToList();

            if (entries2[0].Id != entries[0].Id || entries2[4].Id != entries[4].Id)  // etcetera
            {
                TestResult.Fail("submitting a batch with updates created new resources");
            }

            var refreshedBundle = client.RefreshBundle(returnedBundle);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(refreshedBundle);

            if (refreshedBundle.Entries.OfType <ResourceEntry <DocumentReference> >().First().Resource.MasterIdentifier.Value != newMasterId)
            {
                TestResult.Fail("update on document resource was not reflected in batch result");
            }

            if (refreshedBundle.Entries.OfType <ResourceEntry <Patient> >().First().Resource.Identifier[0].Value != "3141592")
            {
                TestResult.Fail("update on patient was not reflected in batch result");
            }

            doc = client.Read <DocumentReference>(doc.Id);
            if (doc.Resource.MasterIdentifier.Value != newMasterId)
            {
                TestResult.Fail("update on document resource was not reflected in new version");
            }

            pat = client.Read <Patient>(pat.Id);
            if (pat.Resource.Identifier[0].Value != "3141592")
            {
                TestResult.Fail("update on patient was not reflected in new version");
            }
        }
Ejemplo n.º 25
0
        public void GetInstanceHistoryTags()
        {
            IEnumerable <Tag> tags = null;

            var rl = new ResourceIdentity(latest.SelfLink);

            HttpTests.AssertSuccess(client, () => tags = client.Tags <Patient>(rl.Id, rl.VersionId));

            var tagStrings = tags.FilterOnFhirSchemes().Where(t => t.Term != null).Select(t => t.Term);

            if (!tagStrings.Contains(NUTAG) || !tagStrings.Contains(_otherTag))
            {
                TestResult.Fail("expected tags not found in resource instance tag list");
            }
        }
Ejemplo n.º 26
0
        public void UpdateTagsOnUpdate()
        {
            if (original == null)
            {
                TestResult.Skip();
            }

            // Update one tag, add another
            var newtags = new List <Tag>()
            {
                new Tag(NUTAG, Tag.FHIRTAGSCHEME_GENERAL, "readTagTest2"),
                new Tag(_otherTag, Tag.FHIRTAGSCHEME_GENERAL, "dummy")
            };

            HttpTests.AssertSuccess(client, () => latest = client.Read <Patient>(original.Id));

            latest.Tags = newtags;

            HttpTests.AssertSuccess(client, () => client.Update <Patient>(latest));

            var read = client.Read <Patient>(latest.Id);

            if (read.Tags == null)
            {
                TestResult.Fail("fetch after update did not return any tags");
            }

            if (read.Tags.Count() != 2)
            {
                TestResult.Fail(String.Format("Wrong number of tags after update: {0}, expected 2", read.Tags.Count()));
            }

            var nutags = read.Tags.FindByTerm(NUTAG, Tag.FHIRTAGSCHEME_GENERAL);

            if (nutags.Count() != 1 || nutags.First().Label != "readTagTest2")
            {
                TestResult.Fail("update did not replace value in tag");
            }

            var othertags = read.Tags.FindByTerm(_otherTag, Tag.FHIRTAGSCHEME_GENERAL);

            if (othertags.Count() != 1 || othertags.First().Label != "dummy")
            {
                TestResult.Fail("update failed to add new tag");
            }

            latest = read;
        }
Ejemplo n.º 27
0
        public void PostBundleAgain()
        {
            var bundle  = DemoData.GetDemoXdsBundle();
            var trans   = client.Transaction(bundle);
            var entries = trans.Entries.ToList();

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(trans);

            // If server honors the 'search' link, it might *not* re-create the patient
            if (entries[0].Id == connDoc.Id || entries[4].Id == binDoc.Id)  // etcetera
            {
                TestResult.Fail("submitting a bundle with identical cids should still create new resources");
            }

            //TODO: verify server honors the 'search' link
        }
Ejemplo n.º 28
0
        public void SearchResourcesWithNameCriterium()
        {
            if (allPatients == null)
            {
                TestResult.Skip();
            }
            // First create a search argument: any family name present in the
            // previous unlimited search result that has at least 5 characters
            var name = allPatients.Entries.ByResourceType <Patient>()
                       .Where(p => p.Resource.Name != null)
                       .SelectMany(p => p.Resource.Name)
                       .Where(hn => hn.Family != null)
                       .SelectMany(hn => hn.Family)
                       .Where(s => s.Length > 5).First();

            // Take the first three characters
            name = name.Substring(0, 3);


            var result = client.Search <Patient>(new string[] { "family=" + name });

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            if (result.Entries.Count == 0)
            {
                TestResult.Fail("search did not return any results");
            }

            // Each patient returned should have a family name with the
            // criterium
            var names = result.Entries.ByResourceType <Patient>()
                        .Where(p => p.Resource.Name != null)
                        .SelectMany(p => p.Resource.Name)
                        .Where(hn => hn.Family != null)
                        .SelectMany(hn => hn.Family);

            var correct = result.Entries.ByResourceType <Patient>()
                          .All(p => p.Resource.Name != null &&
                               p.Resource.Name.Where(hn => hn.Family != null)
                               .SelectMany(hn => hn.Family)
                               .Any(s => s.ToLower().Contains(name.ToLower())));

            if (!correct)
            {
                TestResult.Fail("search result contains patients that do not match the criterium");
            }
        }
Ejemplo n.º 29
0
        public void SearchPatientByGenderMissing()
        {
            var patients = new List <ResourceEntry <Patient> >();
            var bundle   = client.Search <Patient>();

            while (bundle != null && bundle.Entries.ByResourceType <Patient>().Count() > 0)
            {
                patients.AddRange(bundle.Entries.ByResourceType <Patient>());
                bundle = client.Continue(bundle);
            }
            var patientsNoGender = patients.Where(p => p.Resource.Gender == null);
            var nrOfPatientsWithMissingGender = patientsNoGender.Count();

            var actual = client.Search <Patient>(new string[] { "gender:missing=true" }, pageSize: 500).Entries.ByResourceType <Patient>();

            HttpTests.AssertCorrectNumberOfResults(nrOfPatientsWithMissingGender, actual.Count(), "Expected {0} patients without gender, but got {1}.");
        }
Ejemplo n.º 30
0
        public void GetResourceWideTags()
        {
            IEnumerable <Tag> tags = null;

            HttpTests.AssertSuccess(client, () => tags = client.TypeTags <Patient>());

            var tagStrings = tags.FilterOnFhirSchemes().Where(t => t.Term != null).Select(t => t.Term);

            if (!tagStrings.Contains(NUTAG) || !tagStrings.Contains(_otherTag))
            {
                TestResult.Fail("expected tags not found in resource-wide tag list");
            }

            HttpTests.AssertSuccess(client, () => tags = client.TypeTags <Conformance>());

            tagStrings = tags.FilterOnFhirSchemes().Where(t => t.Term != null).Select(t => t.Term);
            if (tagStrings.Contains(NUTAG) || tagStrings.Contains(_otherTag))
            {
                TestResult.Fail("tags showed up while listing tags for another resource type");
            }
        }
Ejemplo n.º 31
0
        public void RunStreamTests()
        {
            var st = new StreamTests (this);
            var files = new FileSystemTests (this);
            var http = new HttpTests (this);

            st.Run ();
            files.Run ();
            http.Run ();
        }