コード例 #1
0
        public void GetRestClient_IfUrlIsInvalid_ThrowsException(string baseUrl)
        {
            var wrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(It.IsAny <RestClientCredentials>());
            var restClientParameters = new RestClientParameters {
                BaseUrl = baseUrl
            };

            Assert.Catch <Exception>(() => wrapper.GetRestClient(restClientParameters));
        }
コード例 #2
0
        public void GetRestClient_IDataFormatDoesNotExist_ThrowsException(DataFormat responseDataFormat)
        {
            var wrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(It.IsAny <RestClientCredentials>());
            var restClientParameters = new RestClientParameters
            {
                BaseUrl            = TestValidUrl,
                ResponseDataFormat = responseDataFormat,
            };

            Assert.Catch(() => wrapper.GetRestClient(restClientParameters));
        }
コード例 #3
0
        public void GetRestClient_IfUrlIsValid_ReturnsCorrectlyWithInitializedUrl(string baseUrl)
        {
            var wrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(It.IsAny <RestClientCredentials>());
            var restClientParameters = new RestClientParameters {
                BaseUrl = baseUrl
            };

            var result = wrapper.GetRestClient(restClientParameters);

            Assert.AreEqual(restClientParameters.BaseUrl, result.BaseUrl.OriginalString);
        }
コード例 #4
0
        public void GetRestClient_IfAuthenticatorCannotBeCreated_ReturnsCorrectlyWithAuthenticatorAsNull(
            RestClientCredentials credentials)
        {
            var wrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(credentials);
            var restClientParameters = new RestClientParameters {
                BaseUrl = TestValidUrl
            };

            var result = wrapper.GetRestClient(restClientParameters);

            Assert.Null(result.Authenticator);
        }
コード例 #5
0
        public void GetRestClient_IfAuthenticatorCanBeCreated_ReturnsCorrectlyWithAuthenticator(
            RestClientCredentials credentials,
            IAuthenticator expectedAuthenticator,
            string expectedHeader)
        {
            var wrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(credentials);
            var restClientParameters = new RestClientParameters {
                BaseUrl = TestValidUrl
            };
            var request = new RestRequest();

            var result = wrapper.GetRestClient(restClientParameters);

            result.Authenticator?.Authenticate(It.IsAny <IRestClient>(), request);

            Assert.IsInstanceOf(expectedAuthenticator.GetType(), result.Authenticator);
            var authParam = request.Parameters.FirstOrDefault(x =>
                                                              x.Type == ParameterType.HttpHeader && x.Name == "Authorization");

            Assert.NotNull(authParam);
            Assert.AreEqual(expectedHeader, authParam.Value);
        }
コード例 #6
0
        public void GetRestClient_IfParametersIsNull_ThrowsException()
        {
            var restClientWrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper();

            Assert.Catch(() => restClientWrapper.GetRestClient(null));
        }