Пример #1
0
        public void Setup()
        {
            var fixture = new Fixture();
            var mockApprenticeshipValidator = new Mock <AbstractValidator <Apprenticeship> >();

            _mockUlnValidator          = new Mock <IUlnValidator>();
            _mockAcademicYearValidator = new Mock <IAcademicYearValidator>();

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

            var exampleValidApprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship {
                    FirstName = "Bob", LastName = "Smith"
                },
                new Apprenticeship {
                    FirstName = "Bill", LastName = "Jones"
                }
            };

            _exampleCommand = new BulkUploadApprenticeshipsCommand
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Provider,
                    Id         = 1
                },
                CommitmentId    = 123L,
                Apprenticeships = exampleValidApprenticeships
            };
        }
        public async Task ThenIfFileHasMissingFieldsReturnError(string header)
        {
            var inputData = $"{header}" +
                            @"
                            Abba123,1113335559,Froberg,Chris,1998-12-08,SE123321C,25,,,2,2120-08,2125-08,1500,,Employer ref,Provider ref";

            var textStream = new MemoryStream(UTF8.GetBytes(inputData));

            _file.Setup(m => m.InputStream).Returns(textStream);

            BulkUploadApprenticeshipsCommand commandArgument = null;

            _mockMediator.Setup(x => x.Send(It.IsAny <BulkUploadApprenticeshipsCommand>(), new CancellationToken()))
            .ReturnsAsync(new Unit())
            .Callback((object x) => commandArgument = x as BulkUploadApprenticeshipsCommand);

            _mockMediator.Setup(m => m.Send(It.IsAny <GetCommitmentQueryRequest>(), new CancellationToken()))
            .Returns(Task.FromResult(new GetCommitmentQueryResponse
            {
                Commitment = new CommitmentView
                {
                    AgreementStatus = AgreementStatus.NotAgreed,
                    EditStatus      = EditStatus.ProviderOnly
                }
            }));

            _mockMediator.Setup(m => m.Send(It.IsAny <GetOverlappingApprenticeshipsQueryRequest>(), It.IsAny <CancellationToken>()))
            .Returns(
                Task.Run(() => new GetOverlappingApprenticeshipsQueryResponse
            {
                Overlaps = new List <ApprenticeshipOverlapValidationResult>
                {
                    new ApprenticeshipOverlapValidationResult
                    {
                        OverlappingApprenticeships = new List <OverlappingApprenticeship>
                        {
                            new OverlappingApprenticeship
                            {
                                Apprenticeship = new Apprenticeship {
                                    ULN = "1113335559"
                                },
                                ValidationFailReason = ValidationFailReason.DateEmbrace
                            }
                        }
                    }
                }
            }));

            var model = new UploadApprenticeshipsViewModel {
                Attachment = _file.Object, HashedCommitmentId = "ABBA123", ProviderId = 111
            };
            var file = await _sut.UploadFile("user123", model, new SignInUserModel());

            //Assert
            Assert.IsTrue(file.HasFileLevelErrors);

            _logger.Verify(x => x.Info(It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Once);
            _logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Never);
        }
