private ApiContext CreateApiContext <TAuthProvider>() where TAuthProvider : IAuthorizationProvider, new() { var auth = new TAuthProvider().GetAuthentication(Configuration); var dokladConfig = new DokladConfiguration(Configuration.Urls.ApiUrl, Configuration.Urls.IdentityServerTokenUrl); return(new ApiContext("Tests", "1.0", auth, dokladConfig)); }
public void InvalidConfiguration_ThrowsException() { var auth = new ClientCredentialsAuthProvider().GetAuthentication(Configuration); var invalidApiUrl = Configuration.Urls.ApiUrl + "/dev/v3"; var dokladConfig = new DokladConfiguration(invalidApiUrl, Configuration.Urls.IdentityServerTokenUrl); var context = new ApiContext("Tests", "1.0", auth, dokladConfig); var api = new DokladApi(context); Assert.Throws <ValidationException>(() => api.ContactClient.List().Get()); }
public async Task GetToken_SucessfullyAsync() { // Arrange var auth = new PinAuthentication(Configuration.PinFlow.ClientId, Configuration.PinFlow.ClientSecret, Configuration.PinFlow.Pin, Configuration.PinFlow.RefreshToken); var config = new DokladConfiguration(Configuration.Urls.ApiUrl, Configuration.Urls.IdentityServerTokenUrl); auth.Configuration = config; // Act var token = await auth.RefreshAccessTokenAsync(); // Assert Assert.IsNotNull(token); Assert.That(token.AccessToken, Is.Not.Null.Or.Empty); }
public void GetToken_Sucessfully() { // Arrange var auth = new ClientCredentialsAuthentication(Configuration.ClientCredentials.ClientId, Configuration.ClientCredentials.ClientSecret); var config = new DokladConfiguration(Configuration.Urls.ApiUrl, Configuration.Urls.IdentityServerTokenUrl); auth.Configuration = config; // Act var token = auth.GetToken(); // Assert Assert.IsNotNull(token); Assert.That(token.AccessToken, Is.Not.Null.Or.Empty); }
public async Task Claims_ParsedSucessfullyAsync() { // Arrange var auth = new ClientCredentialsAuthentication(Configuration.ClientCredentials.ClientId, Configuration.ClientCredentials.ClientSecret); var config = new DokladConfiguration(Configuration.Urls.ApiUrl, Configuration.Urls.IdentityServerTokenUrl); auth.Configuration = config; // Act var token = await auth.GetTokenAsync(); // Assert Assert.IsNotNull(token); Assert.That(token.Claims, Is.Not.Null.And.Not.Empty); var tokenClaims = new TokenClaims(token.Claims); Assert.That(tokenClaims.LicenceStatus, Is.Not.Null); Assert.That(tokenClaims.UserRight, Is.Not.Null); }