public void DeleteShouldDeleteTheaterJob()
        {
            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");

            theaterService.CreateTheater(theater);
            dbcontext.SaveChanges();
            var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType");

            theaterJobService.CreateTheaterJob(jobPosting);
            dbcontext.SaveChanges();
            var controller = new HelpWantedController();

            //Act
            var actionResult = controller.DeleteTheaterJob(jobPosting.HelpWantedID);
            var response     = actionResult as NegotiatedContentResult <string>;
            var content      = response.Content;

            var dbcontext2      = new BroadwayBuilderContext();
            var theaterService2 = new TheaterService(dbcontext2);

            theaterService2.DeleteTheater(theater);
            dbcontext2.SaveChanges();
            //Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.AreEqual("Successfully Deleted Job Posting", content);
            Assert.AreEqual((HttpStatusCode)202, response.StatusCode);
        }
        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);
        }
示例#3
0
 public IHttpActionResult CreateTheaterJob([FromBody] TheaterJobPosting theaterJob)
 {
     using (var dbcontext = new BroadwayBuilderContext())
     {
         TheaterJobService jobService = new TheaterJobService(dbcontext);
         try
         {
             if (theaterJob == null)
             {
                 return(Content((HttpStatusCode)400, "That job posting does not exist"));
             }
             jobService.CreateTheaterJob(theaterJob);
             var results = dbcontext.SaveChanges();
             if (results <= 0)
             {
                 throw new ZeroAffectedRowsException();
             }
             return(Content((HttpStatusCode)201, theaterJob));
             //return Content((HttpStatusCode)201, "Theater Job Posting Created");
         }
         catch (ZeroAffectedRowsException)
         {
             return(Content((HttpStatusCode)500, "There appears to be no additions made. The Job posting was not created"));
         }
         catch (DbEntityValidationException)
         {
             return(Content((HttpStatusCode)500, "Unable to create the requested job posting"));
         }
         catch (Exception e)//needs to be updated
         {
             return(Content((HttpStatusCode)400, e.Message));
         }
     }
 }