Ejemplo n.º 1
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();
            }
        }
        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);

            _loggerMock = new Mock <ILogger <CancelPunchOutCommandHandler> >();


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

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

            _fusionMeetingClient = new Mock <IFusionMeetingClient>();
            //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.Contractor,
                                              IpoParticipantType.FunctionalRole,
                                              "FR",
                                              null,
                                              null,
                                              null,
                                              null,
                                              null,
                                              0);

            _invitation.CompleteIpo(participant, "AAAAAAAAABB=", currentPerson, new DateTime());

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

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

            _dut = new CancelPunchOutCommandHandler(
                _invitationRepositoryMock.Object,
                _personRepositoryMock.Object,
                _unitOfWorkMock.Object,
                _fusionMeetingClient.Object,
                _currentUserProviderMock.Object,
                _loggerMock.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);
        }
        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 = "Ola",
                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 participant1 = new Participant(
                _plant,
                Organization.Contractor,
                IpoParticipantType.FunctionalRole,
                _functionalRoleCode,
                null,
                null,
                null,
                null,
                null,
                0);

            participant1.SetProtectedIdForTesting(_contractorParticipantId);
            _invitation.AddParticipant(participant1);
            var participant2 = new Participant(
                _plant,
                Organization.ConstructionCompany,
                IpoParticipantType.Person,
                null,
                "Kari",
                "Nordmann",
                "KN",
                "*****@*****.**",
                null,
                1);

            participant2.SetProtectedIdForTesting(_constructionCompanyParticipantId);
            _invitation.AddParticipant(participant2);

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

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

            currentPerson.SetProtectedIdForTesting(_contractorParticipantId);

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

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

            //command
            _command = new UpdateAttendedStatusAndNotesOnParticipantsCommand(
                _invitation.Id,
                _participants);

            _dut = new UpdateAttendedStatusAndNotesOnParticipantsCommandHandler(
                _plantProviderMock.Object,
                _invitationRepositoryMock.Object,
                _unitOfWorkMock.Object,
                _currentUserProviderMock.Object,
                _personApiServiceMock.Object);
        }