Пример #3
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>()
            });
        }
        public async Task ThenIfAnyRecordsOverlapWithActiveApprenticeshipsThenReturnError()
        {
            const string dataLine     = "\n\rABBA123,Chris,Froberg,1998-12-08,,,25,2,2020-08,2025-08,1500,,Employer ref,Provider ref,1113335559";
            const string fileContents = HeaderLine + dataLine;
            var          textStream   = new MemoryStream(UTF8.GetBytes(fileContents));

            _file.Setup(m => m.InputStream).Returns(textStream);

            BulkUploadApprenticeshipsCommand commandArgument = null;

            _mockMediator.Setup(x => x.Send(It.IsAny <BulkUploadApprenticeshipsCommand>(), new CancellationToken()))
            .ReturnsAsync(new Unit())
            .Callback((object x) => commandArgument = x as BulkUploadApprenticeshipsCommand);

            _mockMediator.Setup(m => m.Send(It.IsAny <GetCommitmentQueryRequest>(), new CancellationToken()))
            .Returns(Task.FromResult(new GetCommitmentQueryResponse
            {
                Commitment = new CommitmentView
                {
                    AgreementStatus = AgreementStatus.NotAgreed,
                    EditStatus      = EditStatus.ProviderOnly
                }
            }));

            _mockMediator.Setup(m => m.Send(It.IsAny <GetOverlappingApprenticeshipsQueryRequest>(), It.IsAny <CancellationToken>()))
            .Returns(
                Task.Run(() => new GetOverlappingApprenticeshipsQueryResponse
            {
                Overlaps = new List <ApprenticeshipOverlapValidationResult>
                {
                    new ApprenticeshipOverlapValidationResult
                    {
                        OverlappingApprenticeships = new List <OverlappingApprenticeship>
                        {
                            new OverlappingApprenticeship
                            {
                                Apprenticeship = new Apprenticeship {
                                    ULN = "1113335559"
                                },
                                ValidationFailReason = ValidationFailReason.DateEmbrace
                            }
                        }
                    }
                }
            }));

            var model = new UploadApprenticeshipsViewModel {
                Attachment = _file.Object, HashedCommitmentId = "ABBA123", ProviderId = 111
            };
            var file = await _sut.UploadFile("user123", model, new SignInUserModel());

            //Assert
            Assert.IsTrue(file.HasRowLevelErrors);
        }
        public async Task ShouldCallMediatorPassingInMappedApprenticeships()
        {
            const string dataLine     = "\n\rABBA123,Chris,Froberg,1998-12-08,,,25,2,2020-08,2025-08,1500,,Employer ref,Provider ref,1113335559";
            const string fileContents = HeaderLine + dataLine;
            var          textStream   = new MemoryStream(UTF8.GetBytes(fileContents));

            _file.Setup(m => m.InputStream).Returns(textStream);

            BulkUploadApprenticeshipsCommand commandArgument = null;

            _mockMediator.Setup(x => x.Send(It.IsAny <BulkUploadApprenticeshipsCommand>(), new CancellationToken()))
            .ReturnsAsync(new Unit())
            .Callback <BulkUploadApprenticeshipsCommand, CancellationToken>((command, token) => commandArgument = command);

            _mockMediator.Setup(m => m.Send(It.IsAny <GetCommitmentQueryRequest>(), new CancellationToken()))
            .Returns(Task.FromResult(new GetCommitmentQueryResponse
            {
                Commitment = new CommitmentView
                {
                    AgreementStatus = AgreementStatus.NotAgreed,
                    EditStatus      = EditStatus.ProviderOnly
                }
            }));

            var model = new UploadApprenticeshipsViewModel {
                Attachment = _file.Object, HashedCommitmentId = "ABBA123", ProviderId = 111
            };
            var signinUser = new SignInUserModel {
                DisplayName = "Bob", Email = "*****@*****.**"
            };

            await _sut.UploadFile("user123", model, signinUser);

            _mockMediator.Verify(x => x.Send(It.IsAny <BulkUploadApprenticeshipsCommand>(), new CancellationToken()), Times.Once);

            commandArgument.ProviderId.Should().Be(111);
            commandArgument.CommitmentId.Should().Be(123);

            commandArgument.Apprenticeships.Should().NotBeEmpty();
            commandArgument.Apprenticeships.ToList()[0].FirstName.Should().Be("Chris");
            commandArgument.Apprenticeships.ToList()[0].LastName.Should().Be("Froberg");
            commandArgument.Apprenticeships.ToList()[0].DateOfBirth.Should().Be(new DateTime(1998, 12, 8));
            commandArgument.Apprenticeships.ToList()[0].TrainingType.Should().Be(DAS.Commitments.Api.Types.Apprenticeship.Types.TrainingType.Standard);
            commandArgument.Apprenticeships.ToList()[0].TrainingCode.Should().Be("2");
            commandArgument.Apprenticeships.ToList()[0].StartDate.Should().Be(new DateTime(2020, 8, 1));
            commandArgument.Apprenticeships.ToList()[0].EndDate.Should().Be(new DateTime(2025, 8, 1));
            commandArgument.Apprenticeships.ToList()[0].Cost.Should().Be(1500);
            commandArgument.Apprenticeships.ToList()[0].ProviderRef.Should().Be("Provider ref");
            commandArgument.Apprenticeships.ToList()[0].ULN.Should().Be("1113335559");
            commandArgument.UserEmailAddress.Should().Be(signinUser.Email);
            commandArgument.UserDisplayName.Should().Be(signinUser.DisplayName);
            commandArgument.UserId.Should().Be("user123");
        }
        public void Setup()
        {
            _validator = new BulkUploadApprenticeshipsCommandValidator();
            var exampleValidApprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship {
                    FirstName = "Bob", LastName = "Smith"
                },
                new Apprenticeship {
                    FirstName = "Bill", LastName = "Jones"
                }
            };

            _exampleValidCommand = new BulkUploadApprenticeshipsCommand
            {
                UserId          = "user1234",
                ProviderId      = 111L,
                CommitmentId    = 123L,
                Apprenticeships = exampleValidApprenticeships
            };
        }
        public void Setup()
        {
            _mockCommitmentsApi  = new Mock <IProviderCommitmentsApi>();
            _exampleValidCommand = new BulkUploadApprenticeshipsCommand
            {
                UserId          = "user123",
                ProviderId      = 123L,
                CommitmentId    = 333L,
                Apprenticeships = new List <Apprenticeship>
                {
                    new Apprenticeship {
                        FirstName = "John", LastName = "Smith"
                    },
                    new Apprenticeship {
                        FirstName = "Emma", LastName = "Jones"
                    },
                },
                UserEmailAddress = "*****@*****.**",
                UserDisplayName  = "Bob"
            };

            _handler = new BulkUploadApprenticeshipsCommandHandler(_mockCommitmentsApi.Object, Mock.Of <IProviderCommitmentsLogger>());
        }
Пример #8
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>());
        }