public async Task Status_InvalidAuthToken_Fail() { var settings = new DialogsApiSettings("i'm invalid for sure"); using var dialogsApiService = new DialogsApiService(settings); var response = await dialogsApiService.StatusAsync().ConfigureAwait(false); Assert.False(response.IsSuccess); Assert.Contains("Unauthorized", response.ErrorMessage, StringComparison.OrdinalIgnoreCase); }
public async Task UploadImage_InvalidAuthToken_Fail() { var request = new DialogsWebUploadRequest(new Uri(_imageUrl)); var settings = new DialogsApiSettings("i'm invalid"); using var dialogsApiService = new DialogsApiService(settings); var response = await dialogsApiService.UploadImageAsync(_skillId, request).ConfigureAwait(false); Assert.False(response.IsSuccess); Assert.Contains("Unauthorized", response.ErrorMessage, StringComparison.OrdinalIgnoreCase); }
public DialogsApiFixture() { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddUserSecrets<DialogsApiFixture>() .Build(); var skillIdSection = configuration.GetSection("AliceSettings:SkillId"); AliceSettings = new AliceSettings(skillIdSection.Value); var apiSettings = new DialogsApiSettings(configuration.GetSection("AliceSettings:DialogsOAuthToken").Value); DialogsApiService = new DialogsApiService(apiSettings); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); string skillId = Configuration["AliceSettings:SkillId"]; var aliceSettings = new AliceSettings(skillId); var apiSettings = new DialogsApiSettings(Configuration["AliceSettings:DialogsOAuthToken"]); services.AddSingleton(apiSettings); services.AddSingleton <IDialogsApiService, DialogsApiService>(); services.AddSingleton(aliceSettings); services.AddSingleton <ICleanService, CleanService>(); services.AddHostedService <CleanResourcesWorker>(); }
public DialogsApiService(DialogsApiSettings dialogsApiSettings) { if (dialogsApiSettings == null) { throw new ArgumentNullException(nameof(dialogsApiSettings)); } if (string.IsNullOrEmpty(dialogsApiSettings.DialogsOAuthToken)) { throw new ArgumentException(Yandex_Alice_Sdk_Resources.Error_NoOAuthToken); } _dialogsApiClient = new HttpClient() { BaseAddress = new Uri("https://dialogs.yandex.net") }; _dialogsApiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", dialogsApiSettings.DialogsOAuthToken); }