public void JobOfferDetails_IdNotInDatabase_NotFoundResult() { JobOffersController jobOffersController = new JobOffersController(context); var response = jobOffersController.Details(5); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }
public async Task Details_method_in_jobOffersController_should_throw_exception_when_id_is_null() { var options = new DbContextOptionsBuilder <WebApplication1Context>().UseInMemoryDatabase(databaseName: "Test1").Options; using (var context = new WebApplication1Context(options)) { context.JobOffer.Add(new JobOffer() { Id = 1, JobTitle = "job1" }); context.SaveChanges(); var controller = new JobOffersController(context); await Assert.ThrowsAsync <InvalidOperationException>(() => controller.Details(null)); } }
public async Task Details_method_in_jobOffersController() { var options = new DbContextOptionsBuilder <WebApplication1Context>().UseInMemoryDatabase(databaseName: "Test").Options; using (var context = new WebApplication1Context(options)) { context.JobOffer.Add(new JobOffer() { Id = 1, JobTitle = "job1" }); context.SaveChanges(); var controller = new JobOffersController(context); var result = await controller.Details(1); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(1, ((JobOffer)viewResult.Model).Id); Assert.Equal("job1", ((JobOffer)viewResult.Model).JobTitle); } }