public void Can_Perform_Update_With_Property()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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


                stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;"));

                repository.Save(stylesheet);


                //re-get
                stylesheet = repository.Get(stylesheet.Name);

                //Assert
                Assert.That(stylesheet.Content, Is.EqualTo("body { color:#000; } .bold {font-weight:bold;}\r\n\r\n/**umb_name:Test*/\r\np {\r\n\tfont-size:2em;\r\n}"));
                Assert.AreEqual(1, stylesheet.Properties.Count());
            }
        }
        public void Can_Perform_Update()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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


                var stylesheetUpdate = repository.Get("test-update.css");
                stylesheetUpdate.Content = "body { color:#000; }";
                repository.Save(stylesheetUpdate);


                var stylesheetUpdated = repository.Get("test-update.css");

                //Assert
                Assert.That(stylesheetUpdated, Is.Not.Null);
                Assert.That(stylesheetUpdated.HasIdentity, Is.True);
                Assert.That(stylesheetUpdated.Content, Is.EqualTo("body { color:#000; }"));
            }
        }
        public void Can_Perform_Add()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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


                //Assert
                Assert.That(_fileSystem.FileExists("test-add.css"), Is.True);
            }
        }
        public void Throws_When_Adding_Duplicate_Properties()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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


                stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;"));

                Assert.Throws<DuplicateNameException>(() => stylesheet.AddProperty(new StylesheetProperty("test", "p", "font-size:2em;")));
            }
        }
        public void Can_Perform_GetAll_With_Params()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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


                // Act
                var stylesheets = repository.GetMany("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

            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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

                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.Save(stylesheet);

                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.Save(stylesheet);

                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.Save(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
                });
            }
        }
Пример #7
0
        public void PathTests()
        {
            // unless noted otherwise, no changes / 7.2.8

            using (ScopeProvider.CreateScope())
            {
                var repository = new StylesheetRepository(_fileSystems);

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

                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.Save(stylesheet);

                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.Save(stylesheet);

                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 <UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
                {
                    repository.Save(stylesheet);
                });

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

                // #7713 changes behaviour to return null when outside the filesystem
                // to accomodate changing the CSS path and not flooding the backoffice with errors
                stylesheet = repository.Get("\\test-path-4.css"); // outside the filesystem, does not exist
                Assert.IsNull(stylesheet);

                stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
                Assert.IsNull(stylesheet);
            }
        }