public async Task Handler_ShouldReturnIpo_IfMeetingIsNotFound() { using var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); { _meetingClientMock .Setup(x => x.GetMeetingAsync(It.IsAny <Guid>(), It.IsAny <Action <ODataQuery> >())) .Returns(Task.FromResult <GeneralMeeting>(null)); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); Assert.AreEqual(null, result.Data.Participants.First().FunctionalRole.Response); Assert.IsFalse(result.Data.CanEdit); } }
public async Task Handle_WhenHandlingGetInvitationByIdQueryAndInvitationIsFound_ThenShouldReturnGetInvitationByIdQueryResult( ProviderRegistrationsDbContext setupContext, Invitation invitation, GetInvitationByIdQueryHandler handler ) { //arrange setupContext.Invitations.Add(invitation); await setupContext.SaveChangesAsync(); var query = new GetInvitationByIdQuery(invitation.Reference); //act var result = await handler.Handle(query, new CancellationToken()); //assert result.Invitation.Should().NotBeNull(); result.Invitation.Should().BeEquivalentTo(new { invitation.Ukprn, invitation.EmployerFirstName, invitation.EmployerLastName, invitation.EmployerEmail, invitation.EmployerOrganisation, invitation.Status, SentDate = invitation.CreatedDate }); }
public async Task Handler_ShouldReturnIpo_IfUserIsNotInvitedToMeeting() { using var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); { _meetingClientMock .Setup(x => x.GetMeetingAsync(It.IsAny <Guid>(), It.IsAny <Action <ODataQuery> >())) .Throws(new Exception("Something failed")); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; AssertInvitation(invitationDto, _mdpInvitation); Assert.IsFalse(invitationDto.CanEdit); } }
public async Task Handler_ShouldReturnNullAsOutlookResponses_IfUserIsNotInvitedToMeeting() { using var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); { _meetingClientMock .Setup(x => x.GetMeetingAsync(It.IsAny <Guid>(), It.IsAny <Action <ODataQuery> >())) .Throws(new Exception("Something failed")); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var participants = result.Data.Participants.ToList(); Assert.AreEqual(null, participants.First().FunctionalRole.Response); Assert.AreEqual(null, participants[1].Person.Response); Assert.AreEqual(null, participants.Last().FunctionalRole.Response); Assert.AreEqual(null, participants.Last().FunctionalRole.Persons.First().Response); Assert.AreEqual(null, participants.Last().FunctionalRole.Persons.Last().Response); } }
public async Task Handler_ShouldReturnCorrectOutlookResponse() { using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var participants = result.Data.Participants.ToList(); Assert.AreEqual(OutlookResponse.Declined, participants.First().FunctionalRole.Response); Assert.AreEqual(OutlookResponse.None, participants[1].Person.Response); Assert.AreEqual(OutlookResponse.Accepted, participants.Last().FunctionalRole.Response); Assert.AreEqual(OutlookResponse.Accepted, participants.Last().FunctionalRole.Persons.First().Response); Assert.AreEqual(OutlookResponse.Declined, participants.Last().FunctionalRole.Persons.Last().Response); Assert.IsTrue(result.Data.CanEdit); } }
public async Task Handler_ShouldReturnWithCanEditAttendedStatusAndNotesForSignerWhenNotSigned() { var newCurrentUserOid = new Guid("11111111-2222-2222-2222-333333333332"); var currentUserProviderMock = new Mock <ICurrentUserProvider>(); currentUserProviderMock.Setup(x => x.GetCurrentUserOid()).Returns(newCurrentUserOid); using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var functionalRoleDetails = new ProCoSysFunctionalRole { Code = _functionalRoleCode2, Description = "FR description", Email = "*****@*****.**", InformationEmail = null, Persons = new List <ProCoSysPerson> { new ProCoSysPerson { AzureOid = newCurrentUserOid.ToString(), Email = "*****@*****.**", FirstName = "FN", LastName = "LN", UserName = "******" } }, UsePersonalEmail = true }; IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> { functionalRoleDetails }; _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, new List <string> { _functionalRoleCode2 })) .Returns(Task.FromResult(frDetails)); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, currentUserProviderMock.Object, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; Assert.IsFalse(invitationDto.Participants.First().CanEditAttendedStatusAndNote); Assert.IsFalse(invitationDto.Participants.ToList()[1].CanEditAttendedStatusAndNote); Assert.IsTrue(invitationDto.Participants.ToList()[2].CanEditAttendedStatusAndNote); } }
public async Task Handle_WhenHandlingGetInvitationByIdQueryAndInvitationIsNotFound_ThenShouldReturnNull( GetInvitationByIdQueryHandler handler, GetInvitationByIdQuery query) { //act var result = await handler.Handle(query, new CancellationToken()); //assert result.Should().BeNull(); }
public async Task Handler_ShouldReturnIpo_IfPersonsInFunctionalRoleHaveAzureOidNull() { using var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); { var functionalRoleDetails = new ProCoSysFunctionalRole { Code = _functionalRoleCode1, Description = "FR description", Email = "*****@*****.**", InformationEmail = null, Persons = new List <ProCoSysPerson> { new ProCoSysPerson { AzureOid = null, Email = "*****@*****.**", FirstName = "FN", LastName = "LN", UserName = "******" } }, UsePersonalEmail = true }; IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> { functionalRoleDetails }; _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, new List <string> { _functionalRoleCode1 })) .Returns(Task.FromResult(frDetails)); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; AssertInvitation(invitationDto, _mdpInvitation); } }
public async Task Handler_ShouldReturnNotFound_IfInvitationIsNotFound() { using var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); { const int UnknownId = 500; var query = new GetInvitationByIdQuery(UnknownId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.NotFound, result.ResultType); Assert.IsNull(result.Data); } }
public async Task Handler_ShouldReturnWithCannotEditAttendedStatusAndNotes_ForAdminCreator() { using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var invitation = context.Invitations.Single(inv => inv.Id == _mdpInvitationId); invitation.CancelIpo(new Person(_currentUserOid, "Ola", "N", "olan", "email")); context.SaveChangesAsync().Wait(); } using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { IList <string> ipoAdminPrivilege = new List <string> { "IPO/ADMIN" }; _permissionCacheMock .Setup(x => x.GetPermissionsForUserAsync(_plantProvider.Plant, _currentUserOid)) .Returns(Task.FromResult(ipoAdminPrivilege)); var query = new GetInvitationByIdQuery(_mdpInvitation.Id); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; Assert.IsTrue(invitationDto.Participants.All(participant => !participant.CanEditAttendedStatusAndNote)); Assert.IsTrue(invitationDto.CanDelete); Assert.IsFalse(invitationDto.CanCancel); } }
public async Task Handler_ShouldReturnCorrectDpInvitation() { using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var query = new GetInvitationByIdQuery(_dpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; AssertInvitation(invitationDto, _dpInvitation); } }
public async Task Handler_ShouldReturnWithCannotEditAttendedStatusAndNotesForContractorWhenCompleted() { var newCurrentUserOid = new Guid("11111111-2222-2222-2222-333333333339"); var currentUserProviderMock = new Mock <ICurrentUserProvider>(); currentUserProviderMock.Setup(x => x.GetCurrentUserOid()).Returns(newCurrentUserOid); using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var person = context.QuerySet <Person>().FirstAsync().Result; var invitation = context.Invitations.Include(i => i.Participants).Single(inv => inv.Id == _mdpInvitationId); invitation.CompleteIpo( invitation.Participants.First(), invitation.Participants.First().RowVersion.ConvertToString(), person, DateTime.Now); context.SaveChangesAsync().Wait(); } using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var functionalRoleDetails = new ProCoSysFunctionalRole { Code = _functionalRoleCode1, Description = "FR description", Email = "*****@*****.**", InformationEmail = null, Persons = new List <ProCoSysPerson> { new ProCoSysPerson { AzureOid = newCurrentUserOid.ToString(), Email = "*****@*****.**", FirstName = "FN", LastName = "LN", UserName = "******" } }, UsePersonalEmail = true }; IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> { functionalRoleDetails }; _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, new List <string> { _functionalRoleCode1 })) .Returns(Task.FromResult(frDetails)); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, currentUserProviderMock.Object, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var invitationDto = result.Data; Assert.IsFalse(invitationDto.Participants.All(participant => participant.CanEditAttendedStatusAndNote)); Assert.IsFalse(invitationDto.CanDelete); Assert.IsTrue(invitationDto.CanCancel); } }
public async Task Handler_ShouldReturnCorrectOutlookResponse2() { using (var context = new IPOContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { _meetingClientMock .Setup(x => x.GetMeetingAsync(It.IsAny <Guid>(), It.IsAny <Action <ODataQuery> >())) .Returns(Task.FromResult( new GeneralMeeting( new ApiGeneralMeeting() { Classification = string.Empty, Contract = null, Convention = string.Empty, DateCreatedUtc = DateTime.MinValue, DateEnd = new ApiDateTimeTimeZoneModel(), DateStart = new ApiDateTimeTimeZoneModel(), ExternalId = null, Id = _meetingId, InviteBodyHtml = string.Empty, IsDisabled = false, IsOnlineMeeting = false, Location = string.Empty, Organizer = new ApiPersonDetailsV1 { Id = _currentUserOid }, OutlookMode = string.Empty, Participants = new List <ApiMeetingParticipant>() { new ApiMeetingParticipant() { Id = Guid.NewGuid(), Person = new ApiPersonDetailsV1() { Id = Guid.NewGuid(), Mail = _personEmail1 }, OutlookResponse = "None" }, new ApiMeetingParticipant() { Id = Guid.NewGuid(), Person = new ApiPersonDetailsV1() { Id = Guid.NewGuid(), Mail = _frEmail1 }, OutlookResponse = "Accepted" }, new ApiMeetingParticipant() { Id = Guid.NewGuid(), Person = new ApiPersonDetailsV1() { Id = Guid.NewGuid(), Mail = _frPersonEmail1 }, OutlookResponse = "Declined" }, new ApiMeetingParticipant() { Id = Guid.NewGuid(), Person = new ApiPersonDetailsV1() { Id = Guid.NewGuid(), Mail = _frPersonEmail2 }, OutlookResponse = "None" } }, Project = null, ResponsiblePersons = new List <ApiPersonDetailsV1>(), Series = null, Title = string.Empty }))); var query = new GetInvitationByIdQuery(_mdpInvitationId); var dut = new GetInvitationByIdQueryHandler( context, _meetingClientMock.Object, _currentUserProvider, _functionalRoleApiServiceMock.Object, _plantProvider, _loggerMock.Object); var result = await dut.Handle(query, default); Assert.IsNotNull(result); Assert.AreEqual(ResultType.Ok, result.ResultType); var participants = result.Data.Participants.ToList(); Assert.AreEqual(OutlookResponse.Accepted, participants.First().FunctionalRole.Response); Assert.AreEqual(OutlookResponse.Organizer, participants[1].Person.Response); Assert.AreEqual(OutlookResponse.Declined, participants.Last().FunctionalRole.Response); Assert.AreEqual(OutlookResponse.Declined, participants.Last().FunctionalRole.Persons.First().Response); Assert.AreEqual(OutlookResponse.None, participants.Last().FunctionalRole.Persons.Last().Response); Assert.IsTrue(result.Data.CanEdit); } }