コード例 #1
0
        public void ProductionController_GetProductions_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "Some Theater",
                StreetAddress = "Theater St",
                State         = "CA",
                City          = "LA",
                CompanyName   = "Regal",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

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


            var productionService = new ProductionService(dbcontext);

            var production1 = new Production()
            {
                ProductionName    = "The Lion King 14",
                DirectorFirstName = "Joan",
                DirectorLastName  = "Doe",
                Street            = "123 Anahiem St",
                City          = "Long Beach",
                StateProvince = "California",
                Country       = "United States",
                Zipcode       = "919293",
                TheaterID     = theater.TheaterID
            };


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

            var production2 = new Production()
            {
                ProductionName    = "The Lion King 15",
                DirectorFirstName = "Joan",
                DirectorLastName  = "Doe",
                Street            = "123 Anahiem St",
                City          = "Long Beach",
                StateProvince = "California",
                Country       = "United States",
                Zipcode       = "919293",
                TheaterID     = theater.TheaterID
            };

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

            var productionDateTime1 = new ProductionDateTime()
            {
                Date         = DateTime.Parse("3/23/2019 3:22:29 PM"),
                Time         = TimeSpan.Parse("10:30:00"),
                ProductionID = production1.ProductionID
            };

            productionService.CreateProductionDateTime(production1.ProductionID, productionDateTime1);
            dbcontext.SaveChanges();

            var productionDateTime2 = new ProductionDateTime()
            {
                Date         = DateTime.Parse("3/29/2019 3:22:29 PM"),
                Time         = TimeSpan.Parse("5:30:00"),
                ProductionID = production2.ProductionID
            };

            productionService.CreateProductionDateTime(production2.ProductionID, productionDateTime2);
            dbcontext.SaveChanges();


            var productionController = new ProductionController();

            // Act
            var actionResult = productionController.GetProductions(currentDate: new DateTime(2019, 3, 1));

            var response = actionResult as OkNegotiatedContentResult <List <ProductionResponseModel> >;

            var productions = response.Content;

            var expected = true;
            var actual   = false;

            if (productions.Count > 0)
            {
                actual = true;
            }

            productionService.DeleteProductionDateTime(productionDateTime2);
            dbcontext.SaveChanges();
            productionService.DeleteProductionDateTime(productionDateTime1);
            dbcontext.SaveChanges();
            productionService.DeleteProduction(production1.ProductionID);
            dbcontext.SaveChanges();
            productionService.DeleteProduction(production2.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();

            // Assert
            Assert.IsNotNull(response.Content);
            Assert.AreEqual(expected, actual);
        }