abstracts out IScript, stops casting stuff
This commit is contained in:
7
src/Umbraco.Abstractions/Models/IScript.cs
Normal file
7
src/Umbraco.Abstractions/Models/IScript.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IScript : IFile
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class Script : File
|
||||
public class Script : File, IScript
|
||||
{
|
||||
public Script(string path)
|
||||
: this(path, (Func<File, string>) null)
|
||||
@@ -25,9 +25,6 @@ namespace Umbraco.Core.Models
|
||||
/// <remarks>
|
||||
/// Overrides the default Entity identity check.
|
||||
/// </remarks>
|
||||
public override bool HasIdentity
|
||||
{
|
||||
get { return string.IsNullOrEmpty(Path) == false; }
|
||||
}
|
||||
public override bool HasIdentity => string.IsNullOrEmpty(Path) == false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IScriptRepository : IReadRepository<string, Script>, IWriteRepository<Script>
|
||||
public interface IScriptRepository : IReadRepository<string, IScript>, IWriteRepository<IScript>
|
||||
{
|
||||
bool ValidateScript(Script script);
|
||||
bool ValidateScript(IScript script);
|
||||
Stream GetFileContentStream(string filepath);
|
||||
void SetFileContent(string filepath, Stream content);
|
||||
long GetFileSize(string filepath);
|
||||
|
||||
void AddFolder(string folderPath);
|
||||
void DeleteFolder(string folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
Stream GetFileContentStream(string filepath);
|
||||
void SetFileContent(string filepath, Stream content);
|
||||
long GetFileSize(string filepath);
|
||||
|
||||
void AddFolder(string folderPath);
|
||||
void DeleteFolder(string folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
/// <summary>
|
||||
/// Represents the Script Repository
|
||||
/// </summary>
|
||||
internal class ScriptRepository : FileRepository<string, Script>, IScriptRepository
|
||||
internal class ScriptRepository : FileRepository<string, IScript>, IScriptRepository
|
||||
{
|
||||
private readonly IContentSection _contentConfig;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public ScriptRepository(IFileSystems fileSystems, IContentSection contentConfig)
|
||||
public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper)
|
||||
: base(fileSystems.ScriptsFileSystem)
|
||||
{
|
||||
_contentConfig = contentConfig ?? throw new ArgumentNullException(nameof(contentConfig));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
#region Implementation of IRepository<string,Script>
|
||||
|
||||
public override Script Get(string id)
|
||||
public override IScript Get(string id)
|
||||
{
|
||||
// get the relative path within the filesystem
|
||||
// (though... id should be relative already)
|
||||
@@ -55,16 +55,19 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return script;
|
||||
}
|
||||
|
||||
public override void Save(Script entity)
|
||||
public override void Save(IScript entity)
|
||||
{
|
||||
base.Save(entity);
|
||||
// TODO: Casting :/ Review GetFileContent and it's usages, need to look into it later
|
||||
var script = (Script) entity;
|
||||
|
||||
base.Save(script);
|
||||
|
||||
// ensure that from now on, content is lazy-loaded
|
||||
if (entity.GetFileContent == null)
|
||||
entity.GetFileContent = file => GetFileContent(file.OriginalPath);
|
||||
if (script.GetFileContent == null)
|
||||
script.GetFileContent = file => GetFileContent(file.OriginalPath);
|
||||
}
|
||||
|
||||
public override IEnumerable<Script> GetMany(params string[] ids)
|
||||
public override IEnumerable<IScript> GetMany(params string[] ids)
|
||||
{
|
||||
//ensure they are de-duplicated, easy win if people don't do this as this can cause many excess queries
|
||||
ids = ids.Distinct().ToArray();
|
||||
@@ -86,7 +89,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateScript(Script script)
|
||||
public bool ValidateScript(IScript script)
|
||||
{
|
||||
// get full path
|
||||
string fullPath;
|
||||
@@ -102,9 +105,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
// validate path & extension
|
||||
var validDir = SystemDirectories.Scripts;
|
||||
var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir);
|
||||
var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir);
|
||||
var validExts = new[] {"js"};
|
||||
var isValidExtension = Current.IOHelper.VerifyFileExtension(script.Path, validExts);
|
||||
var isValidExtension = _ioHelper.VerifyFileExtension(script.Path, validExts);
|
||||
return isValidPath && isValidExtension;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
public override void Save(IStylesheet entity)
|
||||
{
|
||||
// TODO: Casting :/ Do we need GetFileContent below? Need to look into it later
|
||||
// TODO: Casting :/ Review GetFileContent and it's usages, need to look into it later
|
||||
var stylesheet = (Stylesheet)entity;
|
||||
|
||||
base.Save(stylesheet);
|
||||
|
||||
@@ -24,26 +24,26 @@ namespace Umbraco.Core.Services
|
||||
bool DeletePartialViewMacro(string path, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = Constants.Security.SuperUserId);
|
||||
bool ValidatePartialView(PartialView partialView);
|
||||
bool ValidatePartialViewMacro(PartialView partialView);
|
||||
bool ValidatePartialView(IPartialView partialView);
|
||||
bool ValidatePartialViewMacro(IPartialView partialView);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Stylesheet"/> objects
|
||||
/// Gets a list of all <see cref="IStylesheet"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
/// <returns>An enumerable list of <see cref="IStylesheet"/> objects</returns>
|
||||
IEnumerable<IStylesheet> GetStylesheets(params string[] names);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Stylesheet"/> object by its name
|
||||
/// Gets a <see cref="IStylesheet"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the stylesheet incl. extension</param>
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
/// <returns>A <see cref="IStylesheet"/> object</returns>
|
||||
IStylesheet GetStylesheetByName(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Stylesheet"/>
|
||||
/// Saves a <see cref="IStylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
|
||||
/// <param name="stylesheet"><see cref="IStylesheet"/> to save</param>
|
||||
/// <param name="userId">Optional id of the user saving the stylesheet</param>
|
||||
void SaveStylesheet(IStylesheet stylesheet, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
@@ -55,31 +55,31 @@ namespace Umbraco.Core.Services
|
||||
void DeleteStylesheet(string path, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Stylesheet"/>
|
||||
/// Validates a <see cref="IStylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to validate</param>
|
||||
/// <param name="stylesheet"><see cref="IStylesheet"/> to validate</param>
|
||||
/// <returns>True if Stylesheet is valid, otherwise false</returns>
|
||||
bool ValidateStylesheet(IStylesheet stylesheet);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Script"/> objects
|
||||
/// Gets a list of all <see cref="IScript"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
|
||||
IEnumerable<Script> GetScripts(params string[] names);
|
||||
/// <returns>An enumerable list of <see cref="IScript"/> objects</returns>
|
||||
IEnumerable<IScript> GetScripts(params string[] names);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Script"/> object by its name
|
||||
/// Gets a <see cref="IScript"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the script incl. extension</param>
|
||||
/// <returns>A <see cref="Script"/> object</returns>
|
||||
Script GetScriptByName(string name);
|
||||
/// <returns>A <see cref="IScript"/> object</returns>
|
||||
IScript GetScriptByName(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to save</param>
|
||||
/// <param name="script"><see cref="IScript"/> to save</param>
|
||||
/// <param name="userId">Optional id of the user saving the script</param>
|
||||
void SaveScript(Script script, int userId = Constants.Security.SuperUserId);
|
||||
void SaveScript(IScript script, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a script by its name
|
||||
@@ -89,11 +89,11 @@ namespace Umbraco.Core.Services
|
||||
void DeleteScript(string path, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Script"/>
|
||||
/// Validates a <see cref="IScript"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to validate</param>
|
||||
/// <param name="script"><see cref="IScript"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
bool ValidateScript(Script script);
|
||||
bool ValidateScript(IScript script);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a folder for scripts
|
||||
@@ -213,7 +213,7 @@ namespace Umbraco.Core.Services
|
||||
/// Validates a <see cref="ITemplate"/>
|
||||
/// </summary>
|
||||
/// <param name="template"><see cref="ITemplate"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
/// <returns>True if template is valid, otherwise false</returns>
|
||||
bool ValidateTemplate(ITemplate template);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -45,10 +45,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
#region Stylesheets
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Stylesheet"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IStylesheet> GetStylesheets(params string[] names)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
@@ -57,11 +54,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Stylesheet"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the stylesheet incl. extension</param>
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
/// <inheritdoc />
|
||||
public IStylesheet GetStylesheetByName(string name)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
@@ -70,11 +63,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
|
||||
/// <param name="userId"></param>
|
||||
/// <inheritdoc />
|
||||
public void SaveStylesheet(IStylesheet stylesheet, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
@@ -96,11 +85,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a stylesheet by its name
|
||||
/// </summary>
|
||||
/// <param name="path">Name incl. extension of the Stylesheet to delete</param>
|
||||
/// <param name="userId"></param>
|
||||
/// <inheritdoc />
|
||||
public void DeleteStylesheet(string path, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
@@ -128,11 +113,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to validate</param>
|
||||
/// <returns>True if Stylesheet is valid, otherwise false</returns>
|
||||
/// <inheritdoc />
|
||||
public bool ValidateStylesheet(IStylesheet stylesheet)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
@@ -145,7 +126,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
((StylesheetRepository) _stylesheetRepository).AddFolder(folderPath);
|
||||
_stylesheetRepository.AddFolder(folderPath);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
@@ -154,7 +135,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
((StylesheetRepository) _stylesheetRepository).DeleteFolder(folderPath);
|
||||
_stylesheetRepository.DeleteFolder(folderPath);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
@@ -188,11 +169,8 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
#region Scripts
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Script"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
|
||||
public IEnumerable<Script> GetScripts(params string[] names)
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IScript> GetScripts(params string[] names)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -200,12 +178,8 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Script"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the script incl. extension</param>
|
||||
/// <returns>A <see cref="Script"/> object</returns>
|
||||
public Script GetScriptByName(string name)
|
||||
/// <inheritdoc />
|
||||
public IScript GetScriptByName(string name)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -213,16 +187,12 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to save</param>
|
||||
/// <param name="userId"></param>
|
||||
public void SaveScript(Script script, int userId = Constants.Security.SuperUserId)
|
||||
/// <inheritdoc />
|
||||
public void SaveScript(IScript script, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var saveEventArgs = new SaveEventArgs<Script>(script);
|
||||
var saveEventArgs = new SaveEventArgs<IScript>(script);
|
||||
if (scope.Events.DispatchCancelable(SavingScript, this, saveEventArgs))
|
||||
{
|
||||
scope.Complete();
|
||||
@@ -238,11 +208,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a script by its name
|
||||
/// </summary>
|
||||
/// <param name="path">Name incl. extension of the Script to delete</param>
|
||||
/// <param name="userId"></param>
|
||||
/// <inheritdoc />
|
||||
public void DeleteScript(string path, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
@@ -254,7 +220,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
return;
|
||||
}
|
||||
|
||||
var deleteEventArgs = new DeleteEventArgs<Script>(script);
|
||||
var deleteEventArgs = new DeleteEventArgs<IScript>(script);
|
||||
if (scope.Events.DispatchCancelable(DeletingScript, this, deleteEventArgs))
|
||||
{
|
||||
scope.Complete();
|
||||
@@ -270,12 +236,8 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
public bool ValidateScript(Script script)
|
||||
/// <inheritdoc />
|
||||
public bool ValidateScript(IScript script)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -287,7 +249,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
((ScriptRepository) _scriptRepository).AddFolder(folderPath);
|
||||
_scriptRepository.AddFolder(folderPath);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
@@ -296,7 +258,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
((ScriptRepository) _scriptRepository).DeleteFolder(folderPath);
|
||||
_scriptRepository.DeleteFolder(folderPath);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
@@ -907,7 +869,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
return Attempt.Succeed(partialView);
|
||||
}
|
||||
|
||||
public bool ValidatePartialView(PartialView partialView)
|
||||
public bool ValidatePartialView(IPartialView partialView)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -915,7 +877,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidatePartialViewMacro(PartialView partialView)
|
||||
public bool ValidatePartialViewMacro(IPartialView partialView)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -1106,12 +1068,12 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<Script>> DeletingScript;
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<IScript>> DeletingScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Delete
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<Script>> DeletedScript;
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<IScript>> DeletedScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
@@ -1136,12 +1098,12 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavingScript;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<IScript>> SavingScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavedScript;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<IScript>> SavedScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
|
||||
@@ -6,6 +6,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -33,6 +34,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
}
|
||||
}
|
||||
|
||||
private IScriptRepository CreateRepository()
|
||||
{
|
||||
return new ScriptRepository(_fileSystems, new IOHelper());
|
||||
}
|
||||
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
@@ -48,7 +54,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
// Act
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Assert
|
||||
Assert.That(repository, Is.Not.Null);
|
||||
@@ -62,7 +68,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Act
|
||||
var script = new Script("test-add-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
@@ -81,7 +87,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Act
|
||||
var script = new Script("test-updated-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
@@ -107,7 +113,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Act
|
||||
var script = repository.Get("test-script.js");
|
||||
@@ -127,7 +133,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Act
|
||||
var exists = repository.Get("test-script.js");
|
||||
@@ -146,7 +152,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
repository.Save(script);
|
||||
@@ -174,7 +180,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
repository.Save(script);
|
||||
@@ -202,7 +208,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
// Act
|
||||
var exists = repository.Exists("test-script.js");
|
||||
@@ -221,9 +227,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
var script = new Script("test-move-script.js") { Content = content };
|
||||
IScript script = new Script("test-move-script.js") { Content = content };
|
||||
repository.Save(script);
|
||||
|
||||
|
||||
@@ -254,9 +260,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var provider = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new ScriptRepository(_fileSystems, Mock.Of<IContentSection>());
|
||||
var repository = CreateRepository();
|
||||
|
||||
var script = new Script("test-path-1.js") { Content = "// script" };
|
||||
IScript script = new Script("test-path-1.js") { Content = "// script" };
|
||||
repository.Save(script);
|
||||
|
||||
Assert.IsTrue(_fileSystem.FileExists("test-path-1.js"));
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Umbraco.Web.Editors
|
||||
var script = Services.FileService.GetScriptByName(virtualPath);
|
||||
if (script != null)
|
||||
{
|
||||
var display = Mapper.Map<Script, CodeFileDisplay>(script);
|
||||
var display = Mapper.Map<IScript, CodeFileDisplay>(script);
|
||||
display.FileType = Core.Constants.Trees.Scripts;
|
||||
display.Path = Url.GetTreePathFromFilePath(script.Path);
|
||||
display.Id = System.Web.HttpUtility.UrlEncode(script.Path);
|
||||
@@ -503,7 +503,7 @@ namespace Umbraco.Web.Editors
|
||||
/// It's important to note that Scripts are DIFFERENT from cshtml files since scripts use IFileSystem and cshtml files
|
||||
/// use a normal file system because they must exist on a real file system for ASP.NET to work.
|
||||
/// </remarks>
|
||||
private Script CreateOrUpdateScript(CodeFileDisplay display)
|
||||
private IScript CreateOrUpdateScript(CodeFileDisplay display)
|
||||
{
|
||||
return CreateOrUpdateFile(display, ".js", Current.FileSystems.ScriptsFileSystem,
|
||||
name => Services.FileService.GetScriptByName(name),
|
||||
|
||||
@@ -9,17 +9,17 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
{
|
||||
mapper.Define<Stylesheet, EntityBasic>((source, context) => new EntityBasic(), Map);
|
||||
mapper.Define<IStylesheet, EntityBasic>((source, context) => new EntityBasic(), Map);
|
||||
mapper.Define<IPartialView, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
|
||||
mapper.Define<Script, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
|
||||
mapper.Define<Stylesheet, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
|
||||
mapper.Define<IScript, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
|
||||
mapper.Define<IStylesheet, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
|
||||
mapper.Define<CodeFileDisplay, IPartialView>(Map);
|
||||
mapper.Define<CodeFileDisplay, Script>(Map);
|
||||
mapper.Define<CodeFileDisplay, IScript>(Map);
|
||||
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -Trashed -Udi -Icon
|
||||
private static void Map(Stylesheet source, EntityBasic target, MapperContext context)
|
||||
private static void Map(IStylesheet source, EntityBasic target, MapperContext context)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Id = source.Id;
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet
|
||||
private static void Map(Script source, CodeFileDisplay target, MapperContext context)
|
||||
private static void Map(IScript source, CodeFileDisplay target, MapperContext context)
|
||||
{
|
||||
target.Content = source.Content;
|
||||
target.Id = source.Id.ToString();
|
||||
@@ -48,7 +48,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet
|
||||
private static void Map(Stylesheet source, CodeFileDisplay target, MapperContext context)
|
||||
private static void Map(IStylesheet source, CodeFileDisplay target, MapperContext context)
|
||||
{
|
||||
target.Content = source.Content;
|
||||
target.Id = source.Id.ToString();
|
||||
@@ -66,7 +66,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
|
||||
// Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate -GetFileContent
|
||||
// Umbraco.Code.MapAll -Id -Key -Alias -Name -OriginalPath -Path
|
||||
private static void Map(CodeFileDisplay source, Script target, MapperContext context)
|
||||
private static void Map(CodeFileDisplay source, IScript target, MapperContext context)
|
||||
{
|
||||
target.Content = source.Content;
|
||||
target.VirtualPath = source.VirtualPath;
|
||||
|
||||
Reference in New Issue
Block a user