Beispiel #1
0
        public void ShouldErrorIfNoAuthToken()
        {
            // Setup

            // Input Parameters
            string phn = "9735361219";

            // Setup Configuration
            string endpoint = "https://test-endpoint";
            Uri    tokenUri = new Uri("https://localhost");
            ClientCredentialsTokenRequest tokenRequest = new ClientCredentialsTokenRequest()
            {
                ClientId     = "TEST_CLIENTID",
                ClientSecret = "TEST_CLIENT_SECRET",
                Password     = "******",
                Username     = "******",
            };
            Dictionary <string, string> configurationParams = new Dictionary <string, string>
            {
                { "Salesforce:Endpoint", endpoint },
                { "Salesforce:TokenUri", tokenUri.ToString() },
                { "Salesforce:ClientAuthentication:ClientId", tokenRequest.ClientId },
                { "Salesforce:ClientAuthentication:ClientSecret", tokenRequest.ClientSecret },
                { "Salesforce:ClientAuthentication:Username", tokenRequest.Username },
                { "Salesforce:ClientAuthentication:Password", tokenRequest.Password },
            };
            IConfiguration configuration = CreateConfiguration(configurationParams);

            // Setup Authentication
            Mock <IAuthenticationDelegate> mockAuthenticationDelegate = new Mock <IAuthenticationDelegate>();

            mockAuthenticationDelegate
            .Setup(s => s.AuthenticateAsUser(
                       It.Is <Uri>(x => x.ToString() == tokenUri.ToString()),
                       It.Is <ClientCredentialsTokenRequest>(x => x.ClientId == tokenRequest.ClientId)))
            .Returns(() => new JWTModel());

            // Setup class to be tested
            IMedicationRequestDelegate medDelegate = new SalesforeceDelegate(
                CreateLogger(),
                new Mock <IHttpClientService>().Object,
                configuration,
                mockAuthenticationDelegate.Object);

            // Test
            RequestResult <IList <MedicationRequest> > response = Task.Run(async() => await medDelegate.GetMedicationRequestsAsync(phn).ConfigureAwait(true)).Result;

            // Verify
            Assert.Equal(Common.Constants.ResultType.Error, response.ResultStatus);
            Assert.NotNull(response.ResultError);
            Assert.NotNull(response.ResultError?.ErrorCode);
        }
Beispiel #2
0
        public void ShouldRetrieveMedicationRequests()
        {
            // Setup

            // Input Parameters
            string phn = "9735361219";

            // Setup Configuration
            string endpoint = "https://test-endpoint";
            Uri    tokenUri = new Uri("https://localhost");
            ClientCredentialsTokenRequest tokenRequest = new ClientCredentialsTokenRequest()
            {
                ClientId     = "TEST_CLIENTID",
                ClientSecret = "TEST_CLIENT_SECRET",
                Password     = "******",
                Username     = "******",
            };
            Dictionary <string, string> configurationParams = new Dictionary <string, string>
            {
                { "Salesforce:Endpoint", endpoint },
                { "Salesforce:TokenUri", tokenUri.ToString() },
                { "Salesforce:ClientAuthentication:ClientId", tokenRequest.ClientId },
                { "Salesforce:ClientAuthentication:ClientSecret", tokenRequest.ClientSecret },
                { "Salesforce:ClientAuthentication:Username", tokenRequest.Username },
                { "Salesforce:ClientAuthentication:Password", tokenRequest.Password },
            };
            IConfiguration configuration = CreateConfiguration(configurationParams);

            // Setup Authentication
            string   jwtJson          = @"{ ""access_token"":""token"", ""expires_in"":500, ""refresh_expires_in"":0, ""refresh_token"":""refresh_token"", ""token_type"":""bearer"", ""not-before-policy"":25, ""session_state"":""session_state"", ""scope"":""scope"" }";
            JWTModel authorizationJWT = CreateJWTModel(jwtJson);

            Mock <IAuthenticationDelegate> mockAuthenticationDelegate = new Mock <IAuthenticationDelegate>();

            mockAuthenticationDelegate
            .Setup(s => s.AuthenticateAsUser(
                       It.Is <Uri>(x => x.ToString() == tokenUri.ToString()),
                       It.Is <ClientCredentialsTokenRequest>(x => x.ClientId == tokenRequest.ClientId)))
            .Returns(() => authorizationJWT);

            // Setup Http response
            using HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
                  {
                      StatusCode = HttpStatusCode.OK,
                      Content    = new StringContent("{\"items\":[{\"requestStatus\":\"Approved\",\"requestedDate\":\"2020-11-13T00:00:00.000Z\",\"referenceNumber\":\"00001046\",\"prescriberLastName\":\"Provider\",\"prescriberFirstName\":\"Test\",\"patientLastName\":null,\"patientIdentifier\":null,\"patientFirstName\":null,\"expiryDate\":null,\"effectiveDate\":null,\"drugName\":\"rabeprazole 10, 20 mg   NB4\"},{\"requestStatus\":\"Approved\",\"requestedDate\":\"2020-11-15T00:00:00.000Z\",\"referenceNumber\":\"00001048\",\"prescriberLastName\":null,\"prescriberFirstName\":null,\"patientLastName\":null,\"patientIdentifier\":null,\"patientFirstName\":null,\"expiryDate\":null,\"effectiveDate\":\"2021-02-17\",\"drugName\":\"abatacept w/e name here\"},{\"requestStatus\":\"Received\",\"requestedDate\":\"2020-11-15T00:00:00.000Z\",\"referenceNumber\":\"00001047\",\"prescriberLastName\":null,\"prescriberFirstName\":null,\"patientLastName\":null,\"patientIdentifier\":null,\"patientFirstName\":null,\"expiryDate\":null,\"effectiveDate\":null,\"drugName\":\"depakote sprinkle cap 125mg   (SAP)\"}]}"),
                  };
            Mock <IHttpClientService> mockHttpClient = CreateHttpClient(httpResponseMessage, phn, authorizationJWT?.AccessToken);

            // Setup class to be tested
            IMedicationRequestDelegate medDelegate = new SalesforeceDelegate(
                CreateLogger(),
                mockHttpClient.Object,
                configuration,
                mockAuthenticationDelegate.Object);

            // Test
            RequestResult <IList <MedicationRequest> > response = Task.Run(async() => await medDelegate.GetMedicationRequestsAsync(phn).ConfigureAwait(true)).Result;

            // Verify
            Assert.Equal(Common.Constants.ResultType.Success, response.ResultStatus);
            Assert.Equal(3, response.TotalResultCount);
            Assert.Equal(3, response.ResourcePayload?.Count);
        }
Beispiel #3
0
        public void ShouldEmptyIfNoContent()
        {
            // Setup

            // Input Parameters
            string phn = "9735361219";

            // Setup Configuration
            string endpoint = "https://test-endpoint";
            Uri    tokenUri = new Uri("https://localhost");
            ClientCredentialsTokenRequest tokenRequest = new ClientCredentialsTokenRequest()
            {
                ClientId     = "TEST_CLIENTID",
                ClientSecret = "TEST_CLIENT_SECRET",
                Password     = "******",
                Username     = "******",
            };
            Dictionary <string, string> configurationParams = new Dictionary <string, string>
            {
                { "Salesforce:Endpoint", endpoint },
                { "Salesforce:TokenUri", tokenUri.ToString() },
                { "Salesforce:ClientAuthentication:ClientId", tokenRequest.ClientId },
                { "Salesforce:ClientAuthentication:ClientSecret", tokenRequest.ClientSecret },
                { "Salesforce:ClientAuthentication:Username", tokenRequest.Username },
                { "Salesforce:ClientAuthentication:Password", tokenRequest.Password },
            };
            IConfiguration configuration = CreateConfiguration(configurationParams);

            // Setup Authentication
            string   jwtJson          = @"{ ""access_token"":""token"", ""expires_in"":500, ""refresh_expires_in"":0, ""refresh_token"":""refresh_token"", ""token_type"":""bearer"", ""not-before-policy"":25, ""session_state"":""session_state"", ""scope"":""scope"" }";
            JWTModel authorizationJWT = CreateJWTModel(jwtJson);

            Mock <IAuthenticationDelegate> mockAuthenticationDelegate = new Mock <IAuthenticationDelegate>();

            mockAuthenticationDelegate
            .Setup(s => s.AuthenticateAsUser(
                       It.Is <Uri>(x => x.ToString() == tokenUri.ToString()),
                       It.Is <ClientCredentialsTokenRequest>(x => x.ClientId == tokenRequest.ClientId)))
            .Returns(() => authorizationJWT);

            // Setup Http response
            using HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
                  {
                      StatusCode = HttpStatusCode.NoContent,
                  };
            Mock <IHttpClientService> mockHttpClient = CreateHttpClient(httpResponseMessage, phn, authorizationJWT?.AccessToken);

            // Setup class to be tested
            IMedicationRequestDelegate medDelegate = new SalesforeceDelegate(
                CreateLogger(),
                mockHttpClient.Object,
                configuration,
                mockAuthenticationDelegate.Object);

            // Test
            RequestResult <IList <MedicationRequest> > response = Task.Run(async() => await medDelegate.GetMedicationRequestsAsync(phn).ConfigureAwait(true)).Result;

            // Verify
            Assert.Equal(Common.Constants.ResultType.Success, response.ResultStatus);
            Assert.Null(response.ResultError);
            Assert.Null(response.ResultError?.ErrorCode);
            Assert.Equal(0, response.TotalResultCount);
        }