コード例 #1
0
        public async Task Handle_ShouldSendEmail()
        {
            // Arrange
            var objectGuid = Guid.NewGuid();
            var plant      = "TestPlant";
            var commpkgs   = new List <CommPkg>
            {
                new CommPkg(plant, "project", "commpkgno", "description", "status", "system|subsystem")
            };
            var invitation = new Invitation(plant, "project", "title", "description", DisciplineType.MDP, DateTime.Now,
                                            DateTime.Now, "location", null, commpkgs);

            invitation.AddParticipant(new Participant(plant, Organization.ConstructionCompany,
                                                      IpoParticipantType.Person, "code", "firstname", "lastname", "username", "email", Guid.NewGuid(), 1));
            var emails = new List <string>()
            {
                "*****@*****.**", "*****@*****.**"
            };
            var ipoCompletedEvent = new IpoCompletedEvent(plant, objectGuid, invitation.Id, invitation.Title, emails);

            // Act
            await _dut.Handle(ipoCompletedEvent, default);

            // Assert
            _emailServiceMock.Verify(
                t => t.SendEmailsAsync(It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()),
                Times.Once());
        }
        private List <BuilderParticipant> AddPersonParticipantsWithoutOids(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            List <ParticipantsForCommand> personsParticipantsWithEmail)
        {
            foreach (var participant in personsParticipantsWithEmail)
            {
                //This code will only hit for users that do not have and azure oid (which all users should have).
                //Therefore, insert null for names - no endpoint in main is created to retrieve info from users based on email
                invitation.AddParticipant(new Participant(
                                              _plantProvider.Plant,
                                              participant.Organization,
                                              IpoParticipantType.Person,
                                              null,
                                              null,
                                              null,
                                              null,
                                              participant.InvitedPerson.Email,
                                              null,
                                              participant.SortKey));
                meetingParticipants.Add(new BuilderParticipant(ParticipantType.Required,
                                                               new ParticipantIdentifier(participant.InvitedPerson.Email)));
            }

            return(meetingParticipants);
        }
        private async Task <List <BuilderParticipant> > AddPersonParticipantsWithOidsAsync(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            List <ParticipantsForCommand> personParticipantsWithOids)
        {
            var personsAdded = new List <ParticipantsForCommand>();

            foreach (var participant in personParticipantsWithOids)
            {
                if (InvitationHelper.ParticipantIsSigningParticipant(participant))
                {
                    meetingParticipants = await AddSigner(
                        invitation,
                        meetingParticipants,
                        participant.InvitedPerson,
                        participant.SortKey,
                        participant.Organization);

                    personsAdded.Add(participant);
                }
            }

            personParticipantsWithOids.RemoveAll(p => personsAdded.Contains(p));

            var oids    = personParticipantsWithOids.Where(p => p.SortKey > 1).Select(p => p.InvitedPerson.AzureOid.ToString()).ToList();
            var persons = oids.Count > 0
                ? await _personApiService.GetPersonsByOidsAsync(_plantProvider.Plant, oids)
                : new List <ProCoSysPerson>();

            if (persons.Any())
            {
                foreach (var participant in personParticipantsWithOids)
                {
                    var person = persons.SingleOrDefault(p => p.AzureOid == participant.InvitedPerson.AzureOid.ToString());
                    if (person != null)
                    {
                        invitation.AddParticipant(new Participant(
                                                      _plantProvider.Plant,
                                                      participant.Organization,
                                                      IpoParticipantType.Person,
                                                      null,
                                                      person.FirstName,
                                                      person.LastName,
                                                      person.UserName,
                                                      person.Email,
                                                      new Guid(person.AzureOid),
                                                      participant.SortKey));
                        meetingParticipants = InvitationHelper.AddPersonToOutlookParticipantList(person, meetingParticipants);
                    }
                }
            }

            return(meetingParticipants);
        }
        private async Task <List <BuilderParticipant> > AddSigner(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            IList <Participant> existingParticipants,
            InvitedPersonForEditCommand person,
            int sortKey,
            Organization organization)
        {
            var personFromMain = await _personApiService.GetPersonByOidWithPrivilegesAsync(_plantProvider.Plant,
                                                                                           person.AzureOid.ToString(), _objectName, _signerPrivileges);

            if (personFromMain != null)
            {
                var existingParticipant = existingParticipants.SingleOrDefault(p => p.Id == person.Id);
                if (existingParticipant != null)
                {
                    invitation.UpdateParticipant(
                        existingParticipant.Id,
                        organization,
                        IpoParticipantType.Person,
                        null,
                        personFromMain.FirstName,
                        personFromMain.LastName,
                        personFromMain.Email,
                        new Guid(personFromMain.AzureOid),
                        sortKey,
                        person.RowVersion);
                }
                else
                {
                    invitation.AddParticipant(new Participant(
                                                  _plantProvider.Plant,
                                                  organization,
                                                  IpoParticipantType.Person,
                                                  null,
                                                  personFromMain.FirstName,
                                                  personFromMain.LastName,
                                                  personFromMain.UserName,
                                                  personFromMain.Email,
                                                  new Guid(personFromMain.AzureOid),
                                                  sortKey));
                }
                meetingParticipants = InvitationHelper.AddPersonToOutlookParticipantList(personFromMain, meetingParticipants);
            }
            else
            {
                throw new IpoValidationException($"Person does not have required privileges to be the {organization} participant.");
            }
            return(meetingParticipants);
        }
