Example #1
0
            public WhenAddingDraftApprenticeshipTestsFixture()
            {
                Now     = DateTime.UtcNow;
                Fixture = new Fixture();

                Cohort = Fixture.Build <CommitmentsV2.Models.Cohort>()
                         .OmitAutoProperties()
                         .With(c => c.Id)
                         .With(c => c.ProviderId, 1)
                         .With(c => c.EditStatus, EditStatus.ProviderOnly)
                         .Create();

                DraftApprenticeshipDetails = Fixture.Build <DraftApprenticeshipDetails>()
                                             .Without(d => d.StartDate)
                                             .Without(d => d.EndDate)
                                             .Without(d => d.DateOfBirth)
                                             .Without(d => d.Uln)
                                             .Create();

                ExistingApprenticeshipDetails = new DraftApprenticeship(Fixture.Build <DraftApprenticeshipDetails>().Create(), Party.Provider);

                Party             = Party.Provider;
                UnitOfWorkContext = new UnitOfWorkContext();
                UserInfo          = Fixture.Create <UserInfo>();
            }
        public TransferRequestRejectedEventHandlerTestsFixture()
        {
            _fixture          = new Fixture();
            UnitOfWorkContext = new UnitOfWorkContext();
            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                  .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                  .ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning))
                                                  .Options);

            TransferRequestRejectedEvent = _fixture.Create <TransferRequestRejectedEvent>();

            Logger = new FakeLogger <TransferRequestRejectedEvent>();
            LegacyTopicMessagePublisher = new Mock <ILegacyTopicMessagePublisher>();
            Handler = new TransferRequestRejectedEventHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db), LegacyTopicMessagePublisher.Object, Logger);

            Cohort = new Cohort(
                _fixture.Create <long>(),
                _fixture.Create <long>(),
                _fixture.Create <long>(),
                null,
                Party.Employer,
                "",
                new UserInfo())
            {
                Id = TransferRequestRejectedEvent.CohortId, EmployerAccountId = 100, TransferSenderId = 99
            };

            ExistingApprenticeshipDetails = new DraftApprenticeship(_fixture.Build <DraftApprenticeshipDetails>().Create(), Party.Provider);
            Cohort.Apprenticeships.Add(ExistingApprenticeshipDetails);
            Cohort.WithParty = Party.TransferSender;
            Cohort.TransferApprovalStatus = TransferApprovalStatus.Pending;
        }
Example #3
0
        public DeleteCohortHandlerTestsFixture()
        {
            _autoFixture = new Fixture();

            CohortId = _autoFixture.Create <long>();
            UserInfo = _autoFixture.Create <UserInfo>();
            Logger   = new Mock <ILogger <DeleteCohortHandler> >();
            AuthenticationService = new Mock <IAuthenticationService>();

            Command = new DeleteCohortCommand {
                CohortId = CohortId, UserInfo = UserInfo
            };
            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                  .UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings =>
                                                                                                                    warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Sut = new DeleteCohortHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db), Logger.Object, AuthenticationService.Object);
            UnitOfWorkContext = new UnitOfWorkContext();

            DraftApprenticeship = new DraftApprenticeship
            {
                Id            = _autoFixture.Create <long>(),
                FirstName     = "Test",
                LastName      = "Test",
                ReservationId = _autoFixture.Create <Guid>()
            };
        }
        public AddDraftApprenticeshipCommandHandlerTestsFixture()
        {
            Fixture = new Fixture();
            DraftApprenticeshipDetails = Fixture.Create <DraftApprenticeshipDetails>();
            DraftApprenticeship        = new DraftApprenticeship().Set(a => a.Id, 123);
            CancellationToken          = new CancellationToken();

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

            CohortDomainService = new Mock <ICohortDomainService>();
            DraftApprenticeshipDetailsMapper = new Mock <IOldMapper <AddDraftApprenticeshipCommand, DraftApprenticeshipDetails> >();
            UserInfo = Fixture.Create <UserInfo>();
            Command  = Fixture.Build <AddDraftApprenticeshipCommand>().With(o => o.UserInfo, UserInfo).Create();

            Handler = new AddDraftApprenticeshipCommandHandler(
                new Lazy <ProviderCommitmentsDbContext>(() => Db),
                Mock.Of <ILogger <AddDraftApprenticeshipCommandHandler> >(),
                DraftApprenticeshipDetailsMapper.Object,
                CohortDomainService.Object);

            CohortDomainService.Setup(s => s.AddDraftApprenticeship(Command.ProviderId, Command.CohortId,
                                                                    DraftApprenticeshipDetails, Command.UserInfo, CancellationToken)).ReturnsAsync(DraftApprenticeship);
            DraftApprenticeshipDetailsMapper.Setup(m => m.Map(Command)).ReturnsAsync(DraftApprenticeshipDetails);
        }
