Example #1
0
        public void SetUp()
        {
            _mockApprenticeshipEvents      = new Mock <IApprenticeshipEvents>();
            _mockCommitmentRespository     = new Mock <ICommitmentRepository>();
            _mockApprenticeshipRespository = new Mock <IApprenticeshipRepository>();
            _mockMediator              = new Mock <IMediator>();
            _mockHistoryRepository     = new Mock <IHistoryRepository>();
            _mockUlnValidator          = new Mock <IUlnValidator>();
            _mockAcademicYearValidator = new Mock <IAcademicYearValidator>();

            var validator = new BulkUploadApprenticeshipsValidator(new ApprenticeshipValidator(new StubCurrentDateTime(), _mockUlnValidator.Object, _mockAcademicYearValidator.Object));

            _handler = new BulkUploadApprenticeshipsCommandHandler(
                _mockCommitmentRespository.Object,
                _mockApprenticeshipRespository.Object,
                validator,
                _mockApprenticeshipEvents.Object,
                Mock.Of <ICommitmentsLogger>(),
                _mockMediator.Object,
                _mockHistoryRepository.Object);

            _exampleApprenticships = new List <Apprenticeship>
            {
                new Apprenticeship {
                    FirstName = "Bob", LastName = "Smith", ULN = "1234567890", StartDate = new DateTime(2018, 5, 1), EndDate = new DateTime(2018, 5, 2)
                },
                new Apprenticeship {
                    FirstName = "Jane", LastName = "Jones", ULN = "1122334455", StartDate = new DateTime(2019, 3, 1), EndDate = new DateTime(2019, 9, 2)
                },
            };

            _exampleValidRequest = new BulkUploadApprenticeshipsCommand
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Provider,
                    Id         = 111L
                },
                CommitmentId    = 123L,
                Apprenticeships = _exampleApprenticships,
                UserId          = "User",
                UserName        = "******"
            };

            _existingApprenticeships = new List <Apprenticeship>();
            _existingCommitment      = new Commitment {
                ProviderId = 111L, EditStatus = EditStatus.ProviderOnly, Apprenticeships = _existingApprenticeships, EmployerAccountId = 987
            };

            _mockCommitmentRespository.Setup(x => x.GetCommitmentById(It.IsAny <long>())).ReturnsAsync(_existingCommitment);

            _mockMediator.Setup(x => x.SendAsync(It.IsAny <GetOverlappingApprenticeshipsRequest>()))
            .ReturnsAsync(new GetOverlappingApprenticeshipsResponse {
                Data = new List <ApprenticeshipResult>()
            });
        }
Example #2
0
        public void SetUp()
        {
            _mockApprenticeshipEvents      = new Mock <IApprenticeshipEvents>();
            _mockCommitmentRespository     = new Mock <ICommitmentRepository>();
            _mockApprenticeshipRespository = new Mock <IApprenticeshipRepository>();
            _mockMediator              = new Mock <IMediator>();
            _mockHistoryRepository     = new Mock <IHistoryRepository>();
            _mockUlnValidator          = new Mock <IUlnValidator>();
            _mockAcademicYearValidator = new Mock <IAcademicYearValidator>();
            _stubCurrentDateTime       = new Mock <ICurrentDateTime>();
            _mockReservationApiClient  = new Mock <IReservationsApiClient>();
            _mockEncodingService       = new Mock <IEncodingService>();
            _mockV2EventsPublisher     = new Mock <IV2EventsPublisher>();

            var validator = new BulkUploadApprenticeshipsValidator(new ApprenticeshipValidator(_stubCurrentDateTime.Object, _mockUlnValidator.Object, _mockAcademicYearValidator.Object));

            _handler = new BulkUploadApprenticeshipsCommandHandler(
                _mockCommitmentRespository.Object,
                _mockApprenticeshipRespository.Object,
                validator,
                _mockApprenticeshipEvents.Object,
                Mock.Of <ICommitmentsLogger>(),
                _mockMediator.Object,
                _mockHistoryRepository.Object,
                _mockReservationApiClient.Object,
                _mockEncodingService.Object,
                _mockV2EventsPublisher.Object);

            _stubCurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2018, 4, 1));

            _exampleApprenticships = new List <Apprenticeship>
            {
                new Apprenticeship {
                    FirstName = "Bob", LastName = "Smith", ULN = "1234567890", StartDate = new DateTime(2018, 5, 1), EndDate = DateTime.Now.AddMonths(2)
                },
                new Apprenticeship {
                    FirstName = "Jane", LastName = "Jones", ULN = "1122334455", StartDate = new DateTime(2019, 3, 1), EndDate = new DateTime(2019, 9, 2)
                },
            };

            _exampleValidRequest = new BulkUploadApprenticeshipsCommand
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Provider,
                    Id         = 111L
                },
                CommitmentId    = 123L,
                Apprenticeships = _exampleApprenticships,
                UserId          = "User",
                UserName        = "******"
            };

            _existingApprenticeships = new List <Apprenticeship>();
            _existingCommitment      = new Commitment {
                ProviderId = 111L, EditStatus = EditStatus.ProviderOnly, Apprenticeships = _existingApprenticeships, EmployerAccountId = 987, TransferSenderId = 888
            };

            _mockCommitmentRespository.Setup(x => x.GetCommitmentById(It.IsAny <long>())).ReturnsAsync(_existingCommitment);

            _mockMediator.Setup(x => x.SendAsync(It.IsAny <GetOverlappingApprenticeshipsRequest>()))
            .ReturnsAsync(new GetOverlappingApprenticeshipsResponse {
                Data = new List <ApprenticeshipResult>()
            });

            _mockEncodingService.Setup(x => x.Decode(It.IsAny <string>(), It.IsAny <EncodingType>()))
            .Returns(_legalEntityId);

            _mockReservationApiClient.Setup(x => x.BulkCreateReservations(It.IsAny <long>(), It.IsAny <BulkCreateReservationsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_bulkCreateReservationsResult);
            _mockApprenticeshipRespository.Setup(x => x.BulkUploadApprenticeships(It.IsAny <long>(), It.IsAny <IEnumerable <Apprenticeship> >())).ReturnsAsync(new List <Apprenticeship>());
        }