public void DisableUser_Pass() { //Arrange var context = new BroadwayBuilderContext(); var userService = new UserService(context); var username = "******"; var firstName = "Abi"; var lastName = "Castro"; int age = 24; var dob = new DateTime(1994, 1, 7); var streetAddress = "address"; var city = "San Diego"; var stateProvince = "California"; var country = "United States"; var enable = true; var user = new User(username, firstName, lastName, age, dob, streetAddress, city, stateProvince, country, enable, Guid.NewGuid()); userService.CreateUser(user); context.SaveChanges(); var expected = false; var actual = true; //Act User DisabledUser = userService.DisableAccount(user); context.SaveChanges(); actual = DisabledUser.IsEnabled; userService.DeleteUser(user); context.SaveChanges(); //Assert Assert.AreEqual(expected, actual); }
public void PostShouldAddTheater() { //Arrange var dbcontext = new BroadwayBuilderContext(); var theater = new Theater("createTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); var service = new TheaterService(dbcontext); var controller = new TheaterController(); //Act var actionResult = controller.CreateTheater(theater); var response = actionResult as NegotiatedContentResult <string>; var content = response.Content; //Assert Assert.IsNotNull(response); Assert.IsNotNull(response.Content); Assert.AreEqual("Theater Created", content); Assert.AreEqual((HttpStatusCode)201, response.StatusCode); Theater gettheater = service.GetTheaterByName("createTheater"); service.DeleteTheater(gettheater); dbcontext.SaveChanges(); }
public IHttpActionResult UpdateUser([FromBody] User user) { using (var dbcontext = new BroadwayBuilderContext()) { try { var userService = new UserService(dbcontext); var updatedUser = userService.UpdateUser(user); if (updatedUser != null) { dbcontext.SaveChanges(); } else { throw new Exception(); } return(Content((HttpStatusCode)200, user)); } catch { return(Content((HttpStatusCode)404, "The user could not be found")); } } }
public IHttpActionResult GetTheaterJobs(int theaterid)//needs to be changed to string for encryption purposes { using (var dbcontext = new BroadwayBuilderContext()) { try { TheaterJobService service = new TheaterJobService(dbcontext); var list = service.GetAllJobsFromTheater(theaterid); if (list == null) { throw new NullNotFoundException(); } return(Content((HttpStatusCode)200, list)); } catch (NullNotFoundException) { return(Content((HttpStatusCode)404, "Unable to find any jobs related to that Theater")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
public IHttpActionResult CreateProductionJob([FromBody] ProductionJobPosting productionJob) { using (var dbcontext = new BroadwayBuilderContext()) { ProductionJobService jobService = new ProductionJobService(dbcontext); try { if (productionJob == null) { return(Content((HttpStatusCode)404, "The job posting does not exist")); } jobService.CreateProductionJob(productionJob); var results = dbcontext.SaveChanges(); if (results > 0) { return(Content((HttpStatusCode)201, "Production Job Posting Created")); } else { throw new ZeroAffectedRowsException(); } } catch (ZeroAffectedRowsException) { return(Content((HttpStatusCode)500, "There appears to be no changes made. The job posting was not created")); } catch (DbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to created the requested job posting")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
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)); } }
public void ProductionController_DeleteProductionDateTime_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", 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 1", DirectorFirstName = "Doris", DirectorLastName = "Day", City = "San Diego", StateProvince = "California", Country = "U.S", TheaterID = theater.TheaterID, Street = "1234 Sesame St", Zipcode = "91911" }; productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/28/2019 3:22:29 PM"); var time = TimeSpan.Parse("11:30:00"); var productionDateTime = new ProductionDateTime(production.ProductionID, date, time); productionService.CreateProductionDateTime(production.ProductionID, productionDateTime); dbcontext.SaveChanges(); var productionController = new ProductionController(); // Act var actionResult = productionController.deleteProductiondateTime(productionDateTime.ProductionDateTimeId, productionDateTime); var response = actionResult as OkNegotiatedContentResult <string>; var dbcontext_ = new BroadwayBuilderContext(); var theaterService_ = new TheaterService(dbcontext_); var theater_ = theaterService.GetTheaterByID(theater.TheaterID); theaterService_.DeleteTheater(theater_); dbcontext_.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual("Production date time deleted succesfully!", response.Content); }
public void ProductionController_UpdateProductionDateTime_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", 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 1", DirectorFirstName = "Doris", DirectorLastName = "Day", City = "San Diego", StateProvince = "California", Country = "U.S", TheaterID = theater.TheaterID, Street = "1234 Sesame St", Zipcode = "91911" }; productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/28/2019 3:22:29 PM"); var time = TimeSpan.Parse("11:30:00"); var productionDateTime = new ProductionDateTime(production.ProductionID, date, time); productionService.CreateProductionDateTime(production.ProductionID, productionDateTime); dbcontext.SaveChanges(); productionDateTime.Date = DateTime.Parse("3/27/2019 3:22:29 PM"); productionDateTime.Time = TimeSpan.Parse("9:30:00"); var productionController = new ProductionController(); // Act var actionResult = productionController.updateProductionDateTime(productionDateTime.ProductionDateTimeId, productionDateTime); var response = actionResult as OkNegotiatedContentResult <ProductionDateTime>; var updatedProductionDateTime = response.Content; var expected = new { DateTime = DateTime.Parse("3/27/2019 3:22:29 PM"), TimeSpan = TimeSpan.Parse("9:30:00") }; var actual = updatedProductionDateTime; productionService.DeleteProductionDateTime(productionDateTime); dbcontext.SaveChanges(); productionService.DeleteProduction(response.Content.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual(productionDateTime.ProductionDateTimeId, updatedProductionDateTime.ProductionDateTimeId); Assert.AreEqual(expected.DateTime, actual.Date); Assert.AreEqual(expected.TimeSpan, actual.Time); }
public IHttpActionResult UploadProductionProgram(int productionId) { var dbcontext = new BroadwayBuilderContext(); var productionService = new ProductionService(dbcontext); //try to upload pdf and save to server filesystem try { //get the content, headers, etc the full request of the current http request var httpRequest = HttpContext.Current.Request; //A list in case we want to accept more than one file type IList <string> AllowedFileExtension = new List <string> { ".pdf" }; // Todo: Check if length of httpRequest.Files == 1 to ensure only 1 file is uploaded // Max file size is 1MB int MaxContentLength = 1024 * 1024 * 1; foreach (string filename in httpRequest.Files) { // Grab current file of the request var putFile = httpRequest.Files[filename]; // Continue if the file has content if (putFile != null && putFile.ContentLength > 0) { // Checks the current extension of the current file var ext = putFile.FileName.Substring(putFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); // File extension is not valid if (!AllowedFileExtension.Contains(extension)) { //var message = string.Format("Please Upload image of type .pdf only"); // Todo: Log the error that occurs return(BadRequest("File needs to be of type pdf")); } // File size is too big else if (putFile.ContentLength > MaxContentLength) { //var message = string.Format("Please Upload a file upto 1 mb."); // Todo: log the error that occurs return(BadRequest("File exceeds max limit of 1 MB")); } // Send to production service where functinality to save the file is else { // check if id is null or not then proceed productionService.UploadProgram(productionId, extension, putFile); } } // Todo: Create an ErrorMessage model //var message1 = string.Format("Image Updated Successfully."); //return Created(insert path); //return Created("C:\\Users\\ProductionPrograms"); return(Ok("Pdf Uploaded")); } // Todo: Create an ErrorMessage model //var res = string.Format("Please Upload an image."); // Todo: log the error that occurs return(BadRequest("Please upload an image")); } catch (Exception ex) { // Todo: add proper error handling // Todo: log error return(BadRequest("Was not able to upload the image")); } }
public ProductionJobService(BroadwayBuilderContext dbContext) { this._dbContext = dbContext; }
public RoleService(BroadwayBuilderContext dbcontext) { this._dbContext = dbcontext; }
public IHttpActionResult LoginFromSSO([FromBody] LoginRequestModel request) { using (var _dbcontext = new BroadwayBuilderContext()) { try { ControllerHelper.ValidateLoginRequestModel(ModelState, request); Guid userSsoId = ControllerHelper.ParseAndCheckId(request.SSOUserId); SignatureService signatureService = new SignatureService(); // Check if the signature is invalid if (!signatureService.IsValidClientRequest(request.SSOUserId, request.Email, request.Timestamp, request.Signature)) { return(Content(HttpStatusCode.Unauthorized, "Invalid Signature Token")); } // Now we have to get a user (check if it exists) UserService userService = new UserService(_dbcontext); User user; try { user = userService.GetUser(request.Email); } catch (UserNotFoundException ex) { var newUser = new User() { UserGuid = userSsoId, Username = request.Email, DateCreated = DateTime.UtcNow, IsEnabled = false, IsComplete = false }; userService.CreateUser(newUser); user = newUser; // Everyone starts off as a general user userService.AddUserRole(user.UserId, DataAccessLayer.Enums.RoleEnum.GeneralUser); } // User was found, so login user Session session = new Session() { UserId = user.UserId, Token = Guid.NewGuid().ToString(), Signature = request.Signature, CreatedAt = DateTime.UtcNow, ExpiresAt = DateTime.UtcNow.AddMinutes(30), UpdatedAt = DateTime.UtcNow, Id = Guid.NewGuid(), }; _dbcontext.Sessions.Add(session); _dbcontext.SaveChanges(); //Logging Usage //TODO: possibly change the userid argument for LogUsage LoggerHelper.LogUsage("Login", user.UserId); var redirectURL = $"https://ui.broadwaybuilder.xyz/#/login?token={session.Token}"; return(Redirect(redirectURL)); } catch (Exception e) { return(InternalServerError(e)); //TODO: LogError } } }
public void ProductionService_DeleteProductionDateTime_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", 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 1", DirectorFirstName = "Doris", DirectorLastName = "Day", City = "San Diego", StateProvince = "California", Country = "U.S", TheaterID = theater.TheaterID, Street = "1234 Sesame St", Zipcode = "91911" }; productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/28/2019 3:22:29 PM"); var time = TimeSpan.Parse("11:30:00"); var productionDateTime = new ProductionDateTime(production.ProductionID, date, time); productionService.CreateProductionDateTime(production.ProductionID, productionDateTime); dbcontext.SaveChanges(); var expected = true; var actual = false; // Act productionService.DeleteProductionDateTime(productionDateTime); var affectedRows = dbcontext.SaveChanges(); if (affectedRows > 0) { actual = true; } // Assert productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected, actual); }
public void ProductionService_GetProductionsByCurrentDate_Pass() { // Arrange // 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 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 expected = true; var actual = false; // Act var readProductionsList = productionService.GetProductionsByCurrentAndFutureDate(new DateTime(2019, 3, 1), null, 1, 10); // Theater id is meant to be null if (readProductionsList != null) { actual = true; } // Assert 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.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); }
public ProductionService(BroadwayBuilderContext dbcontext) { _dbContext = dbcontext; }
public IHttpActionResult GetProductions(DateTime?currentDate = null, DateTime?previousDate = null, int?theaterID = null, int pageNum = 1, int pageSize = 10) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); if (previousDate != null || currentDate == null) { var productionResponses = productionService.GetProductionsByPreviousDate((DateTime)previousDate, theaterID, pageNum, pageSize) .Select(production => new ProductionResponseModel() { DirectorFirstName = production.DirectorFirstName, DirectorLastName = production.DirectorLastName, ProductionID = production.ProductionID, ProductionName = production.ProductionName, StateProvince = production.StateProvince, Street = production.Street, TheaterID = production.TheaterID, Zipcode = production.Zipcode, City = production.City, Country = production.Country, DateTimes = production.ProductionDateTime.Select(datetime => new ProductionDateTimeResponseModel() { Date = datetime.Date, ProductionDateTimeId = datetime.ProductionDateTimeId, Time = datetime.Time }).ToList() }).ToList(); return(Ok(productionResponses)); } else { var productionResponses = productionService.GetProductionsByCurrentAndFutureDate((DateTime)currentDate, theaterID, pageNum, pageSize) .Select(production => new ProductionResponseModel() { City = production.City, DirectorFirstName = production.DirectorFirstName, DirectorLastName = production.DirectorLastName, Country = production.Country, ProductionID = production.ProductionID, ProductionName = production.ProductionName, StateProvince = production.StateProvince, Street = production.Street, TheaterID = production.TheaterID, Zipcode = production.Zipcode, DateTimes = production.ProductionDateTime.Select(datetime => new ProductionDateTimeResponseModel() { Date = datetime.Date, ProductionDateTimeId = datetime.ProductionDateTimeId, Time = datetime.Time }).ToList() }).ToList(); return(Ok(productionResponses)); } } } catch (DbUpdateException e) // Todo: Log Error { return(Content((HttpStatusCode)500, e.Message)); } // Todo: Add proper exception handling for getting a production catch (Exception e) // Todo: Log Error Might not catch this since okay with returning [] emtpy list { return(BadRequest()); } }
public IHttpActionResult uploadPhoto(int productionId) { var dbcontext = new BroadwayBuilderContext(); var productionService = new ProductionService(dbcontext); //try to upload pdf and save to server filesystem try { //get the content, headers, etc the full request of the current http request var httpRequest = HttpContext.Current.Request; // Todo: Check if length of httpRequest.Files <= 10 to ensure only 10 photos is uploaded // A list in case we want to accept more than one file type IList <string> AllowedFileExtension = new List <string> { ".jpg" }; // Max file size is 1MB int MaxContentLength = 1 * 1024 * 1024 * 5; //Size = 5 MB var count = 0; for (int i = 0; i < httpRequest.Files.Count; i++) { // Grab current file of the request //var putFile = httpRequest.Files[filename]; var putFile = httpRequest.Files[i]; // Continue if the file has content if (putFile != null && putFile.ContentLength > 0) { // Checks the current extension of the current file var ext = putFile.FileName.Substring(putFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); // File extension is not valid if (!AllowedFileExtension.Contains(extension)) { //var message = string.Format("Please Upload image of type .jpg only"); // Todo: Log the error that occurs return(BadRequest("Please upload image of type .jpg only")); } // File size is too big else if (putFile.ContentLength > MaxContentLength) { //var message = string.Format("Please Upload a file upto 1 mb."); // Todo: log the error that occurs return(BadRequest("Please upload a file upto 1mb")); } // Send to production service where functinality to save the file is else { productionService.UploadPhoto(productionId, count, extension, putFile); } } count++; } return(Ok("Photo Uploaded")); } catch (Exception ex) { // Todo: add proper error handling // Todo: log error return(BadRequest("Photo could not be uploaded...dont know why.find out and add detailed message here!")); } }
public IHttpActionResult UploadResume(int userId) { //A list in case we want to accept more than one file type List <string> allowedFileExtension = new List <string> { ".pdf" }; //Business Rule - only one file allowed to submit int maxFileCount = 1; // Max file size is 1MB const int maxContentLength = 1024 * 1024 * 1; try { //get the content, headers, etc the full request of the current http request var httpRequest = HttpContext.Current.Request; var fileValidator = new FileValidator(); //Validate the submitted file to verify that it complies with Business Rules var validationResult = fileValidator.ValidateFiles(httpRequest.Files, allowedFileExtension, maxContentLength, maxFileCount); if (!validationResult.ValidationSuccessful)//if one or more business rules were violated { var errorMessage = string.Join("\n", validationResult.Reasons); return(Content((HttpStatusCode)406, errorMessage)); } // Grab current file of the request var postedFile = httpRequest.Files[0]; using (var dbContext = new BroadwayBuilderContext()) { var userService = new UserService(dbContext); User user = userService.GetUser(userId); if (user == null)//check if user exists { return(Content((HttpStatusCode)404, "There is no record of that User.")); } var resumeService = new ResumeService(dbContext); Resume resume = resumeService.GetResumeByUserID(userId); if (resume == null)//check if user has already submitted a resume { Resume userResume = new Resume(userId, Guid.NewGuid()); resumeService.CreateResume(userResume); var result = dbContext.SaveChanges(); if (result <= 0) { return(Content((HttpStatusCode)500, "Failed to add a resume onto our database")); } resume = userResume; } //Folder path of the user var subdir = Path.Combine(ConfigurationManager.AppSettings["ResumeDir"], (resume.ResumeGuid.ToString() + "/")); //@"C:\Resumes\"+resume.ResumeGuid; //Filepath of the submitted file var filePath = Path.Combine(subdir, resume.ResumeGuid.ToString() + ".pdf"); // subdir+@"\"+resume.ResumeGuid+".pdf"; if (!Directory.Exists(subdir)) //check if the directory exists { Directory.CreateDirectory(subdir); //create the directory if it doesnt exist } //saves file onto the specified file path and overwrites any file that may exist in that shares the same path postedFile.SaveAs(filePath); return(Content((HttpStatusCode)200, "File Uploaded")); } } catch (HttpException e)//HttpPostedFile.SaveAs exception { return(Content((HttpStatusCode)500, "Unable to save the file onto our file system.")); } catch (IOException e)//Exception thrown when creating directory { return(Content((HttpStatusCode)500, "Unable to delete the job posting")); } catch (DbUpdateException e)//exception thrown while saving the database { return(Content((HttpStatusCode)500, "Unable to delete the job posting")); } catch (DbEntityValidationException dbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to delete the job posting")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } }
// Constructor public PermissionService(BroadwayBuilderContext Context) { this._dbContext = Context; }
public void ProductionService_UpdateProduction_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", 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 Lion King", DirectorFirstName = "Jane", DirectorLastName = "Doe", Street = "Anahiem", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; productionService.CreateProduction(production); dbcontext.SaveChanges(); production.ProductionName = "The Lion King 2"; production.StateProvince = "Utah"; production.DirectorLastName = "Mangos"; var expected = new List <string>() { "The Lion King 2", "Utah", "Mangos" }; // Act var actual = productionService.UpdateProduction(production); dbcontext.SaveChanges(); // Assert productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected[0], actual.ProductionName); Assert.AreEqual(expected[1], actual.StateProvince); Assert.AreEqual(expected[2], actual.DirectorLastName); }
public TheaterJobService(BroadwayBuilderContext dbContext) { this._dbContext = dbContext; }
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 async Task ProductionController_CreateProduction_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); /* * Info: * Using Self Hosting of api in order to make a request * */ var baseAddress = new Uri("http://localhost:8000/"); var config = new HttpSelfHostConfiguration(baseAddress); WebApiConfig.Register(config); var server = new HttpSelfHostServer(config); var client = new HttpClient(server) { BaseAddress = baseAddress }; // Act var response = await client.PostAsync <Production>("production/create", production, new JsonMediaTypeFormatter()); productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response); var success = response.TryGetContentValue(out ProductionResponseModel productionFromResponse); Assert.IsTrue(success); //Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.IsNotNull(productionFromResponse); }
public AuthorizationService(BroadwayBuilderContext dbcontext) { //Initialize the DbContext this._dbContext = dbcontext; }
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); }
public ResumeTheaterJobService(BroadwayBuilderContext context) { this._dbContext = context; }
public void ProductionController_UpdateProduction_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", 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 Lion King", DirectorFirstName = "Jane", DirectorLastName = "Doe", Street = "Anahiem", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; production.ProductionName = "The Updated Lion King"; production.StateProvince = "Utah"; production.DirectorLastName = "Mangos"; productionService.CreateProduction(production); dbcontext.SaveChanges(); var productionController = new ProductionController(); // Act var actionResult = productionController.UpdateProduction(production); var response = actionResult as OkNegotiatedContentResult <Production>; var updatedProduction = response.Content; productionService.DeleteProduction(response.Content.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual(production.ProductionID, updatedProduction.ProductionID); Assert.AreEqual("The Updated Lion King", updatedProduction.ProductionName); Assert.AreEqual("Utah", updatedProduction.StateProvince); Assert.AreEqual("Mangos", updatedProduction.DirectorLastName); }
/// <summary> /// Initializes the BroadwayBuilderContext to an instance of the context passed as an argument /// </summary> /// <param name="context"></param> public UserService(BroadwayBuilderContext context) { this._dbContext = context; }
public IHttpActionResult GetProductions(DateTime?currentDate = null, DateTime?previousDate = null, int?theaterID = null) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); try { if (previousDate != null) { var productionResponses = productionService.GetProductionsByPreviousDate((DateTime)previousDate, theaterID) .Select(production => new ProductionResponseModel() { DirectorFirstName = production.DirectorFirstName, DirectorLastName = production.DirectorLastName, ProductionID = production.ProductionID, ProductionName = production.ProductionName, StateProvince = production.StateProvince, Street = production.Street, TheaterID = production.TheaterID, Zipcode = production.Zipcode, City = production.City, Country = production.Country, DateTimes = production.ProductionDateTime.Select(datetime => new ProductionDateTimeResponseModel() { Date = datetime.Date, ProductionDateTimeId = datetime.ProductionDateTimeId, Time = datetime.Time }).ToList() }).ToList(); return(Ok(productionResponses)); } else if (currentDate != null) { var productionResponses = productionService.GetProductionsByCurrentAndFutureDate((DateTime)currentDate) .Select(production => new ProductionResponseModel() { City = production.City, DirectorFirstName = production.DirectorFirstName, DirectorLastName = production.DirectorLastName, Country = production.Country, ProductionID = production.ProductionID, ProductionName = production.ProductionName, StateProvince = production.StateProvince, Street = production.Street, TheaterID = production.TheaterID, Zipcode = production.Zipcode, DateTimes = production.ProductionDateTime.Select(datetime => new ProductionDateTimeResponseModel() { Date = datetime.Date, ProductionDateTimeId = datetime.ProductionDateTimeId, Time = datetime.Time }).ToList() }).ToList(); return(Ok(productionResponses)); } // none of the if conditions were met therfore... return(BadRequest("PreviousDate and Current date were both null")); } // Todo: Add proper exception handling for getting a production catch (Exception e) { return(BadRequest()); } } } catch (Exception e) // Todo: Catch a SqlException ... or Sqlconnection exception? { return(BadRequest("Something big went bad!")); } }