internal File PerformSave(MacroEditorModel model) { Mandate.ParameterNotNull(model, "model"); using (var uow = Hive.Create()) { var fileName = model.Alias.ToUmbracoAlias() + ".macro"; var newFileId = new HiveId(fileName); var macroFile = new File { Name = fileName, ContentBytes = Encoding.UTF8.GetBytes(MacroSerializer.ToXml(model).ToString()) }; var existing = uow.Repositories.Get <File>(newFileId); //delete the file first before re-saving as AddOrUpdate seems to append to the file if (existing != null) { uow.Repositories.Delete <File>(newFileId); } uow.Repositories.AddOrUpdate(macroFile); //TODO: the Hive IO provider commit seems to do nothing :( ... needs to be implemented! uow.Complete(); return(macroFile); } }
public void MacroSerializer_ToXml() { var macro = new MacroEditorModel { Alias = "test", Name = "Test", Id = new HiveId("my-macro.macro"), CacheByPage = true, CachePeriodSeconds = 1234, CachePersonalized = false, MacroType = "ChildAction", RenderContentInEditor = true, SelectedItem = "RenderTwitterFeed", UseInEditor = false }; macro.MacroParameters.Add(new MacroParameterDefinitionModel { Alias = "test1", Name = "Test1", ParameterEditorId = Guid.NewGuid(), Show = true }); macro.MacroParameters.Add(new MacroParameterDefinitionModel { Alias = "test2", Name = "Test2", ParameterEditorId = Guid.NewGuid(), Show = false }); var xml = MacroSerializer.ToXml(macro); Assert.AreEqual(macro.Alias, xml.Root.Attribute("alias").Value); Assert.AreEqual(macro.Name, xml.Root.Attribute("name").Value); Assert.AreEqual(macro.CacheByPage, (bool)xml.Root.Attribute("cacheByPage")); Assert.AreEqual(macro.CachePeriodSeconds, (int)xml.Root.Attribute("cachePeriodSeconds")); Assert.AreEqual(macro.CachePersonalized, (bool)xml.Root.Attribute("cachePersonalized")); Assert.AreEqual(macro.MacroType.ToString(), xml.Root.Attribute("macroType").Value); Assert.AreEqual(macro.RenderContentInEditor, (bool)xml.Root.Attribute("renderContentInEditor")); Assert.AreEqual(macro.SelectedItem, xml.Root.Attribute("selectedItem").Value); Assert.AreEqual(macro.UseInEditor, (bool)xml.Root.Attribute("useInEditor")); //TODO: test parameter values Assert.AreEqual(2, xml.Root.Elements("parameter").Count()); }