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)); }
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)); }
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); }
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); }
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); }
public void GetRestClient_IfParametersIsNull_ThrowsException() { var restClientWrapper = new SDK.Utilities.RestClientWrapper.RestClientWrapper(); Assert.Catch(() => restClientWrapper.GetRestClient(null)); }