コード例 #5
0
        private static void SeedConstructionCompany(IPOContext dbContext, Invitation invitation)
        {
            var constructionCompany = new Participant(
                invitation.Plant,
                Organization.ConstructionCompany,
                IpoParticipantType.Person,
                null,
                "First",
                "Last",
                "UN",
                "*****@*****.**",
                new Guid("11111111-1111-2222-3333-333333333333"),
                1);

            invitation.AddParticipant(constructionCompany);
            dbContext.SaveChangesAsync().Wait();
        }
コード例 #6
0
        private static void SeedContractor(IPOContext dbContext, Invitation invitation)
        {
            var contractor = new Participant(
                invitation.Plant,
                Organization.Contractor,
                IpoParticipantType.FunctionalRole,
                KnownTestData.FunctionalRoleCode,
                null,
                null,
                null,
                "*****@*****.**",
                null,
                0);

            invitation.AddParticipant(contractor);
            dbContext.SaveChangesAsync().Wait();
        }
 private List <BuilderParticipant> AddExternalParticipant(
     Invitation invitation,
     List <BuilderParticipant> meetingParticipants,
     IEnumerable <ParticipantsForEditCommand> participantsWithExternalEmail,
     IList <Participant> existingParticipants)
 {
     foreach (var participant in participantsWithExternalEmail)
     {
         var existingParticipant =
             existingParticipants.SingleOrDefault(p => p.Id == participant.InvitedExternalEmailToEdit.Id);
         if (existingParticipant != null)
         {
             invitation.UpdateParticipant(
                 existingParticipant.Id,
                 participant.Organization,
                 IpoParticipantType.Person,
                 null,
                 null,
                 null,
                 participant.InvitedExternalEmailToEdit.Email,
                 null,
                 participant.SortKey,
                 participant.InvitedExternalEmailToEdit.RowVersion);
         }
         else
         {
             invitation.AddParticipant(new Participant(
                                           _plantProvider.Plant,
                                           participant.Organization,
                                           IpoParticipantType.Person,
                                           null,
                                           null,
                                           null,
                                           null,
                                           participant.InvitedExternalEmailToEdit.Email,
                                           null,
                                           participant.SortKey));
         }
         meetingParticipants.Add(new BuilderParticipant(ParticipantType.Required,
                                                        new ParticipantIdentifier(participant.InvitedExternalEmail.Email)));
     }
     return(meetingParticipants);
 }
        private async Task <List <BuilderParticipant> > AddSigner(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            IInvitedPersonForCommand invitedSigner,
            int sortKey,
            Organization organization)
        {
            var person = await _personApiService.GetPersonByOidWithPrivilegesAsync(
                _plantProvider.Plant,
                invitedSigner.AzureOid.ToString(),
                _objectName,
                _signerPrivileges);

            if (person != null)
            {
                invitation.AddParticipant(new Participant(
                                              _plantProvider.Plant,
                                              organization,
                                              IpoParticipantType.Person,
                                              null,
                                              person.FirstName,
                                              person.LastName,
                                              person.UserName,
                                              person.Email,
                                              new Guid(person.AzureOid),
                                              sortKey));
                meetingParticipants = InvitationHelper.AddPersonToOutlookParticipantList(person, meetingParticipants);
            }
            else
            {
                throw new IpoValidationException(
                          $"Person does not have required privileges to be the {organization} participant.");
            }

            return(meetingParticipants);
        }
        private List <BuilderParticipant> AddExternalParticipant(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            List <ParticipantsForCommand> participantsWithExternalEmail)
        {
            foreach (var participant in participantsWithExternalEmail)
            {
                invitation.AddParticipant(new Participant(
                                              _plantProvider.Plant,
                                              participant.Organization,
                                              IpoParticipantType.Person,
                                              null,
                                              null,
                                              null,
                                              null,
                                              participant.InvitedExternalEmail.Email,
                                              null,
                                              participant.SortKey));
                meetingParticipants.Add(new BuilderParticipant(ParticipantType.Required,
                                                               new ParticipantIdentifier(participant.InvitedExternalEmail.Email)));
            }

            return(meetingParticipants);
        }
        public void Setup()
        {
            _mcPkg = new McPkg(TestPlant, _projectName2, _commPkgNo2, _mcPkgNo, "Description", _system);
            _mcPkg.SetProtectedIdForTesting(McPkgId);

            _commPkg = new CommPkg(TestPlant, _projectName, _commPkgNo, "Description", "OK", "1|2");
            _commPkg.SetProtectedIdForTesting(CommPkgId);

            _commPkg2 = new CommPkg(TestPlant, _projectName, _commPkgNo2, "Description", "OK", "1|2");
            _commPkg.SetProtectedIdForTesting(CommPkgId);

            _commPkg4 = new CommPkg(TestPlant, _projectName, _commPkgNo4, "Description", "OK", "1|2");
            _commPkg4.SetProtectedIdForTesting(CommPkgId4);

            _mcPkg2 = new McPkg(TestPlant, _projectName, _commPkgNo, _mcPkgNo2, "Description", _system);
            _mcPkg2.SetProtectedIdForTesting(McPkgId2);

            _mcPkg3 = new McPkg(TestPlant, _projectName, _commPkgNo3, _mcPkgNo3, "Description", _system);
            _mcPkg3.SetProtectedIdForTesting(McPkgId3);

            _participant = new Participant(
                TestPlant,
                Organization.Contractor,
                IpoParticipantType.FunctionalRole,
                "FR",
                null,
                null,
                null,
                "*****@*****.**",
                null,
                0);
            _participant.SetProtectedIdForTesting(ParticipantId);

            _dpInviation = new Invitation(
                TestPlant,
                _projectName2,
                "Title",
                "D",
                DisciplineType.DP,
                new DateTime(),
                new DateTime(),
                null,
                new List <McPkg> {
                _mcPkg
            },
                null);
            _dpInviation.SetProtectedIdForTesting(InvitationWithMcPkgId);
            _dpInviationMove = new Invitation(
                TestPlant,
                _projectName,
                "Title",
                "D",
                DisciplineType.DP,
                new DateTime(),
                new DateTime(),
                null,
                new List <McPkg> {
                _mcPkg3
            },
                null);
            _dpInviationMove.SetProtectedIdForTesting(InvitationWithMcPkgMoveId);
            _mdpInvitation = new Invitation(
                TestPlant,
                _projectName,
                "Title 2",
                "D",
                DisciplineType.MDP,
                new DateTime(),
                new DateTime(),
                null,
                null,
                new List <CommPkg> {
                _commPkg
            });
            _mdpInvitationWithTwoCommpkgs = new Invitation(
                TestPlant,
                _projectName,
                "Title 3",
                "D",
                DisciplineType.MDP,
                new DateTime(),
                new DateTime(),
                null,
                null,
                new List <CommPkg> {
                _commPkg, _commPkg2
            });

            _attachment = new Attachment(TestPlant, "filename.txt");

            _dpInviation.AddParticipant(_participant);
            _dpInviation.AddAttachment(_attachment);

            _comment = new Comment(TestPlant, "comment");
            _mdpInvitation.AddComment(_comment);

            _mdpInvitation4 = new Invitation(
                TestPlant,
                _projectName,
                "Title 4",
                "D",
                DisciplineType.MDP,
                new DateTime(),
                new DateTime(),
                null,
                null,
                new List <CommPkg> {
                _commPkg4
            });

            _invitations = new List <Invitation>
            {
                _dpInviation,
                _dpInviationMove,
                _mdpInvitation,
                _mdpInvitationWithTwoCommpkgs,
                _mdpInvitation4
            };

            _dbInvitationSetMock = _invitations.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.Invitations)
            .Returns(_dbInvitationSetMock.Object);

            var attachments = new List <Attachment>
            {
                _attachment
            };

            _attachmentSetMock = attachments.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.Attachments)
            .Returns(_attachmentSetMock.Object);

            var participants = new List <Participant>
            {
                _participant
            };

            _participantSetMock = participants.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.Participants)
            .Returns(_participantSetMock.Object);

            var mcPkgs = new List <McPkg>
            {
                _mcPkg,
                _mcPkg2,
                _mcPkg3
            };

            _mcPkgSetMock = mcPkgs.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.McPkgs)
            .Returns(_mcPkgSetMock.Object);

            var commPkgs = new List <CommPkg>
            {
                _commPkg,
                _commPkg2,
                _commPkg4
            };

            _commPkgSetMock = commPkgs.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.CommPkgs)
            .Returns(_commPkgSetMock.Object);

            var comments = new List <Comment>
            {
                _comment
            };

            _commentSetMock = comments.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.Comments)
            .Returns(_commentSetMock.Object);

            _dut = new InvitationRepository(ContextHelper.ContextMock.Object);
        }
        protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (var context =
                       new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                const string description = "Description";

                var functionalRoleParticipant1 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode1,
                    null,
                    null,
                    null,
                    _frEmail1,
                    null,
                    0);

                var functionalRoleParticipant2 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode2,
                    null,
                    null,
                    null,
                    null,
                    null,
                    1);

                var personParticipant1 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    0);

                var personParticipant2 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName2",
                    "LastName2",
                    "UN",
                    _personEmail2,
                    _personGuid,
                    1);

                var personParticipant3 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    null,
                    "FirstName3",
                    "LastName3",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    0);

                var personParticipant4 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail2,
                    _personGuid,
                    1);

                var frPerson1 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    _functionalRoleCode1,
                    "FirstName2",
                    "LastName2",
                    "UN2",
                    _frPersonEmail1,
                    _frPersonGuid1,
                    0);

                var frPerson2 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    _functionalRoleCode2,
                    "FirstName3",
                    "LastName3",
                    "UN3",
                    _frPersonEmail2,
                    _frPersonGuid2,
                    1);

                var supplierPersonParticipant = new Participant(
                    TestPlant,
                    Organization.Supplier,
                    IpoParticipantType.Person,
                    null,
                    "SupplierFirstName",
                    "SupplierLastName",
                    "UN",
                    _personEmail3,
                    _personGuid,
                    5);

                var commPkg = new CommPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    description,
                    "OK",
                    "1|2");

                var mcPkg1 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    _mcPkgNo,
                    description,
                    _system);

                var mcPkg2 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo2,
                    _mcPkgNo,
                    description,
                    _system);

                var startTime1 = _timeProvider.UtcNow;

                _invitation1 = new Invitation(
                    TestPlant,
                    _projectName,
                    _title1,
                    "Description",
                    DisciplineType.DP,
                    startTime1,
                    startTime1.AddHours(1),
                    null,
                    new List <McPkg> {
                    mcPkg1
                },
                    null);

                _invitation1.AddParticipant(functionalRoleParticipant1);
                _invitation1.AddParticipant(personParticipant2);
                _invitation1.AddParticipant(frPerson1);
                _invitation1.AddParticipant(supplierPersonParticipant);

                var startTime2 = _timeProvider.UtcNow.AddWeeks(1);

                _invitation2 = new Invitation(
                    TestPlant,
                    _projectName2,
                    _title1,
                    "Description",
                    DisciplineType.MDP,
                    startTime2,
                    startTime2.AddHours(1),
                    null,
                    null,
                    new List <CommPkg> {
                    commPkg
                });

                personParticipant1.SetProtectedIdForTesting(_participantId1);
                _invitation2.AddParticipant(functionalRoleParticipant2);
                _invitation2.AddParticipant(personParticipant1);
                _invitation2.AddParticipant(frPerson2);

                _currentPerson = new Person(_currentUserOid, "firstname", "lastname", "testusername", null);
                _currentPerson.SetProtectedIdForTesting(_participantId1);

                _personRepositoryMock = new Mock <IPersonRepository>();
                _personRepositoryMock
                .Setup(x => x.GetByIdAsync(It.IsAny <int>()))
                .Returns(Task.FromResult(_currentPerson));

                var startTime3 = _timeProvider.UtcNow.AddWeeks(2);

                _invitation3 = new Invitation(
                    TestPlant,
                    _projectName2,
                    _title2,
                    "Description",
                    DisciplineType.DP,
                    startTime3,
                    startTime3.AddHours(1),
                    null,
                    new List <McPkg> {
                    mcPkg2
                },
                    null);

                _invitation3.AddParticipant(personParticipant3);
                _invitation3.AddParticipant(personParticipant4);

                context.Invitations.Add(_invitation1);
                var history1 = new History(TestPlant, "D1", _invitation1.ObjectGuid, EventType.IpoCreated);
                context.History.Add(history1);

                context.Invitations.Add(_invitation2);
                var history2 = new History(TestPlant, "D2", _invitation2.ObjectGuid, EventType.IpoCreated);
                context.History.Add(history2);

                context.Invitations.Add(_invitation3);
                var history3 = new History(TestPlant, "D3", _invitation3.ObjectGuid, EventType.IpoCreated);
                context.History.Add(history3);

                context.SaveChangesAsync().Wait();
            }
        }
        private async Task <List <BuilderParticipant> > AddFunctionalRoleParticipantsAsync(
            Invitation invitation,
            List <BuilderParticipant> meetingParticipants,
            List <ParticipantsForCommand> functionalRoleParticipants)
        {
            var codes           = functionalRoleParticipants.Select(p => p.InvitedFunctionalRole.Code).ToList();
            var functionalRoles =
                await _functionalRoleApiService.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, codes);

            foreach (var participant in functionalRoleParticipants)
            {
                var fr = functionalRoles.SingleOrDefault(p => p.Code == participant.InvitedFunctionalRole.Code);
                if (fr != null)
                {
                    invitation.AddParticipant(new Participant(
                                                  _plantProvider.Plant,
                                                  participant.Organization,
                                                  IpoParticipantType.FunctionalRole,
                                                  fr.Code,
                                                  null,
                                                  null,
                                                  null,
                                                  fr.Email,
                                                  null,
                                                  participant.SortKey));
                    if (fr.UsePersonalEmail != null && fr.UsePersonalEmail == false && fr.Email != null)
                    {
                        meetingParticipants.AddRange(InvitationHelper.SplitAndCreateOutlookParticipantsFromEmailList(fr.Email));
                    }
                    if (fr.InformationEmail != null)
                    {
                        meetingParticipants.AddRange(InvitationHelper.SplitAndCreateOutlookParticipantsFromEmailList(fr.InformationEmail));
                    }
                    foreach (var person in participant.InvitedFunctionalRole.InvitedPersons)
                    {
                        var frPerson = fr.Persons.SingleOrDefault(p => p.AzureOid == person.AzureOid.ToString());
                        if (frPerson != null)
                        {
                            invitation.AddParticipant(new Participant(
                                                          _plantProvider.Plant,
                                                          participant.Organization,
                                                          IpoParticipantType.Person,
                                                          fr.Code,
                                                          frPerson.FirstName,
                                                          frPerson.LastName,
                                                          frPerson.UserName,
                                                          frPerson.Email,
                                                          new Guid(frPerson.AzureOid),
                                                          participant.SortKey));
                            meetingParticipants = InvitationHelper.AddPersonToOutlookParticipantList(frPerson, meetingParticipants, person.Required);
                        }
                    }
                }
                else
                {
                    throw new IpoValidationException(
                              $"Could not find functional role with functional role code '{participant.InvitedFunctionalRole.Code}' on participant {participant.Organization}.");
                }
            }
            return(meetingParticipants);
        }
        public void Setup()
        {
            _unitOfWorkMock = new Mock <IUnitOfWork>();

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

            //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);

            _invitation.SignIpo(participant, currentUser, participant.RowVersion.ConvertToString());

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

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

            _dut = new UnSignPunchOutCommandHandler(_invitationRepositoryMock.Object,
                                                    _unitOfWorkMock.Object);
        }
