Example #1
0
        public async Task GivenABatch_WhenInvokedAtCosmosDb_MetricNotificationsShouldBeEmitted()
        {
            _metricHandler?.ResetCount();

            await ExecuteAndValidate(
                () => _client.PostBundleAsync(Samples.GetDefaultBatch().ToPoco()),
                (type : typeof(ApiResponseNotification), count : 1, resourceType : Samples.GetDefaultBatch().ToPoco().ResourceType.ToString()),
                (type : typeof(CosmosStorageRequestMetricsNotification), count : 10, resourceType : Samples.GetDefaultBatch().ToPoco().ResourceType.ToString()));
        }
Example #2
0
        public async Task GivenAValidBundleWithReadonlyUser_WhenSubmittingABatch_ThenForbiddenAndOutcomeIsReturned()
        {
            FhirClient tempClient    = Client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);
            Bundle     requestBundle = Samples.GetDefaultBatch().ToPoco <Bundle>();

            FhirResponse <Bundle> fhirResponse = await tempClient.PostBundleAsync(requestBundle);

            Assert.NotNull(fhirResponse);
            Assert.Equal(HttpStatusCode.OK, fhirResponse.StatusCode);

            for (int i = 0; i < 6; i++)
            {
                var entry            = fhirResponse.Resource.Entry[i];
                var operationOutcome = entry.Response.Outcome as OperationOutcome;
                ValidateOperationOutcome(entry.Response.Status, operationOutcome, statusCodeMap[HttpStatusCode.Forbidden], "Authorization failed.", IssueType.Forbidden);
            }

            var resourceEntry = fhirResponse.Resource.Entry[6];

            ValidateOperationOutcome(resourceEntry.Response.Status, resourceEntry.Response.Outcome as OperationOutcome, statusCodeMap[HttpStatusCode.NotFound], $"The route for \"/{requestBundle.Entry[6].Request.Url}\" was not found.", IssueType.NotFound);
            resourceEntry = fhirResponse.Resource.Entry[7];
            ValidateOperationOutcome(resourceEntry.Response.Status, resourceEntry.Response.Outcome as OperationOutcome, statusCodeMap[HttpStatusCode.NotFound], "The route for \"/ValueSet/$lookup\" was not found.", IssueType.NotFound);
            resourceEntry = fhirResponse.Resource.Entry[8];
            Assert.Equal("200", resourceEntry.Response.Status);
            Assert.Null(resourceEntry.Response.Outcome);
            resourceEntry = fhirResponse.Resource.Entry[9];
            ValidateOperationOutcome(resourceEntry.Response.Status, resourceEntry.Response.Outcome as OperationOutcome, statusCodeMap[HttpStatusCode.NotFound], "Resource type 'Patient' with id '12334' couldn't be found.", IssueType.NotFound);
        }
Example #3
0
        public async Task GivenAValidBundleWithForbiddenUser_WhenSubmittingATransaction_ThenOperationOutcomeWithForbiddenStatusIsReturned()
        {
            FhirClient tempClient    = Client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);
            var        requestBundle = Samples.GetJsonSample("Bundle-TransactionWithValidBundleEntry");

            var fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.PostBundleAsync(requestBundle.ToPoco <Bundle>()));

            Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode);

            string[]    expectedDiagnostics = { "Transaction failed on 'POST' for the requested url '/Patient'.", "Authorization failed." };
            IssueType[] expectedCodeType    = { OperationOutcome.IssueType.Processing, OperationOutcome.IssueType.Forbidden };
            ValidateOperationOutcome(expectedDiagnostics, expectedCodeType, fhirException.OperationOutcome);
        }
Example #4
0
        public async Task GivenAValidBundleWithUnauthorizedUser_WhenSubmittingATransaction_ThenOperationOutcomeWithUnAuthorizedStatusIsReturned()
        {
            FhirClient tempClient    = Client.CreateClientForClientApplication(TestApplications.WrongAudienceClient);
            var        requestBundle = Samples.GetJsonSample("Bundle-TransactionWithValidBundleEntry");

            var fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.PostBundleAsync(requestBundle.ToPoco <Bundle>()));

            Assert.Equal(HttpStatusCode.Unauthorized, fhirException.StatusCode);

            string[]    expectedDiagnostics = { "Authentication failed." };
            IssueType[] expectedCodeType    = { OperationOutcome.IssueType.Login };
            ValidateOperationOutcome(expectedDiagnostics, expectedCodeType, fhirException.OperationOutcome);
        }