public void Can_Perform_Move_On_ScriptRepository() { const string content = "/// <reference name=\"MicrosoftAjax.js\"/>"; // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); var script = new Script("test-move-script.js") { Content = content }; repository.AddOrUpdate(script); unitOfWork.Commit(); // Act script = repository.Get("test-move-script.js"); script.Path = "moved/test-move-script.js"; repository.AddOrUpdate(script); unitOfWork.Commit(); var existsOld = repository.Exists("test-move-script.js"); var existsNew = repository.Exists("moved/test-move-script.js"); script = repository.Get("moved/test-move-script.js"); // Assert Assert.IsNotNull(script); Assert.IsFalse(existsOld); Assert.IsTrue(existsNew); Assert.AreEqual(content, script.Content); }
public void Can_Perform_Update_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var script = new Script("test-updated-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.Save(script); script.Content = "/// <reference name=\"MicrosoftAjax-Updated.js\"/>"; repository.Save(script); var scriptUpdated = repository.Get("test-updated-script.js"); // Assert Assert.That(_fileSystem.FileExists("test-updated-script.js"), Is.True); Assert.That(scriptUpdated.Content, Is.EqualTo("/// <reference name=\"MicrosoftAjax-Updated.js\"/>")); } }
public void Can_Perform_Update_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var script = new Script("test-updated-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script); unitOfWork.Commit(); script.Content = "/// <reference name=\"MicrosoftAjax-Updated.js\"/>"; repository.AddOrUpdate(script); unitOfWork.Commit(); var scriptUpdated = repository.Get("test-updated-script.js"); // Assert Assert.That(_fileSystem.FileExists("test-updated-script.js"), Is.True); Assert.That(scriptUpdated.Content, Is.EqualTo("/// <reference name=\"MicrosoftAjax-Updated.js\"/>")); }
public void Can_Perform_Move_On_ScriptRepository() { const string content = "/// <reference name=\"MicrosoftAjax.js\"/>"; // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); var script = new Script("test-move-script.js") { Content = content }; repository.Save(script); // Act script = repository.Get("test-move-script.js"); script.Path = "moved/test-move-script.js"; repository.Save(script); var existsOld = repository.Exists("test-move-script.js"); var existsNew = repository.Exists("moved/test-move-script.js"); script = repository.Get("moved/test-move-script.js"); // Assert Assert.IsNotNull(script); Assert.IsFalse(existsOld); Assert.IsTrue(existsNew); Assert.AreEqual(content, script.Content); } }
public void Can_Perform_Get_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); // Act var exists = repository.Get("test-script.js"); // Assert Assert.That(exists, Is.Not.Null); Assert.That(exists.Alias, Is.EqualTo("test-script")); Assert.That(exists.Name, Is.EqualTo("test-script.js")); }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var script = repository.Get("test-script.js"); repository.Delete(script); unitOfWork.Commit(); // Assert }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); // Act var script = repository.Get("test-script.js"); repository.Delete(script); unitOfWork.Commit(); // Assert Assert.IsFalse(repository.Exists("test-script.js")); }
public void Can_Perform_Get_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var exists = repository.Get("test-script.js"); // Assert Assert.That(exists, Is.Not.Null); Assert.That(exists.Alias, Is.EqualTo("test-script")); Assert.That(exists.Name, Is.EqualTo("test-script.js")); } }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var script = repository.Get("test-script.js"); repository.Delete(script); // Assert Assert.IsFalse(repository.Exists("test-script.js")); } }
public void PathTests() { // unless noted otherwise, no changes / 7.2.8 var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); var script = new Script("test-path-1.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("test-path-1.js")); Assert.AreEqual("test-path-1.js", script.Path); Assert.AreEqual("/scripts/test-path-1.js", script.VirtualPath); //ensure you can prefix the same path as the root path name script = new Script("scripts/path-2/test-path-2.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("scripts/path-2/test-path-2.js")); Assert.AreEqual("scripts\\path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2/test-path-2.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.js")); Assert.AreEqual("path-2\\test-path-2.js", script.Path); // fixed in 7.3 - 7.2.8 does not update the path Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = repository.Get("path-2/test-path-2.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2\\test-path-3.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.js")); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2/test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2\\test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = new Script("\\test-path-4.js") { Content = "// script" }; Assert.Throws <UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \ { repository.Save(script); }); script = repository.Get("missing.js"); Assert.IsNull(script); // fixed in 7.3 - 7.2.8 used to... Assert.Throws <UnauthorizedAccessException>(() => { script = repository.Get("\\test-path-4.js"); // outside the filesystem, does not exist }); Assert.Throws <UnauthorizedAccessException>(() => { script = repository.Get("../packages.config"); // outside the filesystem, exists }); } }
public void Can_Perform_Get_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var exists = repository.Get("test-script.js"); // Assert Assert.That(exists, Is.Not.Null); Assert.That(exists.Alias, Is.EqualTo("test-script")); Assert.That(exists.Name, Is.EqualTo("test-script.js")); }
public void PathTests() { // unless noted otherwise, no changes / 7.2.8 var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); var script = new Script("test-path-1.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("test-path-1.js")); Assert.AreEqual("test-path-1.js", script.Path); Assert.AreEqual("/scripts/test-path-1.js", script.VirtualPath); //ensure you can prefix the same path as the root path name script = new Script("scripts/path-2/test-path-2.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("scripts/path-2/test-path-2.js")); Assert.AreEqual("scripts\\path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2/test-path-2.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.js")); Assert.AreEqual("path-2\\test-path-2.js", script.Path); // fixed in 7.3 - 7.2.8 does not update the path Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = repository.Get("path-2/test-path-2.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2\\test-path-3.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.js")); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2/test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2\\test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = new Script("\\test-path-4.js") { Content = "// script" }; Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \ { repository.AddOrUpdate(script); }); script = repository.Get("missing.js"); Assert.IsNull(script); // fixed in 7.3 - 7.2.8 used to... Assert.Throws<FileSecurityException>(() => { script = repository.Get("\\test-path-4.js"); // outside the filesystem, does not exist }); Assert.Throws<FileSecurityException>(() => { script = repository.Get("../packages.config"); // outside the filesystem, exists }); }