Esempio n. 1
0
        protected override IMacro PerformGet(string id)
        {
            var    name  = string.Concat(id, ".macro");
            Stream file  = _fileSystem.OpenFile(name);
            var    o     = _serializationService.FromStream(file, typeof(Macro));
            var    macro = o as IMacro;

            if (macro != null)
            {
                ((ICanBeDirty)macro).ResetDirtyProperties();
            }

            return(macro);
        }
Esempio n. 2
0
        public void Can_Create_And_Serialize_Then_Deserialize_Macro()
        {
            // Arrange
            var serviceStackSerializer = new ServiceStackJsonSerializer();
            var serializationService   = new SerializationService(serviceStackSerializer);

            var macro = new Macro
            {
                Alias         = "test",
                CacheByPage   = false,
                CacheByMember = false,
                DontRender    = true,
                Name          = "Test",
                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()
            });
            macro.Properties.Add(new MacroProperty {
                Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text()
            });

            // Act
            var    json       = serializationService.ToStream(macro);
            string jsonString = json.ResultStream.ToJsonString();

            var deserialized = serializationService.FromJson <Macro>(jsonString);

            var    stream        = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
            object o             = serializationService.FromStream(stream, typeof(Macro));
            var    deserialized2 = o as IMacro;

            // Assert
            Assert.That(json.Success, Is.True);
            Assert.That(jsonString, Is.Not.Empty);
            Assert.That(deserialized, Is.Not.Null);
            Assert.That(deserialized2, Is.Not.Null);
            Assert.That(deserialized.Name, Is.EqualTo(macro.Name));
            Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias));
            Assert.That(deserialized2.Name, Is.EqualTo(macro.Name));
            Assert.That(deserialized2.Alias, Is.EqualTo(macro.Alias));
        }
Esempio n. 3
0
        public void Can_Read_And_Deserialize_Macro_From_Disc()
        {
            // Arrange
            var serviceStackSerializer = new ServiceStackJsonSerializer();
            var serializationService   = new SerializationService(serviceStackSerializer);
            var fileSystem             = new PhysicalFileSystem("~/App_Data/Macros");

            var macro = new Macro
            {
                Alias         = "test",
                CacheByPage   = false,
                CacheByMember = false,
                DontRender    = true,
                Name          = "Test",
                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()
            });
            macro.Properties.Add(new MacroProperty {
                Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text()
            });

            // Act
            var    json       = serializationService.ToStream(macro);
            string jsonString = json.ResultStream.ToJsonString();

            fileSystem.AddFile("test-serialized-Macro.macro", json.ResultStream, true);

            Stream stream       = fileSystem.OpenFile("test-serialized-Macro.macro");
            object o            = serializationService.FromStream(stream, typeof(Macro));
            var    deserialized = o as IMacro;

            // Assert
            Assert.That(json.Success, Is.True);
            Assert.That(jsonString, Is.Not.Empty);
            Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True);
            Assert.That(deserialized, Is.Not.Null);
            Assert.That(deserialized.Name, Is.EqualTo(macro.Name));
            Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias));
        }