public async Task Should_get_tasks_by_conference_id()
        {
            var taskResponse = new List <TaskResponse>()
            {
                new TaskResponse()
                {
                    Body      = "Body",
                    Created   = DateTime.UtcNow,
                    Id        = new long(),
                    OriginId  = Guid.NewGuid(),
                    Status    = TaskStatus.ToDo,
                    Type      = TaskType.Participant,
                    Updated   = null,
                    UpdatedBy = null
                }
            };

            VideoApiClient
            .Setup(x => x.GetTasksForConferenceAsync(It.IsAny <Guid>()))
            .ReturnsAsync(taskResponse);

            var response = await Controller.GetTasksByConferenceId(Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var tasksResponse = (List <TaskResponse>)result.Value;

            tasksResponse.Should().NotBeNull();
            tasksResponse.Should().BeEquivalentTo(taskResponse);
        }
コード例 #2
0
        private async Task <bool> PollForConferenceDeleted(Guid hearingRefId)
        {
            var policy = Policy
                         .HandleResult <ConferenceDetailsResponse>(e => e != null)
                         .WaitAndRetryAsync(Retries, retryAttempt =>
                                            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            try
            {
                var conferenceResponse = await policy.ExecuteAsync(async() =>
                                                                   await VideoApiClient.GetConferenceByHearingRefIdAsync(hearingRefId, false));

                if (conferenceResponse != null)
                {
                    return(false);
                }
            }
            catch (VideoApiException e)
            {
                if (e.StatusCode == (int)HttpStatusCode.NotFound)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"Encountered error '{e.Message}' after {Math.Pow(2, Retries +1)} seconds.");
            }

            return(true);
        }
コード例 #3
0
        public async Task Should_create_conference(TestType testType)
        {
            var firstUser  = CreateUser(UserType.Judge);
            var secondUser = CreateUser(UserType.Individual);
            var thirdUser  = CreateUser(UserType.Representative);
            var fourthUser = CreateUser(UserType.CaseAdmin);

            var users = new List <UserDto> {
                firstUser, secondUser, thirdUser, fourthUser
            };

            var request = new BookConferenceRequestBuilder(users, testType).BuildRequest();

            var conferenceDetailsResponse = new ConferenceDetailsResponseBuilder(request).BuildResponse();

            VideoApiClient
            .Setup(x => x.BookNewConferenceAsync(It.IsAny <BookNewConferenceRequest>()))
            .ReturnsAsync(conferenceDetailsResponse);

            var response = await Controller.BookNewConference(request);

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.Created);

            var hearingDetails = (ConferenceDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(conferenceDetailsResponse);
        }
        public async Task Should_get_audio_recording_link()
        {
            var audioLinkResponse = new AudioRecordingResponse()
            {
                AudioFileLinks = new List <string>()
                {
                    "http://link-to-file"
                }
            };

            VideoApiClient
            .Setup(x => x.GetAudioRecordingLinkAsync(It.IsAny <Guid>()))
            .ReturnsAsync(audioLinkResponse);

            var response = await Controller.GetAudioRecordingLinksByHearingId(Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var recordingDetails = (AudioRecordingResponse)result.Value;

            recordingDetails.Should().NotBeNull();
            recordingDetails.Should().BeEquivalentTo(audioLinkResponse);
        }
コード例 #5
0
        public async Task Should_delete_hearings()
        {
            var request = new DeleteTestHearingDataRequest()
            {
                PartialHearingCaseName = "Test"
            };

            var idsResponse = new List <Guid>()
            {
                Guid.NewGuid()
            };

            BookingsApiService
            .Setup(x => x.DeleteHearingsByPartialCaseText(It.IsAny <DeleteTestHearingDataRequest>()))
            .ReturnsAsync(idsResponse);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            var response = await Controller.DeleteTestDataByPartialCaseText(request);

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var deletionDetails = (DeletedResponse)result.Value;

            deletionDetails.NumberOfDeletedHearings.Should().Be(1);
        }
コード例 #6
0
        public async Task Should_get_self_test_score()
        {
            var selfTestResponse = new TestCallScoreResponse()
            {
                Passed = true,
                Score  = TestScore.Good
            };

            VideoApiClient
            .Setup(x => x.GetTestCallResultForParticipantAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(selfTestResponse);

            var response = await Controller.GetSelfTestScore(Guid.NewGuid(), Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var conferenceDetails = (TestCallScoreResponse)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(selfTestResponse);
        }
コード例 #7
0
        public void RegisterServices(IServiceCollection services, IConfiguration configuration)
        {
            var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));

            services.AddSingleton <IMemoryCache>(memoryCache);
            services.Configure <AzureAdConfiguration>(options =>
            {
                configuration.GetSection("AzureAd").Bind(options);
            });
            services.Configure <ServicesConfiguration>(options =>
            {
                configuration.GetSection("VhServices").Bind(options);
            });

            var serviceConfiguration = new ServicesConfiguration();

            configuration.GetSection("VhServices").Bind(serviceConfiguration);

            services.AddScoped <IAzureTokenProvider, AzureTokenProvider>();
            services.AddScoped <IMessageHandlerFactory, MessageHandlerFactory>();
            services.AddTransient <VideoServiceTokenHandler>();
            services.AddTransient <VideoWebTokenHandler>();
            services.AddLogging(builder =>
                                builder.AddApplicationInsights(configuration["ApplicationInsights:InstrumentationKey"])
                                );
            RegisterMessageHandlers(services);

            var container = services.BuildServiceProvider();

            if (serviceConfiguration.EnableVideoApiStub)
            {
                services.AddScoped <IVideoApiService, VideoApiServiceFake>();
                services.AddScoped <IVideoWebService, VideoWebServiceFake>();
            }
            else
            {
                services.AddScoped <IVideoApiService, VideoApiService>();
                services.AddHttpClient <IVideoApiClient, VideoApiClient>()
                .AddHttpMessageHandler(() => container.GetService <VideoServiceTokenHandler>())
                .AddTypedClient(httpClient =>
                {
                    var client     = VideoApiClient.GetClient(httpClient);
                    client.BaseUrl = serviceConfiguration.VideoApiUrl;
                    client.ReadResponseAsString = true;
                    return((IVideoApiClient)client);
                });

                services.AddTransient <IVideoWebService, VideoWebService>();
                services.AddHttpClient <IVideoWebService, VideoWebService>(client =>
                {
                    client.BaseAddress = new Uri(serviceConfiguration.VideoWebUrl);
                }).AddHttpMessageHandler(() => container.GetService <VideoWebTokenHandler>());
            }
        }
        public async Task Should_return_not_found_for_non_existent_conference_id()
        {
            VideoApiClient
            .Setup(x => x.GetConferenceDetailsByIdAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("Conference not found", HttpStatusCode.NotFound));

            var response = await Controller.GetConferenceById(Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_delete_participant()
        {
            VideoApiClient
            .Setup(x => x.RemoveParticipantFromConferenceAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            var response = await Controller.DeleteParticipant(Guid.NewGuid(), Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
        public async Task Should_return_not_found_for_non_existent_hearing_id()
        {
            VideoApiClient
            .Setup(x => x.GetAudioRecordingLinkAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("No hearing found", HttpStatusCode.NotFound));

            var response = await Controller.GetAudioRecordingLinksByHearingId(Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_return_not_found_if_Judge_does_not_exist()
        {
            VideoApiClient
            .Setup(x => x.GetConferencesTodayForJudgeByUsernameAsync(It.IsAny <string>()))
            .ThrowsAsync(CreateVideoApiException("Judge does not exist", HttpStatusCode.NotFound));

            var response = await Controller.GetConferencesForTodayJudge(EmailData.NON_EXISTENT_USERNAME);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
コード例 #12
0
        public async Task Should_return_not_found_for_non_existent_conference_and_participant_ids()
        {
            VideoApiClient
            .Setup(x => x.GetTestCallResultForParticipantAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("Conference not found", HttpStatusCode.NotFound));

            var response = await Controller.GetSelfTestScore(Guid.NewGuid(), Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
コード例 #13
0
        private void InitApiClient(TestContext context)
        {
            NUnit.Framework.TestContext.Out.WriteLine("Initialising API Client");
            var bookingsHttpClient = new HttpClient();

            bookingsHttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("bearer", context.Tokens.BookingsApiBearerToken);
            BookingApiClient = BookingsApiClient.GetClient(context.Config.Services.BookingsApiUrl, bookingsHttpClient);

            var videoHttpClient = new HttpClient();

            videoHttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("bearer", context.Tokens.VideoApiBearerToken);
            VideoApiClient = VideoApiClient.GetClient(context.Config.Services.VideoApiUrl, videoHttpClient);
        }
コード例 #14
0
        public async Task Should_create_event()
        {
            var request = new ConferenceEventRequestBuilder()
                          .WithEventType(EventType.None)
                          .Build();

            VideoApiClient
            .Setup(x => x.RaiseVideoEventAsync(It.IsAny <ConferenceEventRequest>()))
            .Returns(Task.CompletedTask);

            var response = await Controller.CreateEvent(request);

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
        public async Task Should_delete_conference_without_deleting_audio_application_with_no_audio_application()
        {
            VideoApiClient
            .Setup(x => x.RemoveConferenceAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException($"No audio application found to delete with hearing id ", HttpStatusCode.NotFound));

            var response = await Controller.DeleteConference(Guid.NewGuid(), Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
        private async Task <ConferenceDetailsResponse> PollForConferenceParticipantUpdated(Guid hearingRefId, Guid participantId, string updatedText)
        {
            var policy = Policy
                         .HandleResult <ConferenceDetailsResponse>(conf => !conf.Participants.First(x => x.RefId == participantId).DisplayName.Contains(updatedText))
                         .WaitAndRetryAsync(Retries, retryAttempt =>
                                            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            try
            {
                var conferenceResponse = await policy.ExecuteAsync(async() => await VideoApiClient.GetConferenceByHearingRefIdAsync(hearingRefId, false));

                conferenceResponse.CaseName.Should().NotBeNullOrWhiteSpace();
                return(conferenceResponse);
            }
            catch (Exception e)
            {
                throw new Exception($"Encountered error '{e.Message}' after {Math.Pow(2, Retries +1)} seconds.");
            }
        }
        public async Task Should_return_empty_list_if_no_tasks_exists()
        {
            VideoApiClient
            .Setup(x => x.GetTasksForConferenceAsync(It.IsAny <Guid>()))
            .ReturnsAsync(new List <TaskResponse>());

            var response = await Controller.GetTasksByConferenceId(Guid.NewGuid());

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var tasksResponse = (List <TaskResponse>)result.Value;

            tasksResponse.Should().NotBeNull();
            tasksResponse.Count.Should().Be(0);
        }
        private async Task <ConferenceDetailsResponse> PollForConferenceParticipantPresence(Guid hearingRefId, string username, bool expected)
        {
            var policy = Policy
                         .HandleResult <ConferenceDetailsResponse>(conf => conf.Participants.Any(p => p.Username == username) != expected)
                         .WaitAndRetryAsync(Retries, retryAttempt =>
                                            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            try
            {
                var conferenceResponse = await policy.ExecuteAsync(async() =>
                                                                   await VideoApiClient.GetConferenceByHearingRefIdAsync(hearingRefId, false));

                conferenceResponse.CaseName.Should().NotBeNullOrWhiteSpace();
                return(conferenceResponse);
            }
            catch (Exception e)
            {
                throw new Exception($"Encountered error '{e.Message}' after {Math.Pow(2, Retries +1)} seconds.");
            }
        }
コード例 #19
0
        public async Task Should_delete_hearing_without_removing_audio_application_with_no_audio_application()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("No audio application found", HttpStatusCode.NotFound));

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
コード例 #20
0
        public async Task Should_delete_hearing()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
コード例 #21
0
        private async Task <ConferenceDetailsResponse> GetUpdatedConferenceDetailsPollingAsync(Guid hearingRefId)
        {
            var policy = Policy
                         .HandleResult <ConferenceDetailsResponse>(conf => conf != null)
                         .OrResult(conf => !conf.HearingVenueName.Contains(HearingData.UPDATED_TEXT))
                         .WaitAndRetryAsync(Retries, retryAttempt =>
                                            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

            try
            {
                var conferenceResponse = await policy.ExecuteAsync(async() => await VideoApiClient.GetConferenceByHearingRefIdAsync(hearingRefId, false));

                conferenceResponse.CaseName.Should().NotBeNullOrWhiteSpace();
                return(conferenceResponse);
            }
            catch (Exception e)
            {
                throw new Exception($"Encountered error '{e.Message}' after {Math.Pow(2, Retries +1)} seconds.");
            }
        }
        public async Task Should_get_conference_by_conference_id()
        {
            var conferenceDetailsResponse = CreateConferenceDetailsResponse();

            VideoApiClient
            .Setup(x => x.GetConferenceDetailsByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(conferenceDetailsResponse);

            var response = await Controller.GetConferenceById(conferenceDetailsResponse.Id);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var conferenceDetails = (ConferenceDetailsResponse)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(conferenceDetailsResponse);
        }
コード例 #23
0
        public async Task Should_return_bad_request_with_video_api_internal_error()
        {
            var idsResponse = new List <Guid>()
            {
                Guid.NewGuid()
            };

            BookingsApiService
            .Setup(x => x.DeleteHearingsByPartialCaseText(It.IsAny <DeleteTestHearingDataRequest>()))
            .ReturnsAsync(idsResponse);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("Request failed", HttpStatusCode.BadRequest));

            var response = await Controller.DeleteTestDataByPartialCaseText(new DeleteTestHearingDataRequest());

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
コード例 #24
0
        public async Task Should_get_conferences_for_today_vho()
        {
            var conferenceDetailsResponse = CreateConferenceDetailsResponse();
            var vhoResponse = ConferenceRequestToAdminTodayMapper.Map(conferenceDetailsResponse);

            VideoApiClient
            .Setup(x => x.GetConferencesTodayForAdminByHearingVenueNameAsync(It.IsAny <List <string> >()))
            .ReturnsAsync(vhoResponse);

            var response = await Controller.GetConferencesForTodayVho();

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var conferenceDetails = (List <ConferenceForAdminResponse>)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(vhoResponse);
        }
コード例 #25
0
        public async Task Should_throw_bad_request_with_invalid_request()
        {
            var firstUser  = CreateUser(UserType.Judge);
            var secondUser = CreateUser(UserType.Individual);
            var thirdUser  = CreateUser(UserType.Representative);
            var fourthUser = CreateUser(UserType.CaseAdmin);

            var users = new List <UserDto> {
                firstUser, secondUser, thirdUser, fourthUser
            };

            var request = new BookConferenceRequestBuilder(users, TestType.Automated).BuildRequest();

            VideoApiClient
            .Setup(x => x.BookNewConferenceAsync(It.IsAny <BookNewConferenceRequest>()))
            .ThrowsAsync(CreateVideoApiException("Conference details missing", HttpStatusCode.BadRequest));

            var response = await Controller.BookNewConference(request);

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public async Task Should_get_conferences_for_today_judge()
        {
            var conferenceDetailsResponse = CreateConferenceDetailsResponse();
            var judge         = conferenceDetailsResponse.Participants.First(x => x.UserRole == UserRole.Judge);
            var judgeResponse = ConferenceRequestToJudgeTodayMapper.Map(conferenceDetailsResponse);

            VideoApiClient
            .Setup(x => x.GetConferencesTodayForJudgeByUsernameAsync(It.IsAny <string>()))
            .ReturnsAsync(judgeResponse);

            var response = await Controller.GetConferencesForTodayJudge(judge.Username);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var conferenceDetails = (List <ConferenceForJudgeResponse>)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(judgeResponse);
        }
コード例 #27
0
        public static IServiceCollection AddCustomTypes(this IServiceCollection serviceCollection)
        {
            serviceCollection.AddHttpContextAccessor();
            serviceCollection.AddMemoryCache();
            serviceCollection.AddTransient <HearingApiTokenHandler>();
            serviceCollection.AddTransient <UserApiTokenHandler>();
            serviceCollection.AddTransient <VideoApiTokenHandler>();
            serviceCollection.AddTransient <NotificationApiTokenHandler>();
            serviceCollection.AddTransient <IHearingsService, HearingsService>();
            serviceCollection.AddScoped <ITokenProvider, TokenProvider>();
            serviceCollection.AddScoped <IUserAccountService, UserAccountService>();
            serviceCollection.AddScoped <AzureAdConfiguration>();
            serviceCollection.AddSingleton <IClaimsCacheProvider, MemoryClaimsCacheProvider>();
            serviceCollection.AddScoped <ICachedUserClaimBuilder, CachedUserClaimBuilder>();
            serviceCollection.AddSingleton <IPollyRetryService, PollyRetryService>();

            // Build the hearings api client using a reusable HttpClient factory and predefined base url
            var container = serviceCollection.BuildServiceProvider();
            var settings  = container.GetService <IOptions <ServiceConfiguration> >().Value;

            serviceCollection.AddHttpClient <IBookingsApiClient, BookingsApiClient>()
            .AddHttpMessageHandler(() => container.GetService <HearingApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = BookingsApiClient.GetClient(httpClient);
                client.BaseUrl = settings.BookingsApiUrl;
                client.ReadResponseAsString = true;
                return((IBookingsApiClient)client);
            });

            serviceCollection.AddHttpClient <IUserApiClient, UserApiClient>()
            .AddHttpMessageHandler(() => container.GetService <UserApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = UserApiClient.GetClient(httpClient);
                client.BaseUrl = settings.UserApiUrl;
                client.ReadResponseAsString = true;
                return((IUserApiClient)client);
            });

            serviceCollection.AddHttpClient <IVideoApiClient, VideoApiClient>()
            .AddHttpMessageHandler(() => container.GetService <VideoApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = VideoApiClient.GetClient(httpClient);
                client.BaseUrl = settings.VideoApiUrl;
                client.ReadResponseAsString = true;
                return((IVideoApiClient)client);
            });

            serviceCollection.AddHttpClient <INotificationApiClient, NotificationApiClient>()
            .AddHttpMessageHandler(() => container.GetService <NotificationApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = NotificationApiClient.GetClient(httpClient);
                client.BaseUrl = settings.NotificationApiUrl;
                client.ReadResponseAsString = true;
                return((INotificationApiClient)client);
            });

            serviceCollection.AddHttpClient <IPublicHolidayRetriever, UkPublicHolidayRetriever>();
            serviceCollection.AddTransient <IUserIdentity, UserIdentity>((ctx) =>
            {
                var userPrincipal = ctx.GetService <IHttpContextAccessor>().HttpContext.User;

                return(new UserIdentity(userPrincipal));
            });

            serviceCollection.AddSingleton <IValidator <EditHearingRequest>, EditHearingRequestValidator>();

            return(serviceCollection);
        }
コード例 #28
0
ファイル: Startup.cs プロジェクト: hmcts/vh-scheduler-jobs
        public void RegisterServices(IServiceCollection services, IConfiguration configuration)
        {
            var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));

            services.AddSingleton <IMemoryCache>(memoryCache);
            services.Configure <AzureAdConfiguration>(options =>
            {
                configuration.GetSection("AzureAd").Bind(options);
            });
            services.Configure <ServicesConfiguration>(options =>
            {
                configuration.GetSection("VhServices").Bind(options);
            });

            var serviceConfiguration = new ServicesConfiguration();

            configuration.GetSection("VhServices").Bind(serviceConfiguration);

            services.AddScoped <IAzureTokenProvider, AzureTokenProvider>();

            services.AddLogging(builder =>
                                builder.AddApplicationInsights(configuration["ApplicationInsights:InstrumentationKey"])
                                );

            services.AddScoped <ICloseConferenceService, CloseConferenceService>();
            services.AddScoped <IClearConferenceChatHistoryService, ClearConferenceChatHistoryService>();
            services.AddScoped <IAnonymiseHearingsConferencesDataService, AnonymiseHearingsConferencesDataService>();
            services.AddScoped <IRemoveHeartbeatsForConferencesService, RemoveHeartbeatsForConferencesService>();

            bool.TryParse(configuration["UseELinksStub"], out var useELinksStub);

            if (useELinksStub)
            {
                services.AddScoped <IELinksService, ELinksServiceStub>();
            }
            else
            {
                services.AddScoped <IELinksService, ELinksService>();
                services.AddTransient <ELinksApiDelegatingHandler>();
                services.AddHttpClient <IPeoplesClient, PeoplesClient>()
                .AddHttpMessageHandler <ELinksApiDelegatingHandler>()
                .AddTypedClient(httpClient =>
                {
                    var peoplesClient = new PeoplesClient(httpClient)
                    {
                        BaseUrl = serviceConfiguration.ELinksPeoplesBaseUrl
                    };
                    return((IPeoplesClient)peoplesClient);
                });
                services.AddHttpClient <ILeaversClient, LeaversClient>()
                .AddHttpMessageHandler <ELinksApiDelegatingHandler>()
                .AddTypedClient(httpClient =>
                {
                    var leaversClient = new LeaversClient(httpClient)
                    {
                        BaseUrl = serviceConfiguration.ELinksLeaversBaseUrl
                    };
                    return((ILeaversClient)leaversClient);
                });
            }

            services.AddTransient <VideoServiceTokenHandler>();
            services.AddTransient <BookingsServiceTokenHandler>();
            services.AddTransient <UserServiceTokenHandler>();

            services.AddHttpClient <IVideoApiClient, VideoApiClient>()
            .AddHttpMessageHandler <VideoServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = VideoApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.VideoApiUrl;
                client.ReadResponseAsString = true;
                return((IVideoApiClient)client);
            });

            services.AddHttpClient <IBookingsApiClient, BookingsApiClient>()
            .AddHttpMessageHandler <BookingsServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = BookingsApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.BookingsApiUrl;
                client.ReadResponseAsString = true;
                return((IBookingsApiClient)client);
            });

            services.AddHttpClient <IUserApiClient, UserApiClient>()
            .AddHttpMessageHandler <UserServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = UserApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.UserApiUrl;
                client.ReadResponseAsString = true;
                return((IUserApiClient)client);
            });
        }
コード例 #29
0
 private static IVideoApiClient BuildVideoApiClient(HttpClient httpClient,
                                                    HearingServicesConfiguration serviceSettings)
 {
     return(VideoApiClient.GetClient(serviceSettings.VideoApiUrl, httpClient));
 }