protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                person = new ProCoSysPerson()
                {
                    AzureOid = "123456", FirstName = "F1", LastName = "F2", UserName = "******", Email = "*****@*****.**"
                };

                _functionalRoleApiServiceMock = new Mock <IFunctionalRoleApiService>();
                _libraryApiFunctionalRoles    = new List <ProCoSysFunctionalRole>
                {
                    new ProCoSysFunctionalRole()
                    {
                        Code = "C1", Description = "D1", Email = "*****@*****.**", InformationEmail = "*****@*****.**", UsePersonalEmail = true
                    },
                    new ProCoSysFunctionalRole
                    {
                        Code = "C2", Description = "D2", Email = "*****@*****.**", InformationEmail = "*****@*****.**", UsePersonalEmail = false, Persons = new List <ProCoSysPerson>()
                        {
                            person
                        }
                    }
                };

                _functionalRoleApiServiceMock
                .Setup(x => x.GetFunctionalRolesByClassificationAsync(TestPlant, _classification))
                .Returns(Task.FromResult(_libraryApiFunctionalRoles));

                _query = new GetFunctionalRolesForIpoQuery(_classification);
            }
        }
 private void AssertPersonData(ProCoSysPerson PCSPerson, ProCoSysPersonDto personDto)
 {
     Assert.AreEqual(PCSPerson.AzureOid, personDto.AzureOid);
     Assert.AreEqual(PCSPerson.FirstName, personDto.FirstName);
     Assert.AreEqual(PCSPerson.LastName, personDto.LastName);
     Assert.AreEqual(PCSPerson.UserName, personDto.UserName);
     Assert.AreEqual(PCSPerson.Email, personDto.Email);
 }
Пример #3
0
        public static List <BuilderParticipant> AddPersonToOutlookParticipantList(
            ProCoSysPerson person,
            List <BuilderParticipant> participants,
            bool required = true)
        {
            var participantType       = GetParticipantType(required);
            var participantIdentifier = CreateParticipantIdentifier(person);

            participants.Add(new BuilderParticipant(participantType, participantIdentifier));
            return(participants);
        }
Пример #4
0
        public void Setup()
        {
            _mainApiOptions = new Mock <IOptionsMonitor <MainApiOptions> >();
            _mainApiOptions
            .Setup(x => x.CurrentValue)
            .Returns(new MainApiOptions {
                ApiVersion = "4.0", BaseAddress = "http://example.com"
            });

            _foreignApiClient = new Mock <IBearerTokenApiClient>();

            _proCoSysPerson1 = new ProCoSysPerson {
                AzureOid  = "12345678-1234-123456789123",
                FirstName = "F1",
                LastName  = "L1",
                UserName  = "******",
                Email     = "E1"
            };
            _proCoSysPerson2 = new ProCoSysPerson {
                AzureOid  = "12345678-1235-123456789123",
                FirstName = "F2",
                LastName  = "L2",
                UserName  = "******",
                Email     = "E2"
            };
            _proCoSysPerson3 = new ProCoSysPerson {
                AzureOid  = "12345678-1236-123456789123",
                FirstName = "F3",
                LastName  = "L3",
                UserName  = "******",
                Email     = "E3"
            };

            _foreignApiClient
            .SetupSequence(x => x.QueryAndDeserializeAsync <List <ProCoSysPerson> >(It.IsAny <string>(), null))
            .Returns(Task.FromResult(new List <ProCoSysPerson> {
                _proCoSysPerson1, _proCoSysPerson2, _proCoSysPerson3
            }));

            _dut = new MainApiPersonService(_foreignApiClient.Object, _mainApiOptions.Object);
        }
Пример #5
0
        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);
        }
Пример #6
0
 private static ParticipantIdentifier CreateParticipantIdentifier(ProCoSysPerson person)
 => IsValidEmail(person.Email) ?
 new ParticipantIdentifier(person.Email) :
 new ParticipantIdentifier(new Guid(person.AzureOid));
