Example #1
0
        public async Task Transcript_ImportInactiveSchool_ShouldThrowUnlicensedSchoolException()
        {
            // Arrange
            SchoolSettingModel schoolSettings = new SchoolSettingModel();

            schoolSettings.SchoolSettingId     = 1;
            schoolSettings.SchoolId            = xello_test_account_school_id;
            schoolSettings.IsTranscriptEnabled = false;

            _mockSchoolSettingRepository.Setup(x => x.GetBySchoolIdAsync(It.IsAny <int>())).Returns(Task.FromResult <SchoolSettingModel>(schoolSettings));

            ITranscriptProviderService tps = CreateService();
            MemoryStream fileStream        = new MemoryStream();

            // Act
            await tps.ImportTranscriptAsync(xello_test_account_school_id, 12, "pdf", fileStream);

            // Assert (ExpectedException)  -> See the applied ExpectedException attribute to the test's method
        }
Example #2
0
        public async Task Transcript_Import_Success()
        {
            // Arrange
            SchoolSettingModel schoolSettings = new SchoolSettingModel
            {
                SchoolSettingId     = 1,
                SchoolId            = xello_test_account_school_id,
                IsTranscriptEnabled = true
            };

            _mockSchoolSettingRepository.Setup(x => x.GetBySchoolIdAsync(It.IsAny <int>())).Returns(Task.FromResult <SchoolSettingModel>(schoolSettings));

            ITranscriptProviderService tps = CreateService();
            MemoryStream fileStream        = new MemoryStream();

            // Act
            await tps.ImportTranscriptAsync(xello_test_account_school_id, 12, "pdf", fileStream);

            // Assert (ran the underlying API call)
            _mockTranscriptProviderAPIService.Verify(m => m.ImportTranscriptAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <MemoryStream>()), Times.Once());
        }
Example #3
0
        public async Task <IActionResult> Import(IFormFile file)
        {
            var educatorId    = GetClaim <int>(CcClaimType.EducatorId);
            var currentSchool = await _institutionRepository.GetDefaultInstitutionByEducatorIdAsync(educatorId);

            try
            {
                //  Validate the type of the file
                var extension = Path.GetExtension(file.FileName).Substring(1);
                if (Enum.IsDefined(typeof(CredentialsAcceptedDocumentTypeEnum), extension))
                {
                    await _transcriptProviderService.ImportTranscriptAsync(currentSchool.Id, educatorId, extension, file.OpenReadStream());

                    return(Ok());
                }
                return(BadRequest()); //  Not supported file type
            }
            catch (Exception)
            {
                return(BadRequest()); // Not supported file format, Credentails error...
            }
        }