public CohortWithChangeOfPartyCreatedEventHandlerTestsFixture()
            {
                var autoFixture = new Fixture();

                _event = autoFixture.Create <CohortWithChangeOfPartyCreatedEvent>();

                _cohort = new Cohort();
                _cohort.SetValue(x => x.Id, _event.CohortId);
                _cohort.SetValue(x => x.Approvals, Party.None);
                _cohort.SetValue(x => x.WithParty, Party.Employer);

                _changeOfPartyRequest = new Mock <ChangeOfPartyRequest>();
                _changeOfPartyRequest.Setup(x => x.Id).Returns(_event.ChangeOfPartyRequestId);
                _changeOfPartyRequest.Setup(x => x.SetCohort(_cohort, _event.UserInfo));

                _db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                       .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                       .ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning))
                                                       .Options);

                _db.Cohorts.Add(_cohort);
                _db.ChangeOfPartyRequests.Add(_changeOfPartyRequest.Object);
                _db.SaveChanges();

                _messageHandlerContext = new Mock <IMessageHandlerContext>();

                _handler = new CohortWithChangeOfPartyCreatedEventHandler(
                    new Lazy <ProviderCommitmentsDbContext>(() => _db), Mock.Of <ILogger <CohortWithChangeOfPartyCreatedEventHandler> >());
            }
コード例 #2
0
            public CohortWithChangeOfPartyCreatedEventHandlerForEmailTestsFixture()
            {
                _autoFixture      = new Fixture();
                _mediator         = new Mock <IMediator>();
                UnitOfWorkContext = new UnitOfWorkContext();

                _db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                       .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                       .Options);

                _cohortSummary = _autoFixture.Create <GetCohortSummaryQueryResult>();
                _mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(),
                                            It.IsAny <CancellationToken>()))
                .ReturnsAsync(() => _cohortSummary);

                _apprenticeship = new Apprenticeship
                {
                    Id        = _autoFixture.Create <long>(),
                    FirstName = _autoFixture.Create <string>(),
                    LastName  = _autoFixture.Create <string>(),
                    Cohort    = new Cohort
                    {
                        AccountLegalEntity = new AccountLegalEntity()
                    },
                    ReservationId = _autoFixture.Create <Guid>()
                };

                _changeOfPartyRequest = new ChangeOfPartyRequest(_apprenticeship, ChangeOfPartyRequestType.ChangeProvider, Party.Employer, _autoFixture.Create <long>(), null, null, null, _autoFixture.Create <UserInfo>(), DateTime.Now);
                _apprenticeship.Cohort.ChangeOfPartyRequestId = _changeOfPartyRequest.Id;

                _db.ChangeOfPartyRequests.Add(_changeOfPartyRequest);
                _db.Apprenticeships.Add(_apprenticeship);
                _db.SaveChanges();

                _expectedApprenticeName         = _apprenticeship.LastName.EndsWith("s") ? $"{_apprenticeship.FirstName} {_apprenticeship.LastName}'" : $"{_apprenticeship.FirstName} {_apprenticeship.LastName}'s";
                _expectedSubjectDetailsRequired = $"{_cohortSummary.LegalEntityName} has requested that you add details on their behalf";
                _expectedSubjectForReview       = $"{_cohortSummary.LegalEntityName} has added details for you to review";
                _expectedRequestUrl             = $"{_cohortSummary.ProviderId}/apprentices/{_cohortSummary.CohortReference}/details";

                _cohortReference          = _autoFixture.Create <string>();
                _employerEncodedAccountId = _autoFixture.Create <string>();
                _encodingService          = new Mock <IEncodingService>();
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.CohortId),
                                                     EncodingType.CohortReference)).Returns(_cohortReference);
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.AccountId),
                                                     EncodingType.AccountId)).Returns(_employerEncodedAccountId);

                _handler = new CohortWithChangeOfPartyCreatedEventHandlerForEmail(new Lazy <ProviderCommitmentsDbContext>(() => _db),
                                                                                  _mediator.Object,
                                                                                  _encodingService.Object,
                                                                                  Mock.Of <ILogger <CohortWithChangeOfPartyCreatedEventHandlerForEmail> >());

                _messageHandlerContext = new TestableMessageHandlerContext();

                _event = new CohortWithChangeOfPartyCreatedEvent(_cohortSummary.CohortId, _changeOfPartyRequest.Id, Party.Employer, DateTime.Now, _autoFixture.Create <UserInfo>());
            }