public async Task HandlingCreateIpoCommand_ShouldThrowErrorIfCommPkgScopeIsNotFoundInMain() { IList <ProCoSysCommPkg> commPkgDetails = new List <ProCoSysCommPkg> { new ProCoSysCommPkg { CommPkgNo = _commPkgNo, Description = "D1", Id = 1, System = _system } }; var commPkgScope = new List <string> { _commPkgNo, _commPkgNo2 }; _commPkgApiServiceMock .Setup(x => x.GetCommPkgsByCommPkgNosAsync(_plant, _projectName, commPkgScope)) .Returns(Task.FromResult(commPkgDetails)); var command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, null, commPkgScope); var result = await Assert.ThrowsExceptionAsync <IpoValidationException>(() => _dut.Handle(command, default)); Assert.IsTrue(result.Message.StartsWith("Could not find all comm pkgs in scope")); }
public async Task HandlingCreateIpoCommand_ShouldThrowErrorIfMcScopeIsAcrossSystems() { var mcPkgDetails1 = new ProCoSysMcPkg { CommPkgNo = _commPkgNo, Description = "D1", Id = 1, McPkgNo = _mcPkgNo1, System = _system }; var mcPkgDetails2 = new ProCoSysMcPkg { CommPkgNo = _commPkgNo2, Description = "D2", Id = 2, McPkgNo = _mcPkgNo2, System = _system2 }; IList <ProCoSysMcPkg> mcPkgDetails = new List <ProCoSysMcPkg> { mcPkgDetails1, mcPkgDetails2 }; _mcPkgApiServiceMock .Setup(x => x.GetMcPkgsByMcPkgNosAsync(_plant, _projectName, _mcPkgScope)) .Returns(Task.FromResult(mcPkgDetails)); var command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, _mcPkgScope, null); var result = await Assert.ThrowsExceptionAsync <IpoValidationException>(() => _dut.Handle(command, default)); Assert.IsTrue(result.Message.StartsWith("Mc pkg scope must be within a system")); }
public async Task HandlingCreateIpoCommand_ShouldThrowErrorIfMcScopeIsNotFoundInMain() { IList <ProCoSysMcPkg> mcPkgDetails = new List <ProCoSysMcPkg> { _mcPkgDetails1 }; _mcPkgApiServiceMock .Setup(x => x.GetMcPkgsByMcPkgNosAsync(_plant, _projectName, _mcPkgScope)) .Returns(Task.FromResult(mcPkgDetails)); var command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, _mcPkgScope, null); var result = await Assert.ThrowsExceptionAsync <IpoValidationException>(() => _dut.Handle(command, default)); Assert.IsTrue(result.Message.StartsWith("Could not find all mc pkgs in scope")); }
public void Setup() { _invitationRepository = new Mock <IInvitationRepository>(); _invitationRepository.Setup(x => x.Get(ExpectedAccountId, ExpectedCallerEmail)).ReturnsAsync(null); _invitationRepository.Setup(x => x.Create(It.IsAny <Invitation>())).ReturnsAsync(ExpectedInvitationId); _membershipRepository = new Mock <IMembershipRepository>(); _membershipRepository.Setup(x => x.GetCaller(ExpectedHashedId, ExpectedExternalUserId)).ReturnsAsync(new MembershipView { AccountId = ExpectedAccountId, UserId = ExpectedUserId }); _userRepository = new Mock <IUserRepository>(); _userRepository.Setup(x => x.GetByEmailAddress(ExpectedExistingUserEmail)).ReturnsAsync(new User { Email = ExpectedExistingUserEmail, UserRef = Guid.NewGuid().ToString() }); _mediator = new Mock <IMediator>(); _validator = new Mock <IValidator <CreateInvitationCommand> >(); _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateInvitationCommand>())).ReturnsAsync(new ValidationResult()); _configuration = new EmployerApprenticeshipsServiceConfiguration(); _handler = new CreateInvitationCommandHandler(_invitationRepository.Object, _membershipRepository.Object, _mediator.Object, _configuration, _validator.Object, _userRepository.Object); _command = new CreateInvitationCommand { HashedAccountId = ExpectedHashedId, Email = ExpectedCallerEmail, Name = "Test User", RoleId = Role.Owner, ExternalUserId = ExpectedExternalUserId }; DateTimeProvider.Current = new FakeTimeProvider(DateTime.UtcNow); }
public void Validate_ShouldFail_WhenFunctinalRoleIsInvalid() { var participants = new List <ParticipantsForCommand> { new ParticipantsForCommand( Organization.Contractor, null, null, new InvitedFunctionalRoleForCreateCommand("F", null), 0), new ParticipantsForCommand( Organization.ConstructionCompany, null, new InvitedPersonForCreateCommand(null, "*****@*****.**", true), null, 1), new ParticipantsForCommand( Organization.External, new InvitedExternalEmailForCreateCommand("*****@*****.**"), null, null, -3) }; _invitationValidatorMock.Setup(inv => inv.IsValidParticipantList(participants)).Returns(true); _invitationValidatorMock.Setup(inv => inv.RequiredParticipantsMustBeInvited(participants)).Returns(true); _invitationValidatorMock.Setup(inv => inv.OnlyRequiredParticipantsHaveLowestSortKeys(participants)).Returns(true); var command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, participants, null, _commPkgScope); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith($"Functional role code must be between 3 and {Participant.FunctionalRoleCodeMaxLength} characters!")); }
public async Task HandleCreateInvitationCommand_ShouldNotFailWhenAFunctionalRoleHasMultipleEmailsInInformationEmailField() { // Setup var participants = new List <ParticipantsForCommand> { new ParticipantsForCommand( Organization.Contractor, null, null, new InvitedFunctionalRoleForCreateCommand(_functionalRoleWithMultipleInformationEmailsCode, null), 0), new ParticipantsForCommand( Organization.ConstructionCompany, null, new InvitedPersonForCreateCommand(_azureOid, "*****@*****.**", true), null, 1) }; var command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, participants, _mcPkgScope, null); await _dut.Handle(command, default); // Assert Assert.IsNotNull(_createdInvitation); _unitOfWorkMock.Verify(t => t.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Exactly(2)); var invitationParticipants = _createdInvitation.Participants.Select(p => p).ToList(); Assert.AreEqual(invitationParticipants.Count, 2); Assert.AreEqual(invitationParticipants[0].FunctionalRoleCode, _functionalRoleWithMultipleInformationEmailsCode); _transactionMock.Verify(t => t.RollbackAsync(It.IsAny <CancellationToken>()), Times.Never); }
public void Arrange() { _createInvitationCommand = new CreateInvitationCommand { EmailOfPersonBeingInvited = "so'*****@*****.**", ExternalUserId = "123", HashedAccountId = "123dfg", NameOfPersonBeingInvited = "Test", RoleOfPersonBeingInvited = Role.Owner }; _membershipRepository = new Mock <IMembershipRepository>(); _membershipRepository.Setup(x => x.GetCaller(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(new MembershipView { Role = Role.Owner }); _membershipRepository.Setup(x => x.Get(It.IsAny <long>(), It.IsAny <string>())).ReturnsAsync(new TeamMember { IsUser = false }); _validator = new CreateInvitationCommandValidator(_membershipRepository.Object); }
public void Setup_OkState() { _invitationValidatorMock = new Mock <IInvitationValidator>(); _invitationValidatorMock.Setup(inv => inv.IsValidScope(_type, new List <string>(), _commPkgScope)).Returns(true); _invitationValidatorMock.Setup(inv => inv.IsValidParticipantList(_participants)).Returns(true); _invitationValidatorMock.Setup(inv => inv.RequiredParticipantsMustBeInvited(_participants)).Returns(true); _invitationValidatorMock.Setup(inv => inv.OnlyRequiredParticipantsHaveLowestSortKeys(_participants)).Returns(true); _command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, null, _commPkgScope); _dut = new CreateInvitationCommandValidator(_invitationValidatorMock.Object); }
public async Task ValidateAsync_OnCreateInvitationCommand_ShouldReturnTrue_WhenAccessToProject() { // Arrange var command = new CreateInvitationCommand( null, null, null, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectWithAccess, DisciplineType.DP, null, null, null); // act var result = await _dut.ValidateAsync(command); // Assert Assert.IsTrue(result); }
public void Constructor_SetsProperties() { var dut = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, _mcPkgScope, null); Assert.AreEqual(_participants, dut.Participants); Assert.AreEqual(_title, dut.Title); Assert.AreEqual(_description, dut.Description); Assert.AreEqual(_location, dut.Location); Assert.AreEqual(new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), dut.StartTime); Assert.AreEqual(new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), dut.EndTime); Assert.AreEqual(2, dut.Participants.Count()); Assert.AreEqual(_participants.First(), dut.Participants.First()); }
public void Setup() { _plantProviderMock = new Mock <IPlantProvider>(); _plantProviderMock .Setup(x => x.Plant) .Returns(_plant); _currentUserProviderMock = new Mock <ICurrentUserProvider>(); _personRepositoryMock = new Mock <IPersonRepository>(); _meetingClientMock = new Mock <IFusionMeetingClient>(); _meetingClientMock .Setup(x => x.CreateMeetingAsync(It.IsAny <Action <GeneralMeetingBuilder> >())) .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(), OutlookMode = string.Empty, Participants = new List <ApiMeetingParticipant>(), Project = null, ResponsiblePersons = new List <ApiPersonDetailsV1>(), Series = null, Title = string.Empty }))); _invitationRepositoryMock = new Mock <IInvitationRepository>(); _invitationRepositoryMock .Setup(x => x.Add(It.IsAny <Invitation>())) .Callback <Invitation>(x => _createdInvitation = x); _transactionMock = new Mock <IDbContextTransaction>(); _unitOfWorkMock = new Mock <IUnitOfWork>(); _unitOfWorkMock.Setup(x => x.BeginTransaction(It.IsAny <CancellationToken>())) .Returns(Task.FromResult(_transactionMock.Object)); _commPkgApiServiceMock = new Mock <ICommPkgApiService>(); _mcPkgDetails1 = new ProCoSysMcPkg { CommPkgNo = _commPkgNo, Description = "D1", Id = 1, McPkgNo = _mcPkgNo1, System = _system }; _mcPkgDetails2 = new ProCoSysMcPkg { CommPkgNo = _commPkgNo, Description = "D2", Id = 2, McPkgNo = _mcPkgNo2, System = _system }; IList <ProCoSysMcPkg> mcPkgDetails = new List <ProCoSysMcPkg> { _mcPkgDetails1, _mcPkgDetails2 }; _mcPkgApiServiceMock = new Mock <IMcPkgApiService>(); _mcPkgApiServiceMock .Setup(x => x.GetMcPkgsByMcPkgNosAsync(_plant, _projectName, _mcPkgScope)) .Returns(Task.FromResult(mcPkgDetails)); _personDetails = new ProCoSysPerson { AzureOid = _azureOid.ToString(), FirstName = "Ola", LastName = "Nordman", Email = "*****@*****.**" }; _personApiServiceMock = new Mock <IPersonApiService>(); _personApiServiceMock .Setup(x => x.GetPersonByOidWithPrivilegesAsync(_plant, _azureOid.ToString(), "IPO", new List <string> { "SIGN" })) .Returns(Task.FromResult(_personDetails)); _functionalRoleDetails = new ProCoSysFunctionalRole { Code = _functionalRoleCode, Description = "FR description", Email = "*****@*****.**", InformationEmail = null, Persons = null, UsePersonalEmail = false }; _functionalRoleWithMultipleEmailsDetails = new ProCoSysFunctionalRole { Code = _functionalRoleWithMultipleEmailsCode, Description = "FR description", Email = "[email protected];[email protected]", InformationEmail = null, Persons = null, UsePersonalEmail = false }; _functionalRoleWithMultipleInformationEmailsDetails = new ProCoSysFunctionalRole { Code = _functionalRoleWithMultipleInformationEmailsCode, Description = "FR description", Email = "*****@*****.**", InformationEmail = "[email protected];[email protected]", Persons = null, UsePersonalEmail = false }; IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> { _functionalRoleDetails }; IList <ProCoSysFunctionalRole> frMultipleEmailsDetails = new List <ProCoSysFunctionalRole> { _functionalRoleWithMultipleEmailsDetails }; IList <ProCoSysFunctionalRole> frMultipleInformationDetails = new List <ProCoSysFunctionalRole> { _functionalRoleWithMultipleInformationEmailsDetails }; _functionalRoleApiServiceMock = new Mock <IFunctionalRoleApiService>(); _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> { _functionalRoleCode })) .Returns(Task.FromResult(frDetails)); _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> { _functionalRoleWithMultipleEmailsCode })) .Returns(Task.FromResult(frMultipleEmailsDetails)); _functionalRoleApiServiceMock .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> { _functionalRoleWithMultipleInformationEmailsCode })) .Returns(Task.FromResult(frMultipleInformationDetails)); _meetingOptionsMock = new Mock <IOptionsMonitor <MeetingOptions> >(); _command = new CreateInvitationCommand( _title, _description, _location, new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc), new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc), _projectName, _type, _participants, _mcPkgScope, null); _dut = new CreateInvitationCommandHandler( _plantProviderMock.Object, _meetingClientMock.Object, _invitationRepositoryMock.Object, _unitOfWorkMock.Object, _commPkgApiServiceMock.Object, _mcPkgApiServiceMock.Object, _personApiServiceMock.Object, _functionalRoleApiServiceMock.Object, _meetingOptionsMock.Object, _personRepositoryMock.Object, _currentUserProviderMock.Object, new Mock <ILogger <CreateInvitationCommandHandler> >().Object); }
public async Task <IActionResult> Invitation(CreateInvitationCommand command) { await Mediator.Send(command); return(NoContent()); }