public async Task should_return_accepted_if_user_is_in_consultation() { // Arrange var cp = new ClaimsPrincipalBuilder().WithRole(AppRoles.RepresentativeRole) .WithUsername("*****@*****.**").Build(); _sut = SetupControllerWithClaims(cp); var request = new InviteToConsultationRequest { ConferenceId = _testConference.Id, ParticipantId = _testConference.Participants[0].Id, RoomLabel = "Room1" }; // Act var result = await _sut.InviteToConsultationAsync(request); // Assert result.Should().BeOfType <AcceptedResult>(); _mocker.Mock <IConsultationNotifier>() .Verify( x => x.NotifyConsultationRequestAsync(_testConference, "Room1", _testConference.Participants[2].Id, _testConference.Participants[0].Id), Times.Once); }
public void ConsultationsController_GetConsultations_ConsultationsRetrievalOk() { List <Patient> newPatients = CreatTestPatients(); var controller = new PatientController { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; foreach (var patient in newPatients) { var response = controller.RegisterPatient(patient); Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } var consulationController = new ConsultationsController { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var result = consulationController.GetConsultations(); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); //Clear registered patients so that individual unit test has control over patient and consultation data. PatientSchedulerContext.Patients.Clear(); PatientSchedulerContext.Consultations.Clear(); }
public ConsultationsControllerTests() { SeedData(); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var mockMapper = new MapperConfiguration(cfg => cfg.AddProfile(new MappingProfile())); var mapper = mockMapper.CreateMapper(); var userManager = MockUserManager.GetMockUserManager(_fakeIdentityUsers).Object; var signInManager = MockSigninManager.GetSignInManager <IdentityUser>(userManager).Object; IdentityRepositoryFake = new IdentityRepository(userManager, signInManager, config); var fakeGenericRepo = MockGenericRepository.GetUserInformationMock(_fakeEntities); var patientRepo = MockGenericRepository.GetUserInformationMock(_patients); var fakeGenericRepoUserInformationMock = MockGenericRepository.GetUserInformationMock(_fakeUsersInformation); MockUserExtension.ExtendMock(fakeGenericRepoUserInformationMock, _fakeUsersInformation); MockGenericExtension.ExtendMock(fakeGenericRepo, _fakeEntities); FakeController = new ConsultationsController(IdentityRepositoryFake, fakeGenericRepo.Object, fakeGenericRepoUserInformationMock.Object, patientRepo.Object, mapper); IdentityHelper.SetUser(_fakeIdentityUsers[0], FakeController); }
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 = new ConferenceCacheModelBuilder().WithLinkedParticipantsInRoom().Build(); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = claimsPrincipal } }; _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 <IMapperFactory>().Setup(x => x.Get <PrivateConsultationRequest, ConsultationRequestResponse>()).Returns(_mocker.Create <PrivateConsultationRequestMapper>()); _mocker.Mock <IMapperFactory>().Setup(x => x.Get <Dictionary <string, string[]>, BadRequestModelResponse>()).Returns(_mocker.Create <BadRequestResponseMapper>()); _mocker.Mock <IMapperFactory>().Setup(x => x.Get <LeavePrivateConsultationRequest, LeaveConsultationRequest>()).Returns(_mocker.Create <LeavePrivateConsultationRequestMapper>()); _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); _controller = _mocker.Create <ConsultationsController>(); _controller.ControllerContext = context; }
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 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; }
public void GetConsultationsForRegisteredPatients_ShouldReturnAllConsultation() { var testPatients = GetTestPatients(); var patientsController = new PatientsController(testPatients); foreach (var patient in testPatients) { patientsController.RegisterPatient(patient); } var consulationController = new ConsultationsController(); var resultResponse = consulationController.GetAllScheduledConsultations(); Assert.AreEqual(resultResponse.StatusCode, HttpStatusCode.Created); }
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_not_found_if_defence_advocate_is_not_found() { var cp = new ClaimsPrincipalBuilder().WithRole(AppRoles.RepresentativeRole) .WithUsername("*****@*****.**").Build(); _controller = SetupControllerWithClaims(cp); var request = new PrivateVideoEndpointConsultationRequest { ConferenceId = _testConference.Id, EndpointId = _testConference.Endpoints.First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocateUsername)) .Id }; var result = await _controller.CallVideoEndpointAsync(request); var actionResult = result.As <NotFoundObjectResult>(); actionResult.Should().NotBeNull(); }
public async Task should_return_unauthorized_if_user_is_not_in_conference_or_vh_officer() { // Arrange var cp = new ClaimsPrincipalBuilder().WithRole(AppRoles.RepresentativeRole) .WithUsername("*****@*****.**").Build(); _sut = SetupControllerWithClaims(cp); var request = new InviteToConsultationRequest { ConferenceId = _testConference.Id, ParticipantId = _testConference.Participants[0].Id, RoomLabel = "Room1" }; // Act var result = await _sut.InviteToConsultationAsync(request); // Assert result.Should().BeOfType <UnauthorizedObjectResult>(); }