public void ProductionService_SavePhotos_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "Some Theater 1", StreetAddress = "Theater St", State = "CA", City = "LA", CompanyName = "Regal", Country = "US", PhoneNumber = "123456789" }; theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var production = new Production() { ProductionName = "The Lion King 2", DirectorFirstName = "Jane", DirectorLastName = "Doe", Street = "Anahiem", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; var productionService = new ProductionService(dbcontext); productionService.CreateProduction(production); dbcontext.SaveChanges(); var mockedPostedPdfFile = new MockPostedFile("jpg", 5000000, "productionPhotoTestFile.jpg"); var extension = Path.GetExtension(mockedPostedPdfFile.FileName); var currentDirectory = ConfigurationManager.AppSettings["FileDir"]; var dir = Path.Combine(currentDirectory, "Photos/"); var subdir = Path.Combine(dir, $"Production{production.ProductionID}/"); var filePath = Path.Combine(subdir, $"{production.ProductionID}-0{extension}"); var expected = true; var actual = false; // Act productionService.SavePhoto(production.ProductionID, mockedPostedPdfFile); if (File.Exists(filePath)) { actual = true; } // Assert productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); File.Delete(filePath); Directory.Delete(subdir); Assert.AreEqual(expected, actual); }
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); }