예제 #1
0
        public void ProductionService_GetProductionById_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "The Language",
                StreetAddress = "Pantene",
                State         = "CA",
                City          = "LA",
                CompanyName   = "123 Sesame St",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

            theaterService.CreateTheater(theater);
            dbcontext.SaveChanges();

            var productionService = new ProductionService(dbcontext);

            var production = new Production
            {
                ProductionName    = "The Pajama Game",
                DirectorFirstName = "Doris",
                DirectorLastName  = "Day",
                City          = "San Diego",
                StateProvince = "California",
                Country       = "U.S",
                TheaterID     = theater.TheaterID,
                Street        = "123 Sesame St",
                Zipcode       = "91911"
            };

            productionService.CreateProduction(production);
            dbcontext.SaveChanges();

            var expected = true;
            var actual   = false;

            // Act
            var readProduction = productionService.GetProduction(production.ProductionID);

            if (readProduction != null)
            {
                actual = true;
            }

            // Assert
            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public IHttpActionResult GetProductionById(int productionId)
        {
            using (var dbcontext = new BroadwayBuilderContext())

            {
                var productionService = new ProductionService(dbcontext);

                try
                {
                    Production current_production = productionService.GetProduction(productionId);

                    return(Ok(current_production));
                }
                // Hack: Need to add proper exception handling
                catch (Exception e)
                {
                    return(BadRequest());
                }
            }
        }
        public IHttpActionResult GetProductionById(int productionId)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())

                {
                    var productionService = new ProductionService(dbcontext);

                    Production current_production = productionService.GetProduction(productionId);

                    return(Ok(current_production));
                }
            }
            catch (DbUpdateException e)
            {
                return(InternalServerError(e));
            }
            // Catching all exceptions
            catch (Exception e) // Todo: log error
            {
                return(BadRequest(e.Message));
            }
        }