public void Can_Perform_Update_With_Property() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of <IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new StylesheetRepository(unitOfWork, _fileSystem); // Act var stylesheet = new Stylesheet("test-update.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;")); repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); //re-get stylesheet = repository.Get(stylesheet.Name); //Assert Assert.That(stylesheet.Content, Is.EqualTo(@"body { color:#000; } .bold {font-weight:bold;} /**umb_name:Test*/ p{font-size:2em;}")); Assert.AreEqual(1, stylesheet.Properties.Count()); }
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 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 Throws_When_Adding_Duplicate_Properties() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of <IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new StylesheetRepository(unitOfWork, _fileSystem); // Act var stylesheet = new Stylesheet("test-update.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;")); Assert.Throws <DuplicateNameException>(() => stylesheet.AddProperty(new StylesheetProperty("test", "p", "font-size:2em;"))); }
public void Can_Add_Property() { // Arrange var stylesheet = new Stylesheet("/css/styles.css") { Content = @"body { color:#000; } .bold {font-weight:bold;}" }; stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-weight:bold; font-family:Arial;")); // Assert Assert.AreEqual(1, stylesheet.Properties.Count()); Assert.AreEqual("Test", stylesheet.Properties.Single().Name); Assert.AreEqual("p", stylesheet.Properties.Single().Alias); Assert.AreEqual("font-weight:bold;\r\nfont-family:Arial;", stylesheet.Properties.Single().Value); }
public void Can_Add_Property() { // Arrange Stylesheet stylesheet = _builder .WithPath("/css/styles.css") .WithContent(@"body { color:#000; } .bold {font-weight:bold;}") .Build(); // Act stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-weight:bold; font-family:Arial;")); // Assert Assert.AreEqual(1, stylesheet.Properties.Count()); Assert.AreEqual("Test", stylesheet.Properties.Single().Name); Assert.AreEqual("p", stylesheet.Properties.Single().Alias); Assert.AreEqual("font-weight:bold;" + Environment.NewLine + "font-family:Arial;", stylesheet.Properties.Single().Value); }
public override void Up() { //Don't exeucte if the stylesheet table is not there var tables = SqlSyntax.GetTablesInSchema(Context.Database).ToArray(); if (tables.InvariantContains("cmsStylesheet") == false) { return; } //This is all rather nasty but it's how stylesheets used to work in the 2 various ugly ways so we just have to // deal with that to get this migration done var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/CssMigration/"); if (Directory.Exists(tempFolder)) { //clear any existing css files (we back the real ones up so if this migration is run again for whatever reason anything that // was previously backed up is still there, backup happens in a post migration: OverwriteStylesheetFilesFromTempFiles class) var files = Directory.GetFiles(tempFolder, "*.css", SearchOption.AllDirectories); foreach (var file in files) { File.Delete(file); } } //create the temp folder var tempDir = Directory.CreateDirectory(IOHelper.MapPath("~/App_Data/TEMP/CssMigration/")); var sheets = Context.Database.Fetch <dynamic>("SELECT * FROM cmsStylesheet INNER JOIN umbracoNode on cmsStylesheet.nodeId = umbracoNode.id"); foreach (var sheet in sheets) { var fileName = sheet.text; string dbContent; //we will always use the file content over the db content if there is any using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(sheet.content))) { dbContent = GetContentAboveUmbracoProps(memStream); } var fileContent = string.Empty; //check for file and read in it's data - umbraco properties will only be kept that are in the db, // anything below the infamous: /* EDITOR PROPERTIES - PLEASE DON'T DELETE THIS LINE TO AVOID DUPLICATE PROPERTIES */ // line is an Umbraco property and therefore anything that is there that is not in the db will be cleared. var filePath = IOHelper.MapPath(string.Format("{0}/{1}.css", SystemDirectories.Css, fileName)); if (File.Exists(filePath)) { using (var stream = File.OpenRead(filePath)) { fileContent = GetContentAboveUmbracoProps(stream); } } var props = Context.Database.Fetch <dynamic>("SELECT * FROM cmsStylesheetProperty INNER JOIN umbracoNode ON cmsStylesheetProperty.nodeId = umbracoNode.id WHere umbracoNode.parentID = @id", new { id = sheet.nodeId }); var cssFolderPath = IOHelper.MapPath(SystemDirectories.Css); var relativeFsPath = StringExtensions.TrimStart(StringExtensions.TrimStart(filePath, cssFolderPath), "\\"); var stylesheetInstance = new Stylesheet(relativeFsPath) { Content = fileContent.IsNullOrWhiteSpace() ? dbContent : fileContent }; foreach (var prop in props) { if (stylesheetInstance.Properties.Any(x => x.Name == prop.text) == false) { stylesheetInstance.AddProperty(new StylesheetProperty(prop.text, prop.stylesheetPropertyAlias, prop.stylesheetPropertyValue)); } } //Save to temp folder //ensure the folder for the file exists since it could be in a sub folder var tempFilePath = Path.Combine(tempDir.FullName, relativeFsPath); Directory.CreateDirectory(Path.GetDirectoryName(tempFilePath)); File.WriteAllText(tempFilePath, stylesheetInstance.Content, Encoding.UTF8); } }