public void AddStreamRecorderAsync_Throws_AudioPlatformException_On_Http_Failure() { // Case 1 var wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{nameof(Exception)}.com/") }); var client = wowzaHttpClient; var exception = Assert.ThrowsAsync <Exception> ( () => client.AddStreamRecorderAsync ( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() ) ); exception.Message.Should().Be("Exception thrown"); // Case 2 wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{HttpStatusCode.BadRequest}.com/") }); exception = Assert.ThrowsAsync <AudioPlatformException> ( () => wowzaHttpClient.AddStreamRecorderAsync ( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() ) ); exception.Message.Should().Be("Bad request"); }
public async Task GetApplicationsDisgnosticsAsync_Success() { // Case 1 var wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{HttpStatusCode.OK}.com/") }); var result = await wowzaHttpClient.GetDiagnosticsAsync ( It.IsAny <string>() ); result.Should().NotBeNull(); }
public async Task MonitoringStreamRecorderAsync_Success() { // Case 1 var wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{HttpStatusCode.OK}.com/") }); var result = await wowzaHttpClient.MonitoringStreamRecorderAsync ( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() ); result.Should().NotBeNull(); }
public void UpdateApplicationAsync_Success() { // Case 1 var wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{HttpStatusCode.OK}.com/") }); var result = wowzaHttpClient.UpdateApplicationAsync ( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() ); result.IsCompleted.Should().BeTrue(); result.IsFaulted.Should().BeFalse(); }
public void DeleteApplicationAsync_Throws_AudioPlatformException_On_Http_Failure() { // Case 1 var wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{nameof(Exception)}.com/") }); var exception = Assert.ThrowsAsync <Exception> ( () => wowzaHttpClient.DeleteApplicationAsync ( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>() ) ); exception.Message.Should().Be("Exception thrown"); }
public void GetApplicationsDisgnosticsAsync_Throws_AudioPlatformException_On_Http_Failure() { WowzaHttpClient wowzaHttpClient; Exception exception; // Case 1 wowzaHttpClient = new WowzaHttpClient(new HttpClient(new FakeHttpMessageHandler()) { BaseAddress = new Uri($"http://{nameof(Exception)}.com/") }); exception = Assert.ThrowsAsync <Exception> ( () => wowzaHttpClient.GetDiagnosticsAsync ( It.IsAny <string>() ) ); exception.Message.Should().Be("Exception thrown"); }
public static IServiceCollection AddCustomTypes(this IServiceCollection services, IWebHostEnvironment environment, bool useStub) { var container = services.BuildServiceProvider(); var servicesConfiguration = container.GetService <IOptions <ServicesConfiguration> >().Value; var wowzaConfiguration = container.GetService <IOptions <WowzaConfiguration> >().Value; var cvpConfiguration = container.GetService <IOptions <CvpConfiguration> >().Value; services.AddMemoryCache(); services.AddScoped <ILoggingDataExtractor, LoggingDataExtractor>(); services.AddScoped <IRoomReservationService, RoomReservationService>(); services.AddScoped <ITokenProvider, AzureTokenProvider>(); services.AddTransient <UserApiTokenHandler>(); services.AddSingleton <ITelemetryInitializer, BadRequestTelemetry>(); services.AddScoped <IQueryHandlerFactory, QueryHandlerFactory>(); services.AddScoped <IQueryHandler, QueryHandler>(); services.AddScoped <ICommandHandlerFactory, CommandHandlerFactory>(); services.AddScoped <ICommandHandler, CommandHandler>(); services.AddScoped <IEventHandlerFactory, EventHandlerFactory>(); services.AddTransient <KinlyApiTokenDelegatingHandler>(); services.AddTransient <KinlySelfTestApiDelegatingHandler>(); services.AddSingleton <IPollyRetryService, PollyRetryService>(); RegisterCommandHandlers(services); RegisterQueryHandlers(services); RegisterEventHandlers(services); if (useStub) { services.AddScoped <IVideoPlatformService, KinlyPlatformServiceStub>(); services.AddScoped <IAudioPlatformService, AudioPlatformServiceStub>(); } else { services .AddHttpClient <IKinlyApiClient, KinlyApiClient>() .AddTypedClient(httpClient => BuildKinlyClient(servicesConfiguration.KinlyApiUrl, httpClient)) .AddHttpMessageHandler <KinlyApiTokenDelegatingHandler>(); foreach (var restApiEndpoint in wowzaConfiguration.RestApiEndpoints) { var handler = new HttpClientHandler { Credentials = new CredentialCache { { new Uri(restApiEndpoint), "Digest", new NetworkCredential(wowzaConfiguration.Username, wowzaConfiguration.Password) } } }; var client = new WowzaHttpClient(new HttpClient(handler) { BaseAddress = new Uri(restApiEndpoint), DefaultRequestHeaders = { { "Accept", "application/json" }, { "ContentType", "application/json" } } }); services.AddSingleton <IWowzaHttpClient>(client); } services .AddHttpClient <IKinlySelfTestHttpClient, KinlySelfTestHttpClient>() .AddHttpMessageHandler <KinlySelfTestApiDelegatingHandler>(); services.AddScoped <IVideoPlatformService, KinlyPlatformService>(); services.AddScoped <IAudioPlatformService, AudioPlatformService>(); } services.AddScoped <ICustomJwtTokenHandler, CustomJwtTokenHandler>(); services.AddScoped <ICustomJwtTokenProvider, CustomJwtTokenProvider>(); if (environment.IsDevelopment()) { var vhBlobServiceClient = new BlobServiceClient(new Uri(wowzaConfiguration.StorageEndpoint), new StorageSharedKeyCredential(wowzaConfiguration.StorageAccountName, wowzaConfiguration.StorageAccountKey)); var cvpBlobServiceClient = new BlobServiceClient(new Uri(cvpConfiguration.StorageEndpoint), new StorageSharedKeyCredential(cvpConfiguration.StorageAccountName, cvpConfiguration.StorageAccountKey)); services.AddSingleton <IAzureStorageService>(x => new VhAzureStorageService(vhBlobServiceClient, wowzaConfiguration, false)); services.AddSingleton <IAzureStorageService>(x => new CvpAzureStorageService(cvpBlobServiceClient, cvpConfiguration, false)); } else { var vhBlobServiceClient = new BlobServiceClient(new Uri(wowzaConfiguration.StorageEndpoint), new ChainedTokenCredential(new ManagedIdentityCredential(wowzaConfiguration.ManagedIdentityClientId), new DefaultAzureCredential())); var cvpBlobServiceClient = new BlobServiceClient(new Uri(cvpConfiguration.StorageEndpoint), new ChainedTokenCredential(new ManagedIdentityCredential(cvpConfiguration.ManagedIdentityClientId), new DefaultAzureCredential())); services.AddSingleton <IAzureStorageService>(x => new VhAzureStorageService(vhBlobServiceClient, wowzaConfiguration, true)); services.AddSingleton <IAzureStorageService>(x => new CvpAzureStorageService(cvpBlobServiceClient, cvpConfiguration, true)); } services.AddSingleton <IAzureStorageServiceFactory, AzureStorageServiceFactory>(); return(services); }