コード例 #14
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);
        }
コード例 #15
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);
        }
        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);

            _permissionCacheMock = new Mock <IPermissionCache>();

            //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 participant1 = new Participant(
                _plant,
                Organization.Contractor,
                IpoParticipantType.FunctionalRole,
                _functionalRoleCode,
                null,
                null,
                null,
                null,
                null,
                0);

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

            var participant2 = new Participant(
                _plant,
                Organization.ConstructionCompany,
                IpoParticipantType.Person,
                null,
                _firstName,
                _lastName,
                "OlaN",
                "*****@*****.**",
                _azureOidForCurrentUser,
                1);

            _invitation.AddParticipant(participant2);
            var currentPerson = new Person(_azureOidForCurrentUser, _firstName, _lastName, null, null);

            _invitation.CompleteIpo(participant1, participant1.RowVersion.ConvertToString(), currentPerson, new DateTime());

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

            _mcPkgApiServiceMock = new Mock <IMcPkgApiService>();

            //command
            _command = new UnCompletePunchOutCommand(
                _invitation.Id,
                _invitationRowVersion,
                _participantRowVersion);

            _dut = new UnCompletePunchOutCommandHandler(
                _plantProviderMock.Object,
                _invitationRepositoryMock.Object,
                _unitOfWorkMock.Object,
                _currentUserProviderMock.Object,
                _mcPkgApiServiceMock.Object,
                _permissionCacheMock.Object);
        }
        protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (var context = new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var          meetingId      = new Guid("11111111-2222-2222-2222-333333333333");
                var          personAzureOid = new Guid("44444444-5555-5555-5555-666666666666");
                const string description    = "Description";

                var functionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    "FR1",
                    null,
                    null,
                    null,
                    "*****@*****.**",
                    null,
                    0);

                var personParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    "*****@*****.**",
                    personAzureOid,
                    1);

                var functionalRoleParticipant2 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    "FR2",
                    null,
                    null,
                    null,
                    "*****@*****.**",
                    null,
                    0);

                var personParticipant2 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName2",
                    "LastName",
                    "UN",
                    "*****@*****.**",
                    personAzureOid,
                    1);

                var commPkg = new CommPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    description,
                    "OK",
                    "1|2");

                var mcPkg1 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    "McPkgNo1",
                    description,
                    _system);

                var mcPkg2 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    "McPkgNo2",
                    description,
                    _system);

                _dpInvitation = new Invitation(
                    TestPlant,
                    _projectName,
                    "DP Title",
                    "Description1",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    mcPkg1, mcPkg2
                },
                    null)
                {
                    MeetingId = meetingId
                };

                _dpInvitation.AddParticipant(functionalRoleParticipant);
                _dpInvitation.AddParticipant(personParticipant);

                _mdpInvitation = new Invitation(
                    TestPlant,
                    _projectName,
                    "MDP Title",
                    "Description2",
                    DisciplineType.MDP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    null,
                    new List <CommPkg> {
                    commPkg
                })
                {
                    MeetingId = meetingId
                };

                _mdpInvitation.AddParticipant(functionalRoleParticipant2);
                _mdpInvitation.AddParticipant(personParticipant2);

                context.Invitations.Add(_dpInvitation);
                context.Invitations.Add(_mdpInvitation);
                context.SaveChangesAsync().Wait();
                _dpInvitationId  = _dpInvitation.Id;
                _mdpInvitationId = _mdpInvitation.Id;
            }
        }