Example #5
0
        public WhenSendingCohortToOtherPartyTestsFixture AddDraftApprenticeship()
        {
            ApprenticeshipBase apprenticeship = new DraftApprenticeship(new DraftApprenticeshipDetails(), Party.None);

            Cohort.Add(c => c.Apprenticeships, apprenticeship);
            return(this);
        }
Example #6
0
            private void SeedData()
            {
                _cohort = new Cohort
                {
                    CommitmentStatus = CommitmentStatus.New,
                    EditStatus       = EditStatus.EmployerOnly,
                    LastAction       = LastAction.None,
                    Originator       = Originator.Unknown,
                    Id        = _cohortId,
                    Reference = string.Empty
                };

                for (var i = 0; i < 10; i++)
                {
                    var apprenticeship = new DraftApprenticeship
                    {
                        CommitmentId      = _cohortId,
                        Cohort            = _cohort,
                        FirstName         = _autoFixture.Create <string>(),
                        LastName          = _autoFixture.Create <string>(),
                        Cost              = _autoFixture.Create <int?>(),
                        DateOfBirth       = _autoFixture.Create <DateTime?>(),
                        StartDate         = _autoFixture.Create <DateTime?>(),
                        EndDate           = _autoFixture.Create <DateTime?>(),
                        CourseCode        = _autoFixture.Create <string>(),
                        CourseName        = _autoFixture.Create <string>(),
                        Uln               = _autoFixture.Create <string>(),
                        OriginalStartDate = _autoFixture.Create <DateTime?>()
                    };
                    _cohort.Apprenticeships.Add(apprenticeship);
                }

                _db.Cohorts.Add(_cohort);
                _db.SaveChanges();
            }
        public AddDraftApprenticeshipValidationTestsFixture WithApprenticeship(long id, string uln)
        {
            var draftApprenticeshipDetails = new DraftApprenticeshipDetails().Set(d => d.Uln, uln);
            var draftApprenticeship        = new DraftApprenticeship(draftApprenticeshipDetails, Party.Provider).Set(d => d.Id, id);

            Cohort.Apprenticeships.Add(draftApprenticeship);

            return(this);
        }
 public DraftApprenticeship UpdatePropertiesWithNewValues(DraftApprenticeship draftApprenticeship)
 {
     return(new DraftApprenticeship(new DraftApprenticeshipDetails
     {
         Id = draftApprenticeship.Id,
         FirstName = SafeUpdate(draftApprenticeship.FirstName),
         LastName = SafeUpdate(draftApprenticeship.LastName),
         StartDate = SafeUpdate(draftApprenticeship.StartDate),
         EndDate = SafeUpdate(draftApprenticeship.EndDate),
         DateOfBirth = SafeUpdate(draftApprenticeship.DateOfBirth)
     }, Party.Provider));
 }
        private void AssertSameProperty <P>(DraftApprenticeship expected, DraftApprenticeship actual, Expression <Func <DraftApprenticeship, P> > action)
        {
            var    expression = (MemberExpression)action.Body;
            string name       = expression.Member.Name;

            var propertyInfo = expression.Member as PropertyInfo;

            var expectedValue = propertyInfo.GetValue(expected);
            var actualValue   = propertyInfo.GetValue(actual);

            Assert.AreEqual(expectedValue, actualValue, $"{name} is not equal");
        }
 public void AssertSameProperties(DraftApprenticeship expected, DraftApprenticeship actual)
 {
     AssertSameProperty(expected, actual, da => da.StartDate);
     AssertSameProperty(expected, actual, da => da.DateOfBirth);
     AssertSameProperty(expected, actual, da => da.EndDate);
     AssertSameProperty(expected, actual, da => da.Cost);
     AssertSameProperty(expected, actual, da => da.CourseCode);
     AssertSameProperty(expected, actual, da => da.Id);
     AssertSameProperty(expected, actual, da => da.ReservationId);
     AssertSameProperty(expected, actual, da => da.Uln);
     AssertSameProperty(expected, actual, da => da.FirstName);
     AssertSameProperty(expected, actual, da => da.LastName);
 }
