コード例 #1
0
        public void TestBinaryDetection()
        {
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary"));
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary?param=x"));
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/_history"));

            Assert.IsTrue(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/2"));
            Assert.IsTrue(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/2/_history/1"));
        }
コード例 #2
0
        public void TestBinaryDetection()
        {
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary"));
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary?param=x"));
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/_history"));

            Assert.IsTrue(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/2"));
            Assert.IsTrue(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/Binary/2/_history/1"));

            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/ValueSet/extensional-case-1/$expand?filter=f"));
            Assert.IsFalse(HttpToEntryExtensions.IsBinaryResponse("http://server.org/fhir/ValueSet/extensional-case-1/$expand%3Ffilter=f"));
        }
コード例 #3
0
        public void CallsCallbacks()
        {
            FhirClient client = new FhirClient(testEndpoint);

            client.ParserSettings.AllowUnrecognizedEnums = true;

            bool           calledBefore = false;
            HttpStatusCode?status       = null;

            byte[] body    = null;
            byte[] bodyOut = null;

            client.OnBeforeRequest += (sender, e) =>
            {
                calledBefore = true;
                bodyOut      = e.Body;
            };

            client.OnAfterResponse += (sender, e) =>
            {
                body   = e.Body;
                status = e.RawResponse.StatusCode;
            };

            var pat = client.Read <Patient>("Patient/example");

            Assert.IsTrue(calledBefore);
            Assert.IsNotNull(status);
            Assert.IsNotNull(body);

            var bodyText = HttpToEntryExtensions.DecodeBody(body, Encoding.UTF8);

            Assert.IsTrue(bodyText.Contains("<Patient"));

            calledBefore = false;
            client.Update(pat); // create cannot be called with an ID (which was retrieved)
            Assert.IsTrue(calledBefore);
            Assert.IsNotNull(bodyOut);

            bodyText = HttpToEntryExtensions.DecodeBody(body, Encoding.UTF8);
            Assert.IsTrue(bodyText.Contains("<Patient"));
        }
コード例 #4
0
        public void CallsCallbacks()
        {
            FhirClient client = new FhirClient(testEndpoint);

            bool           calledBefore = false;
            HttpStatusCode?status       = null;

            byte[] body    = null;
            byte[] bodyOut = null;

            client.OnBeforeRequest += (sender, e) =>
            {
                calledBefore = true;
                bodyOut      = e.Body;
            };

            client.OnAfterResponse += (sender, e) =>
            {
                body   = e.Body;
                status = e.RawResponse.StatusCode;
            };

            var pat = client.Read <Patient>("Patient/example");

            Assert.IsTrue(calledBefore);
            Assert.IsNotNull(status);
            Assert.IsNotNull(body);

            var bodyText = HttpToEntryExtensions.DecodeBody(body, Encoding.UTF8);

            Assert.IsTrue(bodyText.Contains("<Patient"));

            calledBefore = false;
            client.Create(pat);
            Assert.IsTrue(calledBefore);
            Assert.IsNotNull(bodyOut);

            bodyText = HttpToEntryExtensions.DecodeBody(body, Encoding.UTF8);
            Assert.IsTrue(bodyText.Contains("<Patient"));
        }
コード例 #5
0
        public void TestFormBody()
        {
            string expected = "given=test&Key=Value&Active=true";

            var    endpoint     = new Uri("http://myserver.org/fhir");
            string resourceType = "Patient";

            var parameters = new List <Tuple <string, string> >();

            parameters.Add(new Tuple <string, string>("given", "test"));
            parameters.Add(new Tuple <string, string>("Key", "Value"));
            parameters.Add(new Tuple <string, string>("Active", "true"));
            SearchParams searchParams = SearchParams.FromUriParamList(parameters);

            Bundle bundle = new TransactionBuilder(endpoint).SearchUsingPost(searchParams, resourceType).ToBundle();

            byte[]         body;
            HttpWebRequest request = bundle.Entry[0].ToHttpRequest(endpoint, Prefer.ReturnRepresentation, ResourceFormat.Json, true, false, out body);

            var bodyText = HttpToEntryExtensions.DecodeBody(body, Encoding.UTF8);

            Assert.AreEqual(bodyText, expected);
        }