public async Task GetAuthenticatedClientUsingCustomAuthenticationAsync() { var baseEndpointUrl = "https://resource/"; var client = await BusinessClientExtensions.GetAuthenticatedClientUsingCustomAuthenticationAsync( baseEndpointUrl, this.authenticationProvider.Object, this.httpProvider.Object) as OneDriveClient; var clientServiceInfoProvider = client.serviceInfoProvider as ServiceInfoProvider; Assert.IsNotNull(clientServiceInfoProvider, "Unexpected service info provider initialized for client."); Assert.AreEqual(this.authenticationProvider.Object, clientServiceInfoProvider.AuthenticationProvider, "Unexpected authentication provider set."); Assert.AreEqual(this.httpProvider.Object, client.HttpProvider, "Unexpected HTTP provider set."); Assert.IsNull(client.credentialCache, "Unexpected credential cache set."); Assert.AreEqual( string.Format( Constants.Authentication.OneDriveBusinessBaseUrlFormatString, baseEndpointUrl.TrimEnd('/'), "v2.0"), client.BaseUrl, "Unexpected base service URL initialized."); this.authenticationProvider.Verify(provider => provider.AuthenticateAsync(), Times.Once); }
public async Task GetClientUsingCustomAuthentication_InitializeDefaults() { var baseEndpointUrl = "https://resource/"; var client = await BusinessClientExtensions.GetAuthenticatedClientUsingCustomAuthenticationAsync( baseEndpointUrl, this.authenticationProvider) as OneDriveClient; var clientServiceInfoProvider = client.serviceInfoProvider as ServiceInfoProvider; Assert.IsNotNull(clientServiceInfoProvider, "Unexpected service info provider initialized for client."); Assert.AreEqual(this.authenticationProvider, clientServiceInfoProvider.AuthenticationProvider, "Unexpected authentication provider set."); Assert.IsInstanceOfType(client.HttpProvider, typeof(HttpProvider), "Unexpected HTTP provider set."); Assert.IsNull(client.credentialCache, "Unexpected credential cache set."); Assert.AreEqual(ClientType.Business, client.ClientType, "Unexpected client type set."); }
public async Task GetAuthenticatedClientUsingCustomAuthenticationAsync_ServiceEndpointBaseUrlRequired() { try { var client = await BusinessClientExtensions.GetAuthenticatedClientUsingCustomAuthenticationAsync( /* serviceEndpointBaseUrl */ null, this.authenticationProvider.Object, this.httpProvider.Object); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.AuthenticationFailure.ToString(), exception.Error.Code, "Unexpected error thrown."); Assert.AreEqual("Service endpoint base URL is required when using custom authentication.", exception.Error.Message, "Unexpected error thrown."); throw; } }
public async Task GetAuthenticatedClientUsingCustomAuthenticationAsync_AuthenticationProviderRequired() { var baseEndpointUrl = "https://resource/"; try { var client = await BusinessClientExtensions.GetAuthenticatedClientUsingCustomAuthenticationAsync( baseEndpointUrl, /* authenticationProvider */ null, this.httpProvider.Object); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.AuthenticationFailure.ToString(), exception.Error.Code, "Unexpected error thrown."); Assert.AreEqual("An authentication provider is required for a client using custom authentication.", exception.Error.Message, "Unexpected error thrown."); throw; } }