Example #1
0
        public ExportJobTaskTests()
        {
            _cancellationToken = _cancellationTokenSource.Token;
            _exportJobRecord   = new ExportJobRecord(
                new Uri("https://localhost/ExportJob/"),
                "Patient",
                "hash");

            _fhirOperationDataStore.UpdateExportJobAsync(_exportJobRecord, _weakETag, _cancellationToken).Returns(x =>
            {
                _lastExportJobOutcome = new ExportJobOutcome(_exportJobRecord, _weakETag);

                return(_lastExportJobOutcome);
            });

            _secretStore.GetSecretAsync(Arg.Any <string>(), _cancellationToken).Returns(x => new SecretWrapper(x.ArgAt <string>(0), "{\"destinationType\": \"in-memory\"}"));

            _exportDestinationClientFactory.Create("in-memory").Returns(_inMemoryDestinationClient);

            _resourceToByteArraySerializer.Serialize(Arg.Any <ResourceWrapper>()).Returns(x => Encoding.UTF8.GetBytes(x.ArgAt <ResourceWrapper>(0).ResourceId));

            _exportJobTask = new ExportJobTask(
                () => _fhirOperationDataStore.CreateMockScope(),
                _secretStore,
                Options.Create(_exportJobConfiguration),
                () => _searchService.CreateMockScope(),
                _resourceToByteArraySerializer,
                _exportDestinationClientFactory,
                NullLogger <ExportJobTask> .Instance);
        }
        /// <summary>
        /// Initializes the Twilio client.
        /// </summary>
        /// <param name="twilioAccountSidSecretName">The SSID of the Twilio account to authenticate as.</param>
        /// <param name="twilioAuthTokenSecretName">The auth token to use for authentication.</param>
        /// <param name="authority">The authority to authenticate against.</param>
        /// <returns>An asynchronous task.</returns>
        public async Task InitializeAsync(string twilioAccountSidSecretName, string twilioAuthTokenSecretName, string authority)
        {
            Secret twilioAccountSid = await _secretStore.GetSecretAsync(twilioAccountSidSecretName, authority);

            Secret twilioAuthToken = await _secretStore.GetSecretAsync(twilioAuthTokenSecretName, authority);

            Twilio.Http.HttpClient twilioHttpClient = new SystemNetHttpClient(_httpClient.GetHttpClient());

            _twilioClient = new TwilioRestClient(twilioAccountSid.Value, twilioAuthToken.Value, httpClient: twilioHttpClient);
        }
Example #3
0
        private async Task <DestinationInfo> GetDestinationInfo(CancellationToken cancellationToken)
        {
            SecretWrapper secret = await _secretStore.GetSecretAsync(_exportJobRecord.SecretName, cancellationToken);

            DestinationInfo destinationInfo = JsonConvert.DeserializeObject <DestinationInfo>(secret.SecretValue);

            return(destinationInfo);
        }
Example #4
0
        // Get destination info from secret store, create appropriate export client and connect to destination.
        private async Task GetDestinationInfoAndConnectAsync(CancellationToken cancellationToken)
        {
            SecretWrapper secret = await _secretStore.GetSecretAsync(_exportJobRecord.SecretName, cancellationToken);

            DestinationInfo destinationInfo = JsonConvert.DeserializeObject <DestinationInfo>(secret.SecretValue);

            _exportDestinationClient = _exportDestinationClientFactory.Create(destinationInfo.DestinationType);

            await _exportDestinationClient.ConnectAsync(destinationInfo.DestinationConnectionString, cancellationToken, _exportJobRecord.Id);
        }
        public void PullRecordingHttpTriggerRun()
        {
            HttpRequest request = CreateHttpPostRequest(_config.InputId, _config.CallSid);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            string expectedStorageContainerName  = _functionConfig[StorageContainerNameAppSettingName];
            string expectedDestinationPathPrefix = $"{_config.InputId}/file_";
            string expectedBlobEndpoint          = GetBlobEndpoint(_functionConfig[StorageAccessConnectionStringAppSettingName]);
            string expectedFullPathPrefix        = $"{expectedBlobEndpoint}{expectedStorageContainerName}/{expectedDestinationPathPrefix}";

            ISecretStore secretStore = PullRecordingHttpTrigger.Container.GetService <ISecretStore>();

            Secret expectedStorageReadAccessKey = secretStore.GetSecretAsync(_functionConfig[StorageReadAccessKeySecretNameAppSettingName], _functionConfig[AuthorityAppSettingName]).Result;

            IActionResult result = PullRecordingHttpTrigger.Run(request, _log, context).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            OkObjectResult okResult = (OkObjectResult)result;

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(okResult.Value, typeof(PullRecordingResponse));

            PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

            Assert.AreEqual(_config.CallSid, response.CallSid);
            Assert.IsNotNull(response.RecordingUri);
            Assert.IsTrue(response.RecordingUri.StartsWith(expectedDestinationPathPrefix));
            Assert.IsTrue(response.FullRecordingUrl.StartsWith(expectedFullPathPrefix));
            Assert.IsTrue(response.FullRecordingUrl.EndsWith($"?{expectedStorageReadAccessKey.Value}"));
            Assert.IsTrue(response.RecordingLength > 600000); // Recording size should be ~800KB
            Assert.IsNotNull(response.FullRecordingUrl);

            Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc);

            Assert.IsFalse(response.HasError);
            Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);

            _log.LogInformation("Writing returned recording URI to test configuration...");
            _config.RecordingUri = response.RecordingUri;
            _config.Save(GlobalTestConstants.TestConfigurationFilePath);
        }