Example #1
0
        public async Task UploadPost_ValidFileSupplied()
        {
            SetupValidFileMetadata();
            SetupFileData("a,small,csv,file,here");
            SetupUploadService_Success();

            var result = await _bulkUploadApprenticeshipsController.Upload(_mockFormFile.Object);

            AssertRedirect(result, "BulkUploadApprenticeships", "PublishYourFile");
            VerifyNotUploaded();
        }
Example #2
0
        public async Task Upload_WithBulkUploadFile_UploadsApprenticeshipsAndReturnsRedirectToActionResult()
        {
            var ukPrn    = 12345678;
            var userInfo = new AuthenticatedUserInfo
            {
                CurrentProviderId = Guid.NewGuid(),
                UserId            = Guid.NewGuid().ToString(),
                Email             = "*****@*****.**"
            };

            _session.SetInt32("UKPRN", ukPrn);

            _blobStorageService.SetupGet(s => s.InlineProcessingThreshold).Returns(400);

            _currentUserProvider.Setup(s => s.GetCurrentUser())
            .Returns(userInfo);

            _standardsAndFrameworksCache.Setup(s => s.GetStandard(It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync <int, int, IStandardsAndFrameworksCache, Core.Models.Standard>((c, v) => new Core.Models.Standard {
                StandardCode = c, Version = v
            });

            _standardsAndFrameworksCache.Setup(s => s.GetFramework(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync <int, int, int, IStandardsAndFrameworksCache, Core.Models.Framework>((c, t, p) => new Core.Models.Framework {
                FrameworkCode = c, ProgType = t, PathwayCode = p
            });

            _cosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetVenuesByProvider>()))
            .ReturnsAsync(new List <Core.DataStore.CosmosDb.Models.Venue>()
            {
                new Core.DataStore.CosmosDb.Models.Venue()
                {
                    VenueName = "Fenestra Centre Scunthorpe",
                    Status    = Core.Models.VenueStatus.Live
                }
            });

            var addedApprenticeships = new List <CreateApprenticeship>();

            _cosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <CreateApprenticeship>()))
            .Callback <ICosmosDbQuery <OneOf.Types.Success> >(q => addedApprenticeships.Add((CreateApprenticeship)q))
            .ReturnsAsync(new OneOf.Types.Success());

            const string csv = "STANDARD_CODE,STANDARD_VERSION,FRAMEWORK_CODE,FRAMEWORK_PROG_TYPE,FRAMEWORK_PATHWAY_CODE,APPRENTICESHIP_INFORMATION,APPRENTICESHIP_WEBPAGE,CONTACT_EMAIL,CONTACT_PHONE,CONTACT_URL,DELIVERY_METHOD,VENUE,RADIUS,DELIVERY_MODE,ACROSS_ENGLAND, NATIONAL_DELIVERY,REGION,SUB_REGION\r\n" +
                               "105,1,,,,\"This apprenticeship is applicable to any industry and perfect for those already in a team leading role or entering a management role for the first time.It lasts around 15 months and incorporates 14 one day modules plus on - the job learning and mentoring.It involves managing projects, leading and managing teams, change, financial management and coaching.If you choose to do this qualification with Azesta, you can expect exciting and engaging day long modules fully utilising experiential learning methods(one per month), high quality tutorial support, access to e-mail and telephone support whenever you need it and great results in your end point assessments.\",http://www.azesta.co.uk/apprenticeships/,[email protected],1423711904,http://www.azesta.co.uk/contact-us/,Both,Fenestra Centre Scunthorpe,100,Employer,No,,,\r\n" +
                               "104,1,,,,\"This apprenticeship is great for current managers. It involves managing projects, leading and managing teams, change, financial and resource management, talent management and coaching and mentoring. It takes around 2.5 years to complete and if you choose to do this qualification with Azesta, you can expect exciting and engaging day long modules fully utilising experiential learning methods (one per month), high quality tutorial support, access to e-mail and telephone support whenever you need it and great results in your end point assessments.\",http://www.azesta.co.uk/apprenticeships/,[email protected],1423711904,http://www.azesta.co.uk,Both,Fenestra Centre Scunthorpe,100,Employer,Yes,,,\r\n";

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(csv));
            var bulkUploadFile = new FormFile(stream, 0, stream.Length, "bulkUploadFile", "Test.csv")
            {
                Headers = new HeaderDictionary
                {
                    { "Content-Disposition", "filename" }
                }
            };

            var result = await _controller.Upload(bulkUploadFile);

            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("PublishYourFile", redirectResult.ActionName);
            Assert.Equal("BulkUploadApprenticeships", redirectResult.ControllerName);

            Assert.True(addedApprenticeships.Any());
            Assert.Equal(2, addedApprenticeships.Count);

            var apprenticeship1 = addedApprenticeships.First();
            var apprenticeship2 = addedApprenticeships.Skip(1).First();

            Assert.Equal(ukPrn, apprenticeship1.ProviderUkprn);
            Assert.Equal(userInfo.CurrentProviderId, apprenticeship1.ProviderId);
            Assert.Equal(userInfo.UserId.ToString(), apprenticeship1.CreatedByUser.UserId);
            Assert.Equal(105, apprenticeship1.StandardOrFramework.Standard.StandardCode);
            Assert.Equal("This apprenticeship is applicable to any industry and perfect for those already in a team leading role or entering a management role for the first time.It lasts around 15 months and incorporates 14 one day modules plus on - the job learning and mentoring.It involves managing projects, leading and managing teams, change, financial management and coaching.If you choose to do this qualification with Azesta, you can expect exciting and engaging day long modules fully utilising experiential learning methods(one per month), high quality tutorial support, access to e-mail and telephone support whenever you need it and great results in your end point assessments.", apprenticeship1.MarketingInformation);
            Assert.Equal("http://www.azesta.co.uk/apprenticeships/", apprenticeship1.Url);
            Assert.Equal("*****@*****.**", apprenticeship1.ContactEmail);
            Assert.Equal("1423711904", apprenticeship1.ContactTelephone);
            Assert.Equal("http://www.azesta.co.uk/contact-us/", apprenticeship1.ContactWebsite);

            var apprenticeship1Location = apprenticeship1.ApprenticeshipLocations.Single();

            Assert.Equal("Fenestra Centre Scunthorpe", apprenticeship1Location.Name);

            Assert.Equal(ukPrn, apprenticeship2.ProviderUkprn);
            Assert.Equal(userInfo.CurrentProviderId, apprenticeship2.ProviderId);
            Assert.Equal(userInfo.UserId.ToString(), apprenticeship2.CreatedByUser.UserId);
            Assert.Equal(104, apprenticeship2.StandardOrFramework.Standard.StandardCode);
            Assert.Equal("This apprenticeship is great for current managers. It involves managing projects, leading and managing teams, change, financial and resource management, talent management and coaching and mentoring. It takes around 2.5 years to complete and if you choose to do this qualification with Azesta, you can expect exciting and engaging day long modules fully utilising experiential learning methods (one per month), high quality tutorial support, access to e-mail and telephone support whenever you need it and great results in your end point assessments.", apprenticeship2.MarketingInformation);
            Assert.Equal("http://www.azesta.co.uk/apprenticeships/", apprenticeship2.Url);
            Assert.Equal("*****@*****.**", apprenticeship2.ContactEmail);
            Assert.Equal("1423711904", apprenticeship2.ContactTelephone);
            Assert.Equal("http://www.azesta.co.uk", apprenticeship2.ContactWebsite);

            var apprenticeship2Location = apprenticeship2.ApprenticeshipLocations.Single();

            Assert.Equal("Fenestra Centre Scunthorpe", apprenticeship2Location.Name);
        }