public void Setup()
        {
            _videoApiClientMock = new Mock <IVideoApiClient>();

            _eventHubContextMock = new Mock <IHubContext <EventHub.Hub.EventHub, IEventHubClient> >();
            _conferenceCacheMock = new Mock <IConferenceCache>();
            _eventHubClientMock  = new Mock <IEventHubClient>();
            _loggerMock          = new Mock <ILogger <ConsultationsController> >();

            _testConference = ConsultationHelper.BuildConferenceForTest();

            foreach (var participant in _testConference.Participants)
            {
                _eventHubContextMock.Setup(x => x.Clients.Group(participant.Username.ToLowerInvariant()))
                .Returns(_eventHubClientMock.Object);
            }

            _eventHubContextMock.Setup(x => x.Clients.Group(EventHub.Hub.EventHub.VhOfficersGroupName))
            .Returns(_eventHubClientMock.Object);

            _conferenceCacheMock.Setup(cache =>
                                       cache.GetOrAddConferenceAsync(_testConference.Id,
                                                                     It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(_testConference);

            _controller = SetupControllerWithClaims(null);
        }
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();
            var claimsPrincipal = new ClaimsPrincipalBuilder().Build();

            _testConference = ConsultationHelper.BuildConferenceForTest();

            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <StartPrivateConsultationRequest, StartConsultationRequest>()).Returns(_mocker.Create <StartPrivateConsultationRequestMapper>());

            _mocker.Mock <IConferenceCache>().Setup(cache =>
                                                    cache.GetOrAddConferenceAsync(_testConference.Id,
                                                                                  It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(_testConference);

            _mocker.Mock <IHubClients <IEventHubClient> >().Setup(x => x.Group(It.IsAny <string>())).Returns(_mocker.Mock <IEventHubClient>().Object);
            _mocker.Mock <IHubContext <EventHub.Hub.EventHub, IEventHubClient> >().Setup(x => x.Clients).Returns(_mocker.Mock <IHubClients <IEventHubClient> >().Object);

            _controller = _mocker.Create <ConsultationsController>();
            _controller.ControllerContext = context;
        }
Exemple #3
0
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();
            var claimsPrincipal = new ClaimsPrincipalBuilder().Build();

            _testConference = ConsultationHelper.BuildConferenceForTest();

            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <LockConsultationRoomRequest, LockRoomRequest>()).Returns(_mocker.Create <LockRoomRequestMapper>());

            _mocker.Mock <IConferenceCache>().Setup(cache =>
                                                    cache.GetOrAddConferenceAsync(_testConference.Id,
                                                                                  It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(_testConference);
            _sut = _mocker.Create <ConsultationsController>();
            _sut.ControllerContext = context;
        }
        public void Setup()
        {
            _videoApiClientMock = new Mock <IVideoApiClient>();
            var claimsPrincipal = new ClaimsPrincipalBuilder().Build();

            _eventHubContextMock = new Mock <IHubContext <EventHub.Hub.EventHub, IEventHubClient> >();
            _conferenceCacheMock = new Mock <IConferenceCache>();
            _testConference      = ConsultationHelper.BuildConferenceForTest();
            _loggerMock          = new Mock <ILogger <ConsultationsController> >();

            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _conferenceCacheMock.Setup(cache =>
                                       cache.GetOrAddConferenceAsync(_testConference.Id,
                                                                     It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(_testConference);
            _controller = new ConsultationsController(_videoApiClientMock.Object, _eventHubContextMock.Object,
                                                      _conferenceCacheMock.Object, _loggerMock.Object)
            {
                ControllerContext = context
            };
        }
        public async Task Should_return_accepted_when_request_is_sent_participant_room_type()
        {
            // Arrange
            var request = ConsultationHelper.GetStartParticipantConsultationRequest(_testConference);

            _mocker.Mock <IVideoApiClient>()
            .Setup(x => x.CreatePrivateConsultationAsync(It.IsAny <StartConsultationRequest>()))
            .ReturnsAsync(new RoomResponse {
                Label = "Room1", Locked = false
            });

            // Act
            var result = await _controller.StartConsultationAsync(request);

            // Assert
            result.Should().BeOfType <AcceptedResult>();
            _mocker.Mock <IVideoApiClient>()
            .Verify(x => x.CreatePrivateConsultationAsync(It.IsAny <StartConsultationRequest>()), Times.Once);

            _mocker.Mock <IConsultationNotifier>()
            .Verify(
                x => x.NotifyRoomUpdateAsync(_testConference, It.Is <Room>(r =>
                                                                           r.ConferenceId == _testConference.Id && r.Label == "Room1" && !r.Locked)), Times.Once);

            _mocker.Mock <IConsultationNotifier>()
            .Verify(
                x => x.NotifyConsultationRequestAsync(_testConference, "Room1", request.RequestedBy,
                                                      It.IsIn(request.InviteParticipants)), Times.Exactly(request.InviteParticipants.Length));
        }
Exemple #6
0
        public async Task Should_return_no_content_when_request_is_sent()
        {
            _mocker.Mock <IVideoApiClient>()
            .Setup(x => x.LeaveConsultationAsync(It.IsAny <LeaveConsultationRequest>()))
            .Returns(Task.FromResult(default(object)));

            var leaveConsultationRequest = ConsultationHelper.GetLeaveConsultationRequest(_testConference);
            var result = await _sut.LeaveConsultationAsync(leaveConsultationRequest);

            result.Should().BeOfType <NoContentResult>();
        }
Exemple #7
0
        public async Task Should_return_no_content_when_request_is_sent()
        {
            // Arrange
            var leaveConsultationRequest = ConsultationHelper.GetLeaveConsultationRequest(_testConference);

            // Act
            var result = await _sut.LeaveConsultationAsync(leaveConsultationRequest);

            // Assert
            _mocker.Mock <IVideoApiClient>().Verify(x => x.LeaveConsultationAsync(It.IsAny <LeaveConsultationRequest>()), Times.Once);
            result.Should().BeOfType <NoContentResult>();
        }
        public async Task Should_return_no_content_when_request_is_sent()
        {
            _videoApiClientMock
            .Setup(x => x.LeavePrivateConsultationAsync(It.IsAny <LeaveConsultationRequest>()))
            .Returns(Task.FromResult(default(object)));

            var leaveConsultationRequest = ConsultationHelper.GetLeaveConsultationRequest(_testConference);
            var result = await _controller.LeavePrivateConsultationAsync(leaveConsultationRequest);

            var typedResult = (NoContentResult)result;

            typedResult.Should().NotBeNull();
        }
        public async Task Should_return_accepted_when_request_is_sent()
        {
            // Arrange
            var request = ConsultationHelper.GetStartJohConsultationRequest(_testConference);

            // Act
            var result = await _controller.StartConsultationAsync(request);

            // Assert
            result.Should().BeOfType <AcceptedResult>();
            _mocker.Mock <IVideoApiClient>()
            .Verify(x => x.StartPrivateConsultationAsync(It.IsAny <StartConsultationRequest>()), Times.Once);
        }
        public async Task Should_return_no_content_when_request_is_sent()
        {
            // Arrange
            var request = ConsultationHelper.GetConsultationRequest(_testConference);
            // Act
            var result =
                await _controller.RespondToConsultationRequestAsync(request);

            // Assert
            result.Should().BeOfType <NoContentResult>();
            _mocker.Mock <IConsultationNotifier>()
            .Verify(
                x => x.NotifyConsultationResponseAsync(_testConference, request.RoomLabel,
                                                       request.RequestedForId, request.Answer), Times.Once);
        }
        public async Task Should_only_join_first_successful_endpoint_first_fail()
        {
            // Arrange
            var request = ConsultationHelper.GetStartParticipantConsultationRequest(_testConference);

            request.InviteEndpoints = new[] {
                _testConference.Endpoints[0].Id, // Wrong defense advocate username
                _testConference.Endpoints[1].Id, // Valid but mocked to throw
                _testConference.Endpoints[2].Id
            };                                   // Valid
            _mocker.Mock <IVideoApiClient>()
            .Setup(x => x.CreatePrivateConsultationAsync(It.IsAny <StartConsultationRequest>())).ReturnsAsync(new RoomResponse {
                Label = "Room1", Locked = false
            });
            var apiException = new VideoApiException <ProblemDetails>("Bad Request", (int)HttpStatusCode.BadRequest,
                                                                      "", null, default, null);
Exemple #12
0
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();

            _testConference = ConsultationHelper.BuildConferenceForTest();

            _mocker.Mock <IHubClients <IEventHubClient> >().Setup(x => x.Group(It.IsAny <string>())).Returns(_mocker.Mock <IEventHubClient>().Object);
            _mocker.Mock <IHubContext <EventHub.Hub.EventHub, IEventHubClient> >().Setup(x => x.Clients).Returns(_mocker.Mock <IHubClients <IEventHubClient> >().Object);

            _mocker.Mock <IConferenceCache>().Setup(cache =>
                                                    cache.GetOrAddConferenceAsync(_testConference.Id,
                                                                                  It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(_testConference);

            _sut = SetupControllerWithClaims(null);
        }
        public async Task Should_return_no_content_when_request_is_sent()
        {
            _videoApiClientMock
            .Setup(x => x.RespondToAdminConsultationRequestAsync(It.IsAny <AdminConsultationRequest>()))
            .Returns(Task.FromResult(default(object)));

            var result = await _controller.RespondToAdminConsultationRequestAsync(
                ConsultationHelper.GetAdminConsultationRequest(_testConference, ConsultationAnswer.None));

            var typedResult = (NoContentResult)result;

            typedResult.Should().NotBeNull();
            _eventHubClientMock.Verify(
                x => x.AdminConsultationMessage
                    (It.IsAny <Guid>(), It.IsAny <RoomType>(), It.IsAny <string>(), It.IsAny <ConsultationAnswer>()),
                Times.Never);
        }
        public async Task Should_only_join_first_successful_endpoint()
        {
            // Arrange
            var request = ConsultationHelper.GetStartParticipantConsultationRequest(_testConference);

            request.InviteEndpoints = new[]
            {
                _testConference.Endpoints[0].Id, // Wrong defense advocate username
                _testConference.Endpoints[1].Id, // Valid
                _testConference.Endpoints[2].Id
            };                                   // Shouldnt try
            _mocker.Mock <IVideoApiClient>()
            .Setup(x => x.CreatePrivateConsultationAsync(It.IsAny <StartConsultationRequest>()))
            .ReturnsAsync(new RoomResponse {
                Label = "Room1", Locked = false
            });

            // Act
            var result = await _controller.StartConsultationAsync(request);

            // Assert
            result.Should().BeOfType <AcceptedResult>();
            _mocker.Mock <IVideoApiClient>()
            .Verify(x => x.CreatePrivateConsultationAsync(It.IsAny <StartConsultationRequest>()), Times.Once);

            _mocker.Mock <IConsultationNotifier>()
            .Verify(
                x => x.NotifyRoomUpdateAsync(_testConference, It.Is <Room>(r =>
                                                                           r.ConferenceId == _testConference.Id && r.Label == "Room1" && !r.Locked)), Times.Once);

            _mocker.Mock <IConsultationNotifier>()
            .Verify(
                x => x.NotifyConsultationRequestAsync(_testConference, "Room1", request.RequestedBy,
                                                      It.IsIn(request.InviteParticipants)), Times.Exactly(request.InviteParticipants.Length));

            _mocker.Mock <IVideoApiClient>()
            .Verify(
                x => x.JoinEndpointToConsultationAsync(It.Is <EndpointConsultationRequest>(ecr =>
                                                                                           request.InviteEndpoints.Contains(ecr.EndpointId) && ecr.ConferenceId == _testConference.Id &&
                                                                                           ecr.RequestedById == request.RequestedBy)), Times.Once);
        }
 public async Task Should_return_bad_request()
 {
     // Arrange
     var request      = ConsultationHelper.GetConsultationRequest(_testConference);
     var apiException = new VideoApiException <ProblemDetails>("Bad Request", (int)HttpStatusCode.BadRequest,
                                                               "{\"ConsultationRoom\":[\"No consultation room available\"]}", null, default, null);