public void Setup()
        {
            _invitationRepository = new Mock <IInvitationRepository>();
            _invitationRepository.Setup(x => x.Get(ExpectedAccountId, ExpectedCallerEmail)).ReturnsAsync(null);
            _invitationRepository.Setup(x => x.Create(It.IsAny <Invitation>())).ReturnsAsync(ExpectedInvitationId);

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(ExpectedHashedId, ExpectedExternalUserId)).ReturnsAsync(new MembershipView {
                AccountId = ExpectedAccountId, UserId = ExpectedUserId
            });

            _userRepository = new Mock <IUserRepository>();
            _userRepository.Setup(x => x.GetByEmailAddress(ExpectedExistingUserEmail)).ReturnsAsync(new User {
                Email = ExpectedExistingUserEmail, UserRef = Guid.NewGuid().ToString()
            });

            _mediator = new Mock <IMediator>();

            _validator = new Mock <IValidator <CreateInvitationCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateInvitationCommand>())).ReturnsAsync(new ValidationResult());

            _configuration = new EmployerApprenticeshipsServiceConfiguration();

            _handler = new CreateInvitationCommandHandler(_invitationRepository.Object, _membershipRepository.Object, _mediator.Object, _configuration, _validator.Object, _userRepository.Object);
            _command = new CreateInvitationCommand
            {
                HashedAccountId = ExpectedHashedId,
                Email           = ExpectedCallerEmail,
                Name            = "Test User",
                RoleId          = Role.Owner,
                ExternalUserId  = ExpectedExternalUserId
            };
            DateTimeProvider.Current = new FakeTimeProvider(DateTime.UtcNow);
        }
Exemplo n.º 2
0
        public void Setup()
        {
            _plantProviderMock = new Mock <IPlantProvider>();
            _plantProviderMock
            .Setup(x => x.Plant)
            .Returns(_plant);

            _currentUserProviderMock = new Mock <ICurrentUserProvider>();

            _personRepositoryMock = new Mock <IPersonRepository>();

            _meetingClientMock = new Mock <IFusionMeetingClient>();
            _meetingClientMock
            .Setup(x => x.CreateMeetingAsync(It.IsAny <Action <GeneralMeetingBuilder> >()))
            .Returns(Task.FromResult(
                         new GeneralMeeting(
                             new ApiGeneralMeeting()
            {
                Classification     = string.Empty,
                Contract           = null,
                Convention         = string.Empty,
                DateCreatedUtc     = DateTime.MinValue,
                DateEnd            = new ApiDateTimeTimeZoneModel(),
                DateStart          = new ApiDateTimeTimeZoneModel(),
                ExternalId         = null,
                Id                 = _meetingId,
                InviteBodyHtml     = string.Empty,
                IsDisabled         = false,
                IsOnlineMeeting    = false,
                Location           = string.Empty,
                Organizer          = new ApiPersonDetailsV1(),
                OutlookMode        = string.Empty,
                Participants       = new List <ApiMeetingParticipant>(),
                Project            = null,
                ResponsiblePersons = new List <ApiPersonDetailsV1>(),
                Series             = null,
                Title              = string.Empty
            })));

            _invitationRepositoryMock = new Mock <IInvitationRepository>();
            _invitationRepositoryMock
            .Setup(x => x.Add(It.IsAny <Invitation>()))
            .Callback <Invitation>(x => _createdInvitation = x);

            _transactionMock = new Mock <IDbContextTransaction>();
            _unitOfWorkMock  = new Mock <IUnitOfWork>();
            _unitOfWorkMock.Setup(x => x.BeginTransaction(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(_transactionMock.Object));

            _commPkgApiServiceMock = new Mock <ICommPkgApiService>();

            _mcPkgDetails1 = new ProCoSysMcPkg {
                CommPkgNo = _commPkgNo, Description = "D1", Id = 1, McPkgNo = _mcPkgNo1, System = _system
            };
            _mcPkgDetails2 = new ProCoSysMcPkg {
                CommPkgNo = _commPkgNo, Description = "D2", Id = 2, McPkgNo = _mcPkgNo2, System = _system
            };
            IList <ProCoSysMcPkg> mcPkgDetails = new List <ProCoSysMcPkg> {
                _mcPkgDetails1, _mcPkgDetails2
            };

            _mcPkgApiServiceMock = new Mock <IMcPkgApiService>();
            _mcPkgApiServiceMock
            .Setup(x => x.GetMcPkgsByMcPkgNosAsync(_plant, _projectName, _mcPkgScope))
            .Returns(Task.FromResult(mcPkgDetails));

            _personDetails = new ProCoSysPerson
            {
                AzureOid  = _azureOid.ToString(),
                FirstName = "Ola",
                LastName  = "Nordman",
                Email     = "*****@*****.**"
            };

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

            _functionalRoleDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleCode,
                Description      = "FR description",
                Email            = "*****@*****.**",
                InformationEmail = null,
                Persons          = null,
                UsePersonalEmail = false
            };
            _functionalRoleWithMultipleEmailsDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleWithMultipleEmailsCode,
                Description      = "FR description",
                Email            = "[email protected];[email protected]",
                InformationEmail = null,
                Persons          = null,
                UsePersonalEmail = false
            };
            _functionalRoleWithMultipleInformationEmailsDetails = new ProCoSysFunctionalRole
            {
                Code             = _functionalRoleWithMultipleInformationEmailsCode,
                Description      = "FR description",
                Email            = "*****@*****.**",
                InformationEmail = "[email protected];[email protected]",
                Persons          = null,
                UsePersonalEmail = false
            };

            IList <ProCoSysFunctionalRole> frDetails = new List <ProCoSysFunctionalRole> {
                _functionalRoleDetails
            };
            IList <ProCoSysFunctionalRole> frMultipleEmailsDetails = new List <ProCoSysFunctionalRole> {
                _functionalRoleWithMultipleEmailsDetails
            };
            IList <ProCoSysFunctionalRole> frMultipleInformationDetails = new List <ProCoSysFunctionalRole> {
                _functionalRoleWithMultipleInformationEmailsDetails
            };

            _functionalRoleApiServiceMock = new Mock <IFunctionalRoleApiService>();
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleCode
            }))
            .Returns(Task.FromResult(frDetails));
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleWithMultipleEmailsCode
            }))
            .Returns(Task.FromResult(frMultipleEmailsDetails));
            _functionalRoleApiServiceMock
            .Setup(x => x.GetFunctionalRolesByCodeAsync(_plant, new List <string> {
                _functionalRoleWithMultipleInformationEmailsCode
            }))
            .Returns(Task.FromResult(frMultipleInformationDetails));

            _meetingOptionsMock = new Mock <IOptionsMonitor <MeetingOptions> >();

            _command = new CreateInvitationCommand(
                _title,
                _description,
                _location,
                new DateTime(2020, 9, 1, 12, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 9, 1, 13, 0, 0, DateTimeKind.Utc),
                _projectName,
                _type,
                _participants,
                _mcPkgScope,
                null);

            _dut = new CreateInvitationCommandHandler(
                _plantProviderMock.Object,
                _meetingClientMock.Object,
                _invitationRepositoryMock.Object,
                _unitOfWorkMock.Object,
                _commPkgApiServiceMock.Object,
                _mcPkgApiServiceMock.Object,
                _personApiServiceMock.Object,
                _functionalRoleApiServiceMock.Object,
                _meetingOptionsMock.Object,
                _personRepositoryMock.Object,
                _currentUserProviderMock.Object,
                new Mock <ILogger <CreateInvitationCommandHandler> >().Object);
        }