示例#1
0
        public async Task <Resume> SaveResumeAsync(ResumeUploadModel resumeUploadModel, string userId)
        {
            // approximately 1 MB
            if (resumeUploadModel.FileLength > 1_000_000)
            {
                throw new ArgumentException("Resume file exceeded maximum size of 1 MB");
            }

            var fileExtension = Path.GetExtension(resumeUploadModel.FileName);

            if (fileExtension != ".pdf")
            {
                throw new ArgumentException("Resume file must be of type pdf");
            }

            var resumeKey = $"resumes/{Guid.NewGuid()}";
            await _resumeStorageService.UploadResumeAsync(resumeUploadModel.FileStream, resumeKey);

            var resume = new Resume
            {
                Name          = resumeUploadModel.Name,
                DateSubmitted = DateTime.Now,
                ResumeFileKey = resumeKey,
                UserId        = userId
            };

            await _resumeRepository.AddAsync(resume);

            await _resumeRepository.SaveChangesAsync();

            return(resume);
        }
示例#2
0
        public async Task SaveResumeAsync_Should_SaveResumeCorrectly()
        {
            // arrange
            const string userId = "123";

            await using var stream = new MemoryStream();

            var resumeUploadModel = new ResumeUploadModel
            {
                FileName   = "my_resume.pdf",
                FileLength = 1000,
                Name       = "My Resume",
                FileStream = stream,
            };

            // act
            var result = await _subject.SaveResumeAsync(resumeUploadModel, userId);

            // assert
            result.Should().NotBeNull();
            result.Name.Should().Be(resumeUploadModel.Name);
            result.UserId.Should().Be(userId);

            _mockResumeStorageService.Verify(x => x.UploadResumeAsync(resumeUploadModel.FileStream, It.IsAny <string>()));
            _mockResumeRepository.Verify(x => x.AddAsync(It.IsAny <Resume>()), Times.Once);
            _mockResumeRepository.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
示例#3
0
        public async Task <Resume> CreateResumeAsync([Service] IResumeService resumeService,
                                                     [Service] IHttpContextAccessor httpContextAccessor, ResumeInput resumeInput)
        {
            var user = httpContextAccessor.HttpContext.User;

            using var uploadModel = new ResumeUploadModel
                  {
                      Name       = resumeInput.Name,
                      FileName   = resumeInput.File.Name,
                      FileLength = resumeInput.File.Length,
                      FileStream = resumeInput.File.OpenReadStream()
                  };
            var resume = await resumeService.SaveResumeAsync(uploadModel, user.Identity.Name);

            return(resume);
        }