Example #11
0
 private static void AssertEquality(DraftApprenticeship source, DraftApprenticeshipDto result)
 {
     Assert.AreEqual(source.Id, result.Id);
     Assert.AreEqual(source.FirstName, result.FirstName);
     Assert.AreEqual(source.LastName, result.LastName);
     Assert.AreEqual(source.DateOfBirth, result.DateOfBirth);
     Assert.AreEqual(source.Cost, result.Cost);
     Assert.AreEqual(source.StartDate, result.StartDate);
     Assert.AreEqual(source.EndDate, result.EndDate);
     Assert.AreEqual(source.Uln, result.Uln);
     Assert.AreEqual(source.CourseCode, result.CourseCode);
     Assert.AreEqual(source.CourseName, result.CourseName);
     Assert.AreEqual(source.OriginalStartDate, result.OriginalStartDate);
 }
Example #12
0
        public UpdateDraftApprenticeshipValidationTestsFixture WithApprenticeship(long id, string uln)
        {
            var draftApprenticeshipDetails = new DraftApprenticeshipDetails().Set(d => d.Uln, uln);

            draftApprenticeshipDetails.Set(x => x.FirstName, "TEST");
            draftApprenticeshipDetails.Set(x => x.LastName, "TEST");
            draftApprenticeshipDetails.Set(x => x.TrainingProgramme,
                                           new SFA.DAS.CommitmentsV2.Domain.Entities.TrainingProgramme("TEST", "TEST", ProgrammeType.Framework, DateTime.MinValue, DateTime.MaxValue));
            var draftApprenticeship = new DraftApprenticeship(draftApprenticeshipDetails, Party.Provider).Set(d => d.Id, id);

            Cohort.Apprenticeships.Add(draftApprenticeship);

            return(this);
        }
        public GetDraftApprenticeshipCreatedEventsForCohortHandlerTestsFixtures SetupASingleDraftApprenticeship(long apprenticeId)
        {
            var autoFixture = new Fixture();
            var apprentice1 = autoFixture.Build <DraftApprenticeshipDetails>().Without(x => x.StartDate)
                              .With(x => x.EndDate, DateTime.Today.AddYears(1)).With(x => x.DateOfBirth, DateTime.Today.AddYears(-20))
                              .With(x => x.Uln, "012345678").Create();

            var draftApprenticeship = new DraftApprenticeship(apprentice1, Party.Provider);

            draftApprenticeship.Id = apprenticeId;

            DraftApprentices = new List <DraftApprenticeship> {
                draftApprenticeship
            };

            return(this);
        }
