示例#1
0
        public void ProductionController_GetPhotos_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 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 productionController = new ProductionController();

            var mockPostedPdfFile1 = new MockPostedFile("jpg", 5000000, "1.jpg");
            var mockPostedPdfFile2 = new MockPostedFile("jpg", 5000000, "2.jpg");

            productionService.SavePhoto(production.ProductionID, mockPostedPdfFile1);
            productionService.SavePhoto(production.ProductionID, mockPostedPdfFile2);

            var currentDirectory = ConfigurationManager.AppSettings["FileDir"];

            var dir    = Path.Combine(currentDirectory, "Photos/");
            var subdir = Path.Combine(dir, $"Production{production.ProductionID}/");

            // Act
            var actionResult = productionController.GetPhotos(production.ProductionID);

            // Need access to contet of the response
            var response = actionResult as OkNegotiatedContentResult <List <string> >;

            var photoUrls = response.Content;

            var expected = true;
            var actual   = false;

            if (photoUrls.Count == 2)
            {
                actual = true;
            }

            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Directory.Delete(subdir, true);

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