コード例 #18
0
        protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (var context = new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                const string description = "Description";

                var contractorFunctionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode1,
                    null,
                    null,
                    null,
                    _frEmail1,
                    null,
                    0);

                var constructionCompanyFunctionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode2,
                    null,
                    null,
                    null,
                    null,
                    null,
                    1);

                var commissioningFunctionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.Commissioning,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode3,
                    null,
                    null,
                    null,
                    null,
                    null,
                    2);

                var contractorPersonParticipant = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    0);

                var constructionCompanyPersonParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName2",
                    "LastName2",
                    "UN",
                    _personEmail2,
                    _personGuid,
                    1);

                var contractorPersonParticipant1 = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    null,
                    "FirstName1",
                    "LastName1",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    0);

                var constructionCompanyPersonParticipant1 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail2,
                    _personGuid,
                    1);

                var commissioningPersonParticipant = new Participant(
                    TestPlant,
                    Organization.Commissioning,
                    IpoParticipantType.Person,
                    null,
                    "FirstName3",
                    "LastName3",
                    "UN",
                    _personEmail3,
                    _personGuid,
                    7);

                var externalPersonParticipant = new Participant(
                    TestPlant,
                    Organization.External,
                    IpoParticipantType.Person,
                    null,
                    null,
                    null,
                    null,
                    _externalPersonEmail,
                    _personGuid,
                    8);

                var contractorFunctionalRolePersonParticipant = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    _functionalRoleCode1,
                    "FirstName2",
                    "LastName2",
                    "UN2",
                    _frPersonEmail1,
                    _frPersonGuid1,
                    0);

                var constructionCompanyFunctionalRolePersonParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    _functionalRoleCode2,
                    "FirstName3",
                    "LastName3",
                    "UN3",
                    _frPersonEmail2,
                    _frPersonGuid2,
                    10);

                var constructionCompanyFunctionalRolePersonParticipant1 = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    _functionalRoleCode3,
                    "FirstName4",
                    "LastName4",
                    "UN4",
                    _frPersonEmail3,
                    _frPersonGuid3,
                    11);

                var commPkg = new CommPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    description,
                    "OK",
                    "1|2");

                var mcPkg1 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo,
                    _mcPkgNo,
                    description,
                    _system);

                var mcPkg2 = new McPkg(
                    TestPlant,
                    _projectName,
                    _commPkgNo2,
                    _mcPkgNo,
                    description,
                    _system);

                var startTime1 = _timeProvider.UtcNow;

                _invitation1 = new Invitation(
                    TestPlant,
                    _projectName,
                    _title1,
                    "Description",
                    DisciplineType.DP,
                    startTime1,
                    startTime1.AddHours(1),
                    null,
                    new List <McPkg> {
                    mcPkg1
                },
                    null);

                _invitation1.AddParticipant(contractorFunctionalRoleParticipant);
                _invitation1.AddParticipant(constructionCompanyPersonParticipant);
                _invitation1.AddParticipant(contractorFunctionalRolePersonParticipant);
                _invitation1.AddParticipant(commissioningPersonParticipant);
                _invitation1.AddParticipant(commissioningFunctionalRoleParticipant);
                _invitation1.AddParticipant(constructionCompanyFunctionalRolePersonParticipant1);
                _invitation1.AddParticipant(externalPersonParticipant);

                var startTime2 = _timeProvider.UtcNow.AddWeeks(1);

                _invitation2 = new Invitation(
                    TestPlant,
                    _projectName2,
                    _title1,
                    "Description",
                    DisciplineType.MDP,
                    startTime2,
                    startTime2.AddHours(1),
                    null,
                    null,
                    new List <CommPkg> {
                    commPkg
                });

                _invitation2.AddParticipant(constructionCompanyFunctionalRoleParticipant);
                _invitation2.AddParticipant(contractorPersonParticipant);
                _invitation2.AddParticipant(constructionCompanyFunctionalRolePersonParticipant);

                var startTime3 = _timeProvider.UtcNow.AddWeeks(2);

                _invitation3 = new Invitation(
                    TestPlant,
                    _projectName2,
                    _title2,
                    "Description",
                    DisciplineType.DP,
                    startTime3,
                    startTime3.AddHours(1),
                    null,
                    new List <McPkg> {
                    mcPkg2
                },
                    null);

                _invitation3.AddParticipant(contractorPersonParticipant1);
                _invitation3.AddParticipant(constructionCompanyPersonParticipant1);

                context.Invitations.Add(_invitation1);
                context.Invitations.Add(_invitation2);
                context.Invitations.Add(_invitation3);
                context.SaveChangesAsync().Wait();
            }
        }
