public void TheaterJobService_ReadTheaterJobPosting_Pass() { //Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theaterJobService = new TheaterJobService(dbcontext); var expected = true; var actual = false; var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType"); //Act theaterService.CreateTheater(theater); theaterJobService.CreateTheaterJob(jobPosting); dbcontext.SaveChanges(); TheaterJobPosting getTheaterJob = theaterJobService.GetTheaterJob(jobPosting); if (getTheaterJob != null) { actual = true; } theaterJobService.DeleteTheaterJob(jobPosting); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); //Assert Assert.AreEqual(expected, actual); }
public IHttpActionResult DeleteTheaterJob(int helpWantedId) { using (var dbcontext = new BroadwayBuilderContext()) { TheaterJobService service = new TheaterJobService(dbcontext); TheaterJobPosting job = service.GetTheaterJob(helpWantedId); try { service.DeleteTheaterJob(job); if (job == null) { return(Content((HttpStatusCode)404, "That Job Listing does not exist")); } var results = dbcontext.SaveChanges(); if (results > 0) { return(Content((HttpStatusCode)202, "Successfully Deleted Job Posting")); } else { throw new ZeroAffectedRowsException(); } } catch (ZeroAffectedRowsException) { return(Content((HttpStatusCode)500, "There appears to be no changes made in the database. The job posting wasn't deleted")); } catch (DbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to delete the job posting")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }