public async Task <bool> AddEducation(int?resumeId, EducationServiceModel model) { if (!this.IsEntityStateValid(model)) { return(false); } if (resumeId == null) { return(false); } var resume = await resumesRepository.All().SingleOrDefaultAsync(r => r.Id == resumeId); if (resume == null) { return(false); } var education = Mapper.Map <Education>(model); education.ResumeId = resume.Id; await this.educationsRepository.AddAsync(education); await this.educationsRepository.SaveChangesAsync(); return(true); }
public async Task <bool> UpdateAsync(EducationServiceModel model) { if (!this.IsEntityStateValid(model)) { return(false); } var education = await this.educationsRepository.All().SingleOrDefaultAsync(w => w.Id == model.Id); if (education == null) { return(false); } education.Major = model.Major; education.Institute = model.Institute; education.From = model.From; education.To = model.To; education.Description = model.Description; this.educationsRepository.Update(education); await this.educationsRepository.SaveChangesAsync(); return(true); }
public async Task AddEducation_ToNonExistingResume_ReturnsFalse() { var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new Resume() { JobSeeker = new JobSeeker() { FirstName = "JobSeekerName1", LastName = "JobSeekerName2", User = new User() { UserName = "******" } } }; var serviceModel = new EducationServiceModel(); var educationsService = new EducationsService(new EfRepository <Education>(context), new EfRepository <Resume>(context)); var result = await educationsService.AddEducation(model.Id, serviceModel); Assert.False(result); }
public async Task UpdateAsync_WithNonExistentEducation_ReturnsFalse() { var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var serviceModel = new EducationServiceModel() { Major = "MajorTest", Institute = "InstituteTest", From = 2000, To = 2001, }; var educationsService = new EducationsService(new EfRepository <Education>(context), new EfRepository <Resume>(context)); var result = await educationsService.UpdateAsync(serviceModel); Assert.False(result); }
public async Task UpdateAsync_WithValidData_ReturnsTrue() { string expectedResult = "NewMajor"; var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new Education() { Major = "MajorTest", Institute = "InstituteTest", From = 2000, To = 2001, }; await context.AddAsync(model); context.SaveChanges(); var serviceModel = new EducationServiceModel() { Id = model.Id, Major = expectedResult, Institute = "InstituteTest", From = 2000, To = 2001, }; var educationsService = new EducationsService(new EfRepository <Education>(context), new EfRepository <Resume>(context)); var result = await educationsService.UpdateAsync(serviceModel); Assert.True(result); var actualResult = (await context.EducationsHistory.SingleAsync(e => e.Id == model.Id)).Major; Assert.Equal(expectedResult, actualResult); }
public async Task AddEducation_WithValidData_ToExistingResume_WorksCorrectly() { var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var model = new Resume() { JobSeeker = new JobSeeker() { FirstName = "JobSeekerName1", LastName = "JobSeekerName2", User = new User() { UserName = "******" } } }; await context.AddAsync(model); context.SaveChanges(); var serviceModel = new EducationServiceModel() { Major = "MajorTest", Institute = "InstituteTest", From = 2000, To = 2001, }; var educationsService = new EducationsService(new EfRepository <Education>(context), new EfRepository <Resume>(context)); var result = await educationsService.AddEducation(model.Id, serviceModel); Assert.True(result); }