コード例 #19
0
        protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            _query = new GetOutstandingIposForCurrentPersonQuery();

            _person = new Person(_currentUserOid, "*****@*****.**", "FirstName", "LastName", "UserName");
            using (var context = new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                IList <string> pcsFunctionalRoleCodes = new List <string> {
                    _functionalRoleCode
                };

                _meApiServiceMock = new Mock <IMeApiService>();
                _meApiServiceMock
                .Setup(x => x.GetFunctionalRoleCodesAsync(TestPlant))
                .Returns(Task.FromResult(pcsFunctionalRoleCodes));

                _invitationWithPersonParticipant = new Invitation(
                    TestPlant,
                    _projectName,
                    "TestInvitation1",
                    "TestDescription1",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    new McPkg(TestPlant, _projectName, "Comm", "Mc", "d", "1|2")
                },
                    new List <CommPkg>());

                _invitationWithFunctionalRoleParticipant = new Invitation(
                    TestPlant,
                    _projectName,
                    "TestInvitation2",
                    "TestDescription2",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    new McPkg(TestPlant, _projectName, "Comm", "Mc", "d", "1|2")
                },
                    new List <CommPkg>());

                _cancelledInvitation = new Invitation(
                    TestPlant,
                    _projectName,
                    "TestInvitation3",
                    "TestDescription3",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    new McPkg(TestPlant, _projectName, "Comm", "Mc", "d", "1|2")
                },
                    new List <CommPkg>());

                _invitationWithPersonParticipantContractor = new Invitation(
                    TestPlant,
                    _projectName,
                    "TestInvitation4",
                    "TestDescription4",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    new McPkg(TestPlant, _projectName, "Comm", "Mc", "d", "1|2")
                },
                    new List <CommPkg>());

                _invitationWithFunctionalRoleParticipantContractor = new Invitation(
                    TestPlant,
                    _projectName,
                    "TestInvitation5",
                    "TestDescription5",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    new McPkg(TestPlant, _projectName, "Comm", "Mc", "d", "1|2")
                },
                    new List <CommPkg>());

                _functionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode,
                    null,
                    null,
                    null,
                    null,
                    null,
                    1);
                _functionalRoleParticipant.SetProtectedIdForTesting(1);

                _personParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    null,
                    null,
                    null,
                    null,
                    _currentUserOid,
                    1);
                _personParticipant.SetProtectedIdForTesting(2);

                _personParticipant2 = new Participant(
                    TestPlant,
                    Organization.Operation,
                    IpoParticipantType.Person,
                    null,
                    null,
                    null,
                    null,
                    null,
                    _currentUserOid,
                    3);
                _personParticipant2.SetProtectedIdForTesting(3);

                _functionalRoleParticipantContractor = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode,
                    null,
                    null,
                    null,
                    null,
                    null,
                    0);
                _functionalRoleParticipantContractor.SetProtectedIdForTesting(4);

                _personParticipantContractor = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.Person,
                    null,
                    null,
                    null,
                    null,
                    null,
                    _currentUserOid,
                    0);
                _personParticipantContractor.SetProtectedIdForTesting(5);

                _invitationWithPersonParticipant.AddParticipant(_personParticipant);
                _invitationWithFunctionalRoleParticipant.AddParticipant(_functionalRoleParticipant);
                _cancelledInvitation.AddParticipant(_personParticipant2);
                _invitationWithPersonParticipantContractor.AddParticipant(_personParticipantContractor);
                _invitationWithFunctionalRoleParticipantContractor.AddParticipant(_functionalRoleParticipantContractor);

                _invitationWithPersonParticipant.CompleteIpo(
                    _personParticipant,
                    _personParticipant.RowVersion.ConvertToString(),
                    _person,
                    new DateTime());

                _invitationWithFunctionalRoleParticipant.CompleteIpo(
                    _functionalRoleParticipant,
                    _functionalRoleParticipant.RowVersion.ConvertToString(),
                    _person,
                    new DateTime());

                _cancelledInvitation.CompleteIpo(
                    _personParticipant,
                    _personParticipant.RowVersion.ConvertToString(),
                    _person,
                    new DateTime());
                _cancelledInvitation.CancelIpo(_person);

                context.Invitations.Add(_invitationWithPersonParticipant);
                context.Invitations.Add(_invitationWithFunctionalRoleParticipant);
                context.Invitations.Add(_cancelledInvitation);
                context.Invitations.Add(_invitationWithPersonParticipantContractor);
                context.Invitations.Add(_invitationWithFunctionalRoleParticipantContractor);

                context.SaveChangesAsync().Wait();
            }
        }
        protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (var context = new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                const string projectName = "Project1";
                const string description = "Description";
                const string commPkgNo   = "CommPkgNo";
                const string mcPkgNo     = "McPkgNo";
                const string system      = "1|2";

                var functionalRoleParticipant = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode1,
                    null,
                    null,
                    null,
                    _frEmail1,
                    null,
                    0);

                var personParticipant = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    1);

                var functionalRoleParticipant2 = new Participant(
                    TestPlant,
                    Organization.Commissioning,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode2,
                    null,
                    null,
                    null,
                    null,
                    null,
                    2);

                var frPerson1 = new Participant(
                    TestPlant,
                    Organization.Commissioning,
                    IpoParticipantType.Person,
                    _functionalRoleCode2,
                    "FirstName2",
                    "LastName2",
                    "UN2",
                    _frPersonEmail1,
                    new Guid("11111111-2222-2222-2222-333333333332"),
                    2);

                var frPerson2 = new Participant(
                    TestPlant,
                    Organization.Commissioning,
                    IpoParticipantType.Person,
                    _functionalRoleCode2,
                    "FirstName3",
                    "LastName3",
                    "UN3",
                    _frPersonEmail2,
                    new Guid("11111111-2222-2222-2222-333333333331"),
                    2);

                var commPkg = new CommPkg(
                    TestPlant,
                    projectName,
                    commPkgNo,
                    description,
                    "OK",
                    system);

                _mdpInvitation = new Invitation(
                    TestPlant,
                    projectName,
                    "Title",
                    "Description",
                    DisciplineType.MDP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    null,
                    new List <CommPkg> {
                    commPkg
                })
                {
                    MeetingId = _meetingId
                };

                _mdpInvitation.AddParticipant(functionalRoleParticipant);
                _mdpInvitation.AddParticipant(personParticipant);
                _mdpInvitation.AddParticipant(functionalRoleParticipant2);
                _mdpInvitation.AddParticipant(frPerson1);
                _mdpInvitation.AddParticipant(frPerson2);

                var mcPkg = new McPkg(
                    TestPlant,
                    projectName,
                    commPkgNo,
                    mcPkgNo,
                    description,
                    system);

                _dpInvitation = new Invitation(
                    TestPlant,
                    projectName,
                    "Title 2",
                    "Description 2",
                    DisciplineType.DP,
                    new DateTime(),
                    new DateTime(),
                    null,
                    new List <McPkg> {
                    mcPkg
                },
                    null)
                {
                    MeetingId = _meetingId
                };

                var functionalRoleParticipantForDp = new Participant(
                    TestPlant,
                    Organization.Contractor,
                    IpoParticipantType.FunctionalRole,
                    _functionalRoleCode1,
                    null,
                    null,
                    null,
                    _frEmail1,
                    null,
                    0);

                var personParticipantForDp = new Participant(
                    TestPlant,
                    Organization.ConstructionCompany,
                    IpoParticipantType.Person,
                    null,
                    "FirstName",
                    "LastName",
                    "UN",
                    _personEmail1,
                    _currentUserOid,
                    1);

                _dpInvitation.AddParticipant(functionalRoleParticipantForDp);
                _dpInvitation.AddParticipant(personParticipantForDp);

                var functionalRoleDetails = new ProCoSysFunctionalRole
                {
                    Code             = _functionalRoleCode1,
                    Description      = "FR description",
                    Email            = _frEmail1,
                    InformationEmail = null,
                    Persons          = null,
                    UsePersonalEmail = false
                };

                var functionalRoleDetails2 = new ProCoSysFunctionalRole
                {
                    Code             = _functionalRoleCode2,
                    Description      = "FR description",
                    Email            = null,
                    InformationEmail = null,
                    Persons          = new List <ProCoSysPerson>
                    {
                        new ProCoSysPerson
                        {
                            AzureOid  = "11111111-2222-2222-2222-333333333332",
                            Email     = _frPersonEmail1,
                            FirstName = null,
                            LastName  = null,
                            UserName  = null
                        },
                        new ProCoSysPerson
                        {
                            AzureOid  = "11111111-2222-2222-2222-333333333331",
                            Email     = _frPersonEmail2,
                            FirstName = null,
                            LastName  = null,
                            UserName  = null
                        }
                    },
                    UsePersonalEmail = true
                };
                IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> {
                    functionalRoleDetails
                };
                IList <ProCoSysFunctionalRole> frDetails2 = new List <ProCoSysFunctionalRole> {
                    functionalRoleDetails2
                };

                _functionalRoleApiServiceMock = new Mock <IFunctionalRoleApiService>();
                _functionalRoleApiServiceMock
                .Setup(x => x.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, new List <string> {
                    _functionalRoleCode1
                }))
                .Returns(Task.FromResult(frDetails));
                _functionalRoleApiServiceMock
                .Setup(x => x.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, new List <string> {
                    _functionalRoleCode2
                }))
                .Returns(Task.FromResult(frDetails2));

                _loggerMock          = new Mock <ILogger <GetInvitationByIdQueryHandler> >();
                _permissionCacheMock = new Mock <IPermissionCache>();

                _meetingClientMock = new Mock <IFusionMeetingClient>();
                _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(),
                    OutlookMode     = string.Empty,
                    Participants    = new List <ApiMeetingParticipant>()
                    {
                        new ApiMeetingParticipant()
                        {
                            Id     = Guid.NewGuid(),
                            Person = new ApiPersonDetailsV1()
                            {
                                Id   = _currentUserOid,
                                Mail = _personEmail1
                            },
                            OutlookResponse = "None"
                        },
                        new ApiMeetingParticipant()
                        {
                            Id     = Guid.NewGuid(),
                            Person = new ApiPersonDetailsV1()
                            {
                                Id   = Guid.NewGuid(),
                                Mail = _frEmail1
                            },
                            OutlookResponse = "Declined"
                        },
                        new ApiMeetingParticipant()
                        {
                            Id     = Guid.NewGuid(),
                            Person = new ApiPersonDetailsV1()
                            {
                                Id   = Guid.NewGuid(),
                                Mail = _frPersonEmail1
                            },
                            OutlookResponse = "Accepted"
                        },
                        new ApiMeetingParticipant()
                        {
                            Id     = Guid.NewGuid(),
                            Person = new ApiPersonDetailsV1()
                            {
                                Id   = Guid.NewGuid(),
                                Mail = _frPersonEmail2
                            },
                            OutlookResponse = "Declined"
                        }
                    },
                    Project            = null,
                    ResponsiblePersons = new List <ApiPersonDetailsV1>(),
                    Series             = null,
                    Title = string.Empty
                })));


                context.Invitations.Add(_mdpInvitation);
                context.Invitations.Add(_dpInvitation);
                context.SaveChangesAsync().Wait();
                _mdpInvitationId = _mdpInvitation.Id;
                _dpInvitationId  = _dpInvitation.Id;
            }
        }