Ejemplo n.º 1
0
        private async Task Run_ThrowsTest <TException>(
            Action <ApprenticeshipCsvBuilder> configureCsv,
            string expectedErrorMessage,
            Action additionalMockSetup = null)
            where TException : Exception
        {
            // arrange
            SetupDependencies();
            _mockApprenticeshipService.Setup(m => m.AddApprenticeships(It.IsAny <IEnumerable <Apprenticeship> >(), It.IsAny <bool>()))
            .ReturnsAsync(Result.Ok());
            additionalMockSetup?.Invoke();
            SetupService();
            var apprenticeshipCsvBuilder = new ApprenticeshipCsvBuilder();

            configureCsv?.Invoke(apprenticeshipCsvBuilder);
            await using var csvStream = apprenticeshipCsvBuilder.BuildStream();

            // act
            var actualException = await Record.ExceptionAsync(
                async() => await _apprenticeshipBulkUploadService.ValidateAndUploadCSV(
                    "mybulkupload.csv", csvStream, _authUserDetails)
                );

            // assert
            Assert.NotNull(actualException);
            Assert.IsType <TException>(actualException);
            Assert.Equal(expectedErrorMessage, actualException.Message);
        }
Ejemplo n.º 2
0
        private async Task <List <Apprenticeship> > Run_ReturnsErrorsTest(
            Action <ApprenticeshipCsvBuilder> configureCsv,
            string expectedError)
        {
            // arrange
            SetupDependencies();
            List <Apprenticeship> dataPassedToApprenticeshipService = null;

            _mockApprenticeshipService.Setup(m => m.AddApprenticeships(It.IsAny <IEnumerable <Apprenticeship> >(), It.IsAny <bool>()))
            .ReturnsAsync(Result.Ok())
            .Callback <IEnumerable <Apprenticeship>, bool>((x, _) => dataPassedToApprenticeshipService = x.ToList());
            SetupService();
            var apprenticeshipCsvBuilder = new ApprenticeshipCsvBuilder();

            configureCsv?.Invoke(apprenticeshipCsvBuilder);
            await using var csvStream = apprenticeshipCsvBuilder.BuildStream();

            // act
            var result = await _apprenticeshipBulkUploadService.ValidateAndUploadCSV(
                "mybulkupload.csv", csvStream, _authUserDetails);

            // assert
            var actualErrors   = result.Errors;
            var expectedErrors = new List <string> {
                expectedError
            };

            Assert.Equal(expectedErrors, actualErrors);
            return(dataPassedToApprenticeshipService);
        }
Ejemplo n.º 3
0
        private async Task Run_SuccessTest(
            Action <ApprenticeshipCsvBuilder> configureCsv,
            Action <IList <Apprenticeship> > validateDataPassedToApprenticeshipService,
            string fileName = "mybulkupload.csv")
        {
            // arrange
            SetupDependencies();
            IList <Apprenticeship> dataPassedToApprenticeshipService = null;

            _mockApprenticeshipService.Setup(m => m.AddApprenticeships(It.IsAny <IEnumerable <Apprenticeship> >(), It.IsAny <bool>()))
            .ReturnsAsync(Result.Ok())
            .Callback <IEnumerable <Apprenticeship>, bool>((x, _) => dataPassedToApprenticeshipService = x.ToList());
            SetupService();
            var apprenticeshipCsvBuilder = new ApprenticeshipCsvBuilder();

            configureCsv?.Invoke(apprenticeshipCsvBuilder);
            await using var csvStream = apprenticeshipCsvBuilder.BuildStream();

            // act
            var result = await _apprenticeshipBulkUploadService.ValidateAndUploadCSV(
                fileName, csvStream, _authUserDetails);

            // assert
            var actualErrors = result.Errors;

            Assert.Empty(actualErrors);
            validateDataPassedToApprenticeshipService(dataPassedToApprenticeshipService);
        }