Пример #7
0
        public void Setup()
        {
            _plantProviderMock = new Mock <IPlantProvider>();
            _plantProviderMock
            .Setup(x => x.Plant)
            .Returns(_plant);

            _personRepositoryMock = new Mock <IPersonRepository>();

            _meetingClientMock = new Mock <IFusionMeetingClient>();
            _meetingClientMock
            .Setup(x => x.UpdateMeetingAsync(_meetingId, It.IsAny <Action <GeneralMeetingPatcher> >()))
            .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
            })));

            _unitOfWorkMock = new Mock <IUnitOfWork>();

            //mock comm pkg response from main API
            var commPkgDetails = new ProCoSysCommPkg {
                CommPkgNo = _commPkgNo, Description = "D1", Id = 1, CommStatus = "OK", System = _system
            };
            IList <ProCoSysCommPkg> pcsCommPkgDetails = new List <ProCoSysCommPkg> {
                commPkgDetails
            };

            _commPkgApiServiceMock = new Mock <ICommPkgApiService>();
            _commPkgApiServiceMock
            .Setup(x => x.GetCommPkgsByCommPkgNosAsync(_plant, _projectName, _commPkgScope))
            .Returns(Task.FromResult(pcsCommPkgDetails));

            //mock mc pkg response from main API
            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 = _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));

            //mock person response from main API
            var personDetails = new ProCoSysPerson
            {
                AzureOid  = _azureOid.ToString(),
                FirstName = _firstName,
                LastName  = _lastName,
                Email     = "*****@*****.**",
                UserName  = "******"
            };
            var newPersonDetails = new ProCoSysPerson
            {
                AzureOid  = _newAzureOid.ToString(),
                FirstName = "Kari",
                LastName  = "Nordman",
                Email     = "*****@*****.**",
                UserName  = "******"
            };

            _personApiServiceMock = new Mock <IPersonApiService>();
            _personApiServiceMock
            .Setup(x => x.GetPersonByOidWithPrivilegesAsync(_plant,
                                                            _azureOid.ToString(), "IPO", new List <string> {
                "SIGN"
            }))
            .Returns(Task.FromResult(personDetails));
            _personApiServiceMock
            .Setup(x => x.GetPersonByOidWithPrivilegesAsync(_plant,
                                                            _newAzureOid.ToString(), "IPO", new List <string> {
                "SIGN"
            }))
            .Returns(Task.FromResult(newPersonDetails));

            //mock functional role response from main API
            var frDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleCode,
                Description      = "FR description",
                Email            = "*****@*****.**",
                InformationEmail = null,
                Persons          = null,
                UsePersonalEmail = false
            };
            var newFrDetails = new ProCoSysFunctionalRole
            {
                Code             = _newFunctionalRoleCode,
                Description      = "FR description2",
                Email            = "*****@*****.**",
                InformationEmail = null,
                Persons          = null,
                UsePersonalEmail = false
            };
            var frMultipleEmailsDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleWithMultipleEmailsCode,
                Description      = "FR description",
                Email            = "[email protected];[email protected]",
                InformationEmail = null,
                Persons          = null,
                UsePersonalEmail = false
            };
            var frMultipleInformationEmailsDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleWithMultipleInformationEmailsCode,
                Description      = "FR description",
                Email            = "*****@*****.**",
                InformationEmail = "[email protected];[email protected]",
                Persons          = null,
                UsePersonalEmail = false
            };
            IList <ProCoSysFunctionalRole> pcsFrDetails = new List <ProCoSysFunctionalRole> {
                frDetails
            };
            IList <ProCoSysFunctionalRole> newPcsFrDetails = new List <ProCoSysFunctionalRole> {
                newFrDetails
            };
            IList <ProCoSysFunctionalRole> pcsFrMultipleEmailsDetails = new List <ProCoSysFunctionalRole> {
                frMultipleEmailsDetails
            };
            IList <ProCoSysFunctionalRole> pcsFrMultipleInformationEmailsDetails = new List <ProCoSysFunctionalRole> {
                frMultipleInformationEmailsDetails
            };

            _functionalRoleApiServiceMock = new Mock <IFunctionalRoleApiService>();
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleCode
            }))
            .Returns(Task.FromResult(pcsFrDetails));
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _newFunctionalRoleCode
            }))
            .Returns(Task.FromResult(newPcsFrDetails));
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleWithMultipleEmailsCode
            }))
            .Returns(Task.FromResult(pcsFrMultipleEmailsDetails));
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleWithMultipleInformationEmailsCode
            }))
            .Returns(Task.FromResult(pcsFrMultipleInformationEmailsDetails));

            var mcPkgs = new List <McPkg>
            {
                new McPkg(_plant, _projectName, _commPkgNo, _mcPkgNo1, "d", _system),
                new McPkg(_plant, _projectName, _commPkgNo, _mcPkgNo2, "d2", _system)
            };

            //create invitation
            _dpInvitation = new Invitation(
                _plant,
                _projectName,
                _title,
                _description,
                _typeDp,
                new DateTime(),
                new DateTime(),
                null,
                mcPkgs,
                null)
            {
                MeetingId = _meetingId
            };

            var commPkgs = new List <CommPkg>
            {
                new CommPkg(_plant, _projectName, _commPkgNo, "d", "ok", _system),
                new CommPkg(_plant, _projectName, _commPkgNo, "d2", "ok", _system)
            };

            //create invitation
            _mdpInvitation = new Invitation(
                _plant,
                _projectName,
                _title,
                _description,
                _typeMdp,
                new DateTime(),
                new DateTime(),
                null,
                new List <McPkg>(),
                commPkgs)
            {
                MeetingId = _meetingId
            };
            _mdpInvitation.SetProtectedIdForTesting(_mdpInvitationId);

            var participant = new Participant(
                _plant,
                Organization.Contractor,
                IpoParticipantType.FunctionalRole,
                _functionalRoleCode,
                null,
                null,
                null,
                null,
                null,
                0);

            participant.SetProtectedIdForTesting(_participantId);
            _dpInvitation.AddParticipant(participant);
            _dpInvitation.AddParticipant(new Participant(
                                             _plant,
                                             Organization.ConstructionCompany,
                                             IpoParticipantType.Person,
                                             null,
                                             _firstName,
                                             _lastName,
                                             null,
                                             "*****@*****.**",
                                             _azureOid,
                                             1));
            _dpInvitation.SetProtectedIdForTesting(_dpInvitationId);

            _invitationRepositoryMock = new Mock <IInvitationRepository>();
            _invitationRepositoryMock
            .Setup(x => x.GetByIdAsync(_dpInvitationId))
            .Returns(Task.FromResult(_dpInvitation));

            _invitationRepositoryMock
            .Setup(x => x.GetByIdAsync(_mdpInvitationId))
            .Returns(Task.FromResult(_mdpInvitation));

            _meetingOptionsMock = new Mock <IOptionsMonitor <MeetingOptions> >();
            _meetingOptionsMock.Setup(x => x.CurrentValue)
            .Returns(new MeetingOptions {
                PcsBaseUrl = _plant
            });

            //command
            _command = new EditInvitationCommand(
                _dpInvitationId,
                _newTitle,
                _newDescription,
                null,
                new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc),
                _typeMdp,
                _updatedParticipants,
                null,
                _commPkgScope,
                _rowVersion);

            _dut = new EditInvitationCommandHandler(
                _invitationRepositoryMock.Object,
                _meetingClientMock.Object,
                _plantProviderMock.Object,
                _unitOfWorkMock.Object,
                _mcPkgApiServiceMock.Object,
                _commPkgApiServiceMock.Object,
                _personApiServiceMock.Object,
                _functionalRoleApiServiceMock.Object,
                _meetingOptionsMock.Object,
                _personRepositoryMock.Object);
        }
Пример #8
0
        public void Setup()
        {
            _plantProviderMock = new Mock <IPlantProvider>();
            _plantProviderMock
            .Setup(x => x.Plant)
            .Returns(_plant);

            _unitOfWorkMock = new Mock <IUnitOfWork>();

            _currentUserProviderMock = new Mock <ICurrentUserProvider>();
            _currentUserProviderMock
            .Setup(x => x.GetCurrentUserOid()).Returns(_azureOidForCurrentUser);


            //mock person response from main API
            var personDetails = new ProCoSysPerson
            {
                AzureOid  = _azureOidForCurrentUser.ToString(),
                FirstName = "Kari",
                LastName  = "Nordman",
                Email     = "*****@*****.**",
                UserName  = "******"
            };

            _personApiServiceMock = new Mock <IPersonApiService>();
            _personApiServiceMock
            .Setup(x => x.GetPersonInFunctionalRoleAsync(_plant,
                                                         _azureOidForCurrentUser.ToString(), _functionalRoleCode))
            .Returns(Task.FromResult(personDetails));

            //create invitation
            _invitation = new Invitation(
                _plant,
                _projectName,
                _title,
                _description,
                _typeDp,
                new DateTime(),
                new DateTime(),
                null,
                new List <McPkg> {
                new McPkg(_plant, _projectName, "Comm", "Mc", "d", "1|2")
            },
                null)
            {
                MeetingId = _meetingId
            };
            var participant = new Participant(
                _plant,
                Organization.Operation,
                IpoParticipantType.FunctionalRole,
                _functionalRoleCode,
                null,
                null,
                null,
                null,
                null,
                3);

            participant.SetProtectedIdForTesting(_participantId);
            _invitation.AddParticipant(participant);

            _invitationRepositoryMock = new Mock <IInvitationRepository>();
            _invitationRepositoryMock
            .Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(_invitation));

            var currentUser = new Person(_azureOidForCurrentUser, null, null, null, null);

            currentUser.SetProtectedIdForTesting(_participantId);

            _personRepositoryMock = new Mock <IPersonRepository>();
            _personRepositoryMock
            .Setup(x => x.GetByOidAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(currentUser));

            //command
            _command = new UpdateAttendedStatusOnParticipantCommand(
                _invitation.Id,
                _participantId,
                true,
                _participantRowVersion);

            _dut = new UpdateAttendedStatusOnParticipantCommandHandler(
                _invitationRepositoryMock.Object,
                _unitOfWorkMock.Object);
        }