public void Can_Perform_Delete()
        {
            // Arrange
            var provider   = new FileUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            var repository = new StylesheetRepository(unitOfWork, _fileSystem);

            // Act
            var stylesheet = new Stylesheet("test-delete.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };

            repository.AddOrUpdate(stylesheet);
            unitOfWork.Commit();

            repository.Delete(stylesheet);
            unitOfWork.Commit();

            //Assert
            Assert.That(_fileSystem.FileExists("test-delete.css"), Is.False);
        }
        public void Can_Perform_GetAll_With_Params_On_ScriptRepository()
        {
            // 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-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
            repository.AddOrUpdate(script);
            var script2 = new Script("test-script2.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
            repository.AddOrUpdate(script2);
            var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
            repository.AddOrUpdate(script3);
            unitOfWork.Commit();

            // Act
            var scripts = repository.GetAll("test-script1.js", "test-script2.js");

            // Assert
            Assert.That(scripts, Is.Not.Null);
            Assert.That(scripts.Any(), Is.True);
            Assert.That(scripts.Any(x => x == null), Is.False);
            Assert.That(scripts.Count(), Is.EqualTo(2));
        }
예제 #3
0
        public void Can_Perform_Add_On_MacroRepository()
        {
            // Arrange
            var provider   = new FileUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);

            // Act
            var macro = new Macro {
                Alias = "testMacro", CacheByPage = false, CacheByMember = false, DontRender = true, Name = "Test Macro", Xslt = "/xslt/testMacro.xslt", UseInEditor = false
            };

            macro.Properties = new List <IMacroProperty>();
            macro.Properties.Add(new MacroProperty {
                Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number()
            });

            repository.AddOrUpdate(macro);
            unitOfWork.Commit();

            // Assert
            Assert.That(macro.CreateDate, Is.GreaterThan(DateTime.MinValue));
            Assert.That(macro.UpdateDate, Is.GreaterThan(DateTime.MinValue));
        }
예제 #4
0
        public void Can_Perform_GetAll_With_Params_On_StylesheetRepository()
        {
            // Arrange
            var provider   = new FileUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = new StylesheetRepository(unitOfWork, _fileSystem);

            var stylesheet = new Stylesheet("styles-v2.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };

            repository.AddOrUpdate(stylesheet);
            unitOfWork.Commit();

            // Act
            var stylesheets = repository.GetAll("styles-v2.css", "styles.css");

            // Assert
            Assert.That(stylesheets, Is.Not.Null);
            Assert.That(stylesheets.Any(), Is.True);
            Assert.That(stylesheets.Any(x => x == null), Is.False);
            Assert.That(stylesheets.Count(), Is.EqualTo(2));
        }
        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 StylesheetRepository(unitOfWork, _fileSystem);

            var stylesheet = new Stylesheet("test-path-1.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };

            repository.AddOrUpdate(stylesheet);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("test-path-1.css"));
            Assert.AreEqual("test-path-1.css", stylesheet.Path);
            Assert.AreEqual("/css/test-path-1.css", stylesheet.VirtualPath);

            stylesheet = new Stylesheet("path-2/test-path-2.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };
            repository.AddOrUpdate(stylesheet);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.css"));
            Assert.AreEqual("path-2\\test-path-2.css", stylesheet.Path); // fixed in 7.3 - 7.2.8 does not update the path
            Assert.AreEqual("/css/path-2/test-path-2.css", stylesheet.VirtualPath);

            stylesheet = repository.Get("path-2/test-path-2.css");
            Assert.IsNotNull(stylesheet);
            Assert.AreEqual("path-2\\test-path-2.css", stylesheet.Path);
            Assert.AreEqual("/css/path-2/test-path-2.css", stylesheet.VirtualPath);

            stylesheet = new Stylesheet("path-2\\test-path-3.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };
            repository.AddOrUpdate(stylesheet);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.css"));
            Assert.AreEqual("path-2\\test-path-3.css", stylesheet.Path);
            Assert.AreEqual("/css/path-2/test-path-3.css", stylesheet.VirtualPath);

            stylesheet = repository.Get("path-2/test-path-3.css");
            Assert.IsNotNull(stylesheet);
            Assert.AreEqual("path-2\\test-path-3.css", stylesheet.Path);
            Assert.AreEqual("/css/path-2/test-path-3.css", stylesheet.VirtualPath);

            stylesheet = repository.Get("path-2\\test-path-3.css");
            Assert.IsNotNull(stylesheet);
            Assert.AreEqual("path-2\\test-path-3.css", stylesheet.Path);
            Assert.AreEqual("/css/path-2/test-path-3.css", stylesheet.VirtualPath);

            stylesheet = new Stylesheet("\\test-path-4.css")
            {
                Content = "body { color:#000; } .bold {font-weight:bold;}"
            };
            Assert.Throws <FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
            {
                repository.AddOrUpdate(stylesheet);
            });

            // fixed in 7.3 - 7.2.8 used to throw
            stylesheet = repository.Get("missing.css");
            Assert.IsNull(stylesheet);

            // fixed in 7.3 - 7.2.8 used to...
            Assert.Throws <FileSecurityException>(() =>
            {
                stylesheet = repository.Get("\\test-path-4.css"); // outside the filesystem, does not exist
            });
            Assert.Throws <FileSecurityException>(() =>
            {
                stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
            });
        }
        public void PathTests()
        {
            // unless noted otherwise, no changes / 7.2.8

            var provider   = new FileUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = new PartialViewRepository(unitOfWork, _fileSystem);

            var partialView = new PartialView("test-path-1.cshtml")
            {
                Content = "// partialView"
            };

            repository.AddOrUpdate(partialView);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("test-path-1.cshtml"));
            Assert.AreEqual("test-path-1.cshtml", partialView.Path);
            Assert.AreEqual("/Views/Partials/test-path-1.cshtml", partialView.VirtualPath);

            partialView = new PartialView("path-2/test-path-2.cshtml")
            {
                Content = "// partialView"
            };
            repository.AddOrUpdate(partialView);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.cshtml"));
            Assert.AreEqual("path-2\\test-path-2.cshtml", partialView.Path); // fixed in 7.3 - 7.2.8 does not update the path
            Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);

            partialView = (PartialView)repository.Get("path-2/test-path-2.cshtml");
            Assert.IsNotNull(partialView);
            Assert.AreEqual("path-2\\test-path-2.cshtml", partialView.Path);
            Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);

            partialView = new PartialView("path-2\\test-path-3.cshtml")
            {
                Content = "// partialView"
            };
            repository.AddOrUpdate(partialView);
            unitOfWork.Commit();
            Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.cshtml"));
            Assert.AreEqual("path-2\\test-path-3.cshtml", partialView.Path);
            Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

            partialView = (PartialView)repository.Get("path-2/test-path-3.cshtml");
            Assert.IsNotNull(partialView);
            Assert.AreEqual("path-2\\test-path-3.cshtml", partialView.Path);
            Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

            partialView = (PartialView)repository.Get("path-2\\test-path-3.cshtml");
            Assert.IsNotNull(partialView);
            Assert.AreEqual("path-2\\test-path-3.cshtml", partialView.Path);
            Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

            partialView = new PartialView("\\test-path-4.cshtml")
            {
                Content = "// partialView"
            };
            Assert.Throws <FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
            {
                repository.AddOrUpdate(partialView);
            });

            partialView = (PartialView)repository.Get("missing.cshtml");
            Assert.IsNull(partialView);

            // fixed in 7.3 - 7.2.8 used to...
            Assert.Throws <FileSecurityException>(() =>
            {
                partialView = (PartialView)repository.Get("\\test-path-4.cshtml");  // outside the filesystem, does not exist
            });
            Assert.Throws <FileSecurityException>(() =>
            {
                partialView = (PartialView)repository.Get("../../packages.config");  // outside the filesystem, exists
            });
        }
        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
            });
        }