public void GetEducation_Pass() { using (ApplicationDbContext context = new ApplicationDbContext(Options)) { EducationService educationService = new EducationService(context); UserService userService = new UserService(context); User user = new User { FirstName = "Kyle", LastName = "Burgi" }; userService.AddUser(user); Education edu = new Education { CollegeName = "Eastern Washington University", FieldOfStudy = "Computer Science", UserId = user.Id }; educationService.AddEducation(edu); } using (ApplicationDbContext context = new ApplicationDbContext(Options)) { EducationService educationService = new EducationService(context); Education fetchedEducation = educationService.GetEducation(1); Assert.AreEqual("Eastern Washington University", fetchedEducation.CollegeName); Assert.AreEqual(1, fetchedEducation.UserId); } }
public IHttpActionResult GetEducation(long educationId) { try { return(Ok(_educationService.GetEducation(educationId))); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void GetEducationShouldReturnAnEducationById() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_CreatingEducations").Options; var dbContext = new ApplicationDbContext(options); var service = new EducationService(dbContext); var education = new Education { Title = "Test" }; dbContext.Educations.Add(education); dbContext.SaveChanges(); var returnedEducation = service.GetEducation(1); Assert.Equal(education.Title, returnedEducation.Title); }