コード例 #1
0
ファイル: ImportTests.cs プロジェクト: microsoft/fhir-server
        public async Task GivenImportOperationEnabled_WhenCancelImportTask_ThenTaskShouldBeCanceled()
        {
            _metricHandler?.ResetCount();
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            var respone = await _client.CancelImport(checkLocation);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await _client.CheckImportAsync(checkLocation));

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

            // wait task completed
            while (respone.StatusCode != HttpStatusCode.Conflict)
            {
                respone = await _client.CancelImport(checkLocation);

                await Task.Delay(TimeSpan.FromSeconds(3));
            }

            // Only check metric for local tests
            if (_fixture.IsUsingInProcTestServer)
            {
                var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)];
                var notification     = notificationList.First() as ImportTaskMetricsNotification;
                Assert.Single(notificationList);
                Assert.Equal(TaskResult.Canceled.ToString(), notification.Status);
                Assert.Null(notification.SucceedCount);
                Assert.Null(notification.FailedCount);
            }
        }
コード例 #2
0
        public async Task GivenImportOperationEnabled_WhenCancelImportTask_ThenTaskShouldBeCanceled()
        {
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            await _client.CancelImport(checkLocation);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await _client.CheckImportAsync(checkLocation));

            Assert.Equal(HttpStatusCode.BadRequest, fhirException.StatusCode);
        }