Example #14
0
 private static DraftApprenticeshipDetails ToApprenticeshipDetails(DraftApprenticeship draftApprenticeship)
 {
     return(new DraftApprenticeshipDetails
     {
         Id = draftApprenticeship.Id,
         FirstName = draftApprenticeship.FirstName,
         LastName = draftApprenticeship.LastName,
         Uln = draftApprenticeship.Uln,
         TrainingProgramme = new SFA.DAS.CommitmentsV2.Domain.Entities.TrainingProgramme(draftApprenticeship.CourseCode, "", ProgrammeType.Framework,
                                                                                         null, null),
         Cost = (int?)draftApprenticeship.Cost,
         StartDate = draftApprenticeship.StartDate,
         EndDate = draftApprenticeship.EndDate,
         DateOfBirth = draftApprenticeship.DateOfBirth,
         Reference = draftApprenticeship.ProviderRef,
         ReservationId = draftApprenticeship.ReservationId
     });
 }
            public FundingCapServiceTestFixture SetApprenticesList()
            {
                var apprenticeA = new DraftApprenticeship
                {
                    StartDate  = _breakDate.AddMonths(-1),
                    Cost       = _firstCap,
                    CourseName = "C1Name",
                    CourseCode = "C1"
                };
                var apprenticeB = new DraftApprenticeship
                {
                    StartDate  = _breakDate.AddMonths(2),
                    Cost       = _firstCap,
                    CourseName = "C1Name",
                    CourseCode = "C1"
                };
                var apprenticeC = new DraftApprenticeship
                {
                    StartDate  = _breakDate,
                    Cost       = _firstCap,
                    CourseName = "C2Name",
                    CourseCode = "C2"
                };
                var apprenticeD = new DraftApprenticeship
                {
                    StartDate  = _breakDate,
                    Cost       = _secondCap,
                    CourseName = "C2Name",
                    CourseCode = "C2"
                };
                var apprenticeE = new DraftApprenticeship
                {
                    StartDate  = _breakDate.AddMonths(2),
                    Cost       = _secondCap,
                    CourseName = "C2Name",
                    CourseCode = "C2"
                };

                Apprentices = new List <DraftApprenticeship> {
                    apprenticeA, apprenticeB, apprenticeC, apprenticeD, apprenticeE
                };

                return(this);
            }
        public CanAccessApprenticeshipQueryHandlerTestsFixture SeedData(bool isApproved = true)
        {
            _cohort = new Cohort
            {
                EmployerAccountId = _accountId,
                CommitmentStatus  = CommitmentStatus.Active,
                EditStatus        = EditStatus.Both,
                LastAction        = LastAction.None,
                Originator        = Originator.Unknown,
                ProviderId        = _providerId,
                Id = _cohortId,
            };

            if (isApproved)
            {
                var apprenticeship = new Apprenticeship
                {
                    Id           = _apprenticeshipId,
                    CommitmentId = _cohortId,
                    Cohort       = _cohort
                };

                _cohort.Apprenticeships.Add(apprenticeship);

                Db.Apprenticeships.Add(apprenticeship);
            }
            else
            {
                var apprenticeship = new DraftApprenticeship()
                {
                    Id           = _apprenticeshipId,
                    CommitmentId = _cohortId,
                    Cohort       = _cohort
                };
                _cohort.Apprenticeships.Add(apprenticeship);
            }

            Db.Cohorts.Add(_cohort);

            Db.SaveChanges();

            return(this);
        }
            private void CreateCohort()
            {
                Cohort = new CommitmentsV2.Models.Cohort {
                    EditStatus = EditStatus.ProviderOnly, ProviderId = 1
                };

                for (var i = 0; i < CohortSize; i++)
                {
                    var draftApprenticeship = new DraftApprenticeship
                    {
                        Id            = i + 1,
                        FirstName     = _autoFixture.Create <string>(),
                        LastName      = _autoFixture.Create <string>(),
                        ReservationId = Guid.NewGuid()
                    };

                    Cohort.Apprenticeships.Add(draftApprenticeship);
                }
            }
Example #18
0
        public WhenApprovingCohortFixture AddDraftApprenticeship(bool isIncompleteForEmployer = false, bool isIncompleteForProvider = false)
        {
            var draftApprenticeshipDetailsComposer = AutoFixture.Build <DraftApprenticeshipDetails>().WithAutoProperties();

            if (isIncompleteForEmployer)
            {
                draftApprenticeshipDetailsComposer = draftApprenticeshipDetailsComposer.Without(d => d.FirstName);
            }

            if (isIncompleteForProvider)
            {
                draftApprenticeshipDetailsComposer = draftApprenticeshipDetailsComposer.Without(d => d.Uln);
            }

            ApprenticeshipBase apprenticeship = new DraftApprenticeship(draftApprenticeshipDetailsComposer.Create(), Party.Provider);

            Cohort.Add(c => c.Apprenticeships, apprenticeship);
            return(this);
        }
Example #19
0
            public UpdatingDraftApprenticeshipTestFixture WithExistingDraftApprenticeships()
            {
                Cohort.Apprenticeships.Clear();
                for (var i = 0; i < 10; i++)
                {
                    var apprenticeship = new DraftApprenticeship
                    {
                        Id          = i,
                        FirstName   = _autoFixture.Create <string>(),
                        LastName    = _autoFixture.Create <string>(),
                        Cost        = _autoFixture.Create <int>(),
                        CourseCode  = _autoFixture.Create <string>(),
                        CourseName  = _autoFixture.Create <string>(),
                        DateOfBirth = _autoFixture.Create <DateTime>(),
                    };

                    Cohort.Apprenticeships.Add(apprenticeship);
                }
                return(this);
            }
Example #20
0
            public UpdateChangeOfPartyRequestEventHandlerTestsFixture()
            {
                var autoFixture = new Fixture();

                _command = autoFixture.Build <CohortWithChangeOfPartyUpdatedEvent>()
                           .Create();

                _draftApprenticeship = new DraftApprenticeship
                {
                    StartDate = _startDate,
                    EndDate   = _endDate,
                    Cost      = _cost
                };

                _cohort = new Cohort
                {
                    Id = _command.CohortId,
                    Apprenticeships = new List <ApprenticeshipBase> {
                        _draftApprenticeship
                    },
                    ChangeOfPartyRequestId = 123,
                    WithParty = Party.Provider
                };

                _changeOfPartyRequest = new Mock <ChangeOfPartyRequest>();

                _mockDbContext = new Mock <ProviderCommitmentsDbContext>(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options)
                {
                    CallBase = true
                };

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

                _messageHandlerContext = new Mock <IMessageHandlerContext>();

                _handler = new CohortWithChangeOfPartyUpdatedEventHandler(new Lazy <ProviderCommitmentsDbContext>(() => _mockDbContext.Object));
            }
        public ApproveTransferRequestCommandHandlerTestsFixture()
        {
            UnitOfWorkContext     = new UnitOfWorkContext();
            MessageHandlerContext = new Mock <IMessageHandlerContext>();
            Fixture = new Fixture();
            Now     = DateTime.UtcNow;

            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                  .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                  .ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning))
                                                  .Options);
            Logger = new FakeLogger <ApproveTransferRequestCommandHandler>();
            Sut    = new ApproveTransferRequestCommandHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db), Logger);

            Cohort = new Cohort(
                Fixture.Create <long>(),
                Fixture.Create <long>(),
                Fixture.Create <long>(),
                null,
                Party.Employer,
                "",
                new UserInfo())
            {
                EmployerAccountId = 100, TransferSenderId = 99
            };

            ExistingApprenticeshipDetails = new DraftApprenticeship(Fixture.Build <DraftApprenticeshipDetails>().Create(), Party.Provider);
            Cohort.Apprenticeships.Add(ExistingApprenticeshipDetails);

            Cohort.EditStatus             = EditStatus.Both;
            Cohort.TransferApprovalStatus = TransferApprovalStatus.Pending;
            Cohort.TransferSenderId       = 10900;

            TransferSenderUserInfo = Fixture.Create <UserInfo>();
            TransferRequest        = new TransferRequest
            {
                Status = TransferApprovalStatus.Pending, Cost = 1000, Cohort = Cohort
            };
        }