public void HelpController_Edit_Update_HttpPost_WithFileCallsAssetInsertAndContextHelpRefDataUpdateForValidModelAndAction() { #region Arrange var file = new Mock <HttpPostedFileBase>(); const string action = "update"; var model = new ContextHelpRefDataViewModel { Id = 1, Key = "homepage", Title = "Home Page", HelpText = "New amazing help text!", HelpVideoFile = file.Object }; #endregion #region Act _mockController.Edit(model, action); #endregion #region Assert _mockContextHelpRefDataService.Verify(x => x.Update(It.IsAny <ContextHelpRefData>()), Times.Once); #endregion }
public void HelpController_Edit_Update_HttpPost_WithoutFileCallsContextHelpRefDataUpdateOnlyForValidModelAndAction() { #region Arrange const string action = "update"; var model = new ContextHelpRefDataViewModel { Id = 1, Key = "homepage", Title = "Home Page", HelpText = "New amazing help text!" }; #endregion #region Act _mockController.Edit(model, action); #endregion #region Assert _mockContextHelpRefDataService.Verify(x => x.Update(It.IsAny <ContextHelpRefData>()), Times.Once); #endregion }
public ActionResult Edit(string helpKey) { // Check if we have help in the database var dbHelp = _contextHelpRefDataService.GetByHelpKey(helpKey); if (dbHelp == null) { return(RedirectToAction("Index", helpKey)); } var helpModel = new ContextHelpRefDataViewModel { Id = dbHelp.Id, HelpText = dbHelp.HelpText, Key = dbHelp.Key, Title = dbHelp.Title, }; if (dbHelp.Asset != null) { helpModel.HelpVideoTitle = dbHelp.Asset.OriginalFileName; helpModel.HelpVideoFileName = dbHelp.Asset.FileName; helpModel.HelpVideoFileExtension = dbHelp.Asset.FileExtension.Substring(1); } return(View(helpModel)); }
public void HelpController_Edit_Cancel_HttpPost_RedirectsToCorrectControllerAndActionForValidModelAndAction() { const string expectedAction = "Index"; const string expectedController = "Help"; const string action = "cancel"; var model = new ContextHelpRefDataViewModel { Id = 1, Key = "homepage", Title = "Home Page", HelpText = "New amazing help text! With some new text but user decided to cancel :-(" }; var result = _mockController.Edit(model, action) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual(expectedAction, result.RouteValues["action"]); Assert.AreEqual(expectedController, result.RouteValues["controller"]); }
public ActionResult Index(string helpKey) { // Check if we have help in the database var dbHelp = _contextHelpRefDataService.GetByHelpKey(helpKey); // Create the model for the help page var helpModel = new ContextHelpRefDataViewModel { HelpText = "<p>There is no help available for this page</p>" }; // If we have help the use the text if (dbHelp != null) { helpModel.HelpText = dbHelp.HelpText; helpModel.Key = dbHelp.Key; helpModel.Title = dbHelp.Title; if (dbHelp.Asset != null) { helpModel.HelpVideoTitle = dbHelp.Asset.OriginalFileName; helpModel.HelpVideoFileName = dbHelp.Asset.FileName; helpModel.HelpVideoFileExtension = dbHelp.Asset.FileExtension.Substring(1); } } else { helpModel.Key = helpKey; helpModel.Title = string.Empty; // Create Help var help = Mapper.Map <ContextHelpRefDataViewModel, ContextHelpRefData>(helpModel); _contextHelpRefDataService.Create(help); helpModel.Id = help.Id; } return(View(helpModel)); }
public ActionResult Edit(ContextHelpRefDataViewModel model, string button) { if (model != null && ModelState.IsValid) { if (button.ToLower().Equals("update")) { var help = _contextHelpRefDataService.GetById(model.Id); help.Title = model.Title; help.HelpText = model.HelpText; // Update Help if (model.HelpVideoFile != null) { var folder = SettingsHelper.HelpVideoFileLocation; var fullPath = string.Empty; try { // If the folder doesn't exist then create if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var originalFullFileName = model.HelpVideoFile.FileName; var fileName = Guid.NewGuid(); var fileExtension = Path.GetExtension(originalFullFileName); fullPath = Path.Combine(folder, fileName + fileExtension); model.HelpVideoFile.SaveAs(fullPath); var asset = new Asset { OriginalFileName = Path.GetFileNameWithoutExtension(originalFullFileName), FileName = fileName.ToString(), FileExtension = fileExtension, FullPath = fullPath, MimeType = MimeMapping.GetMimeMapping(fullPath), ContextHelpRefDatas = new List <ContextHelpRefData> { help } }; _assetRepository.Insert(asset); help.Asset = asset; _contextHelpRefDataService.Update(help); } catch (Exception) { // Tidy up the file if it has not been deleted if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } throw; } } else { _contextHelpRefDataService.Update(help); } } } return(RedirectToAction("Index", "Help", new { helpKey = model?.Key ?? "homepage" })); }