Exemplo n.º 1
0
        public void Can_Create_And_Serialize_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();

            // Assert
            Assert.That(json, Is.Not.Null);
            Assert.That(json.Success, Is.True);
            Assert.That(jsonString, Is.Not.Empty);
            Assert.That(jsonString.StartsWith("{"), Is.True);
            Assert.That(jsonString.EndsWith("}"), Is.True);
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            UmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false);
           
            base.Initialize();

            var jsonNetSerializer = new JsonNetSerializer();
            SerializationService = new SerializationService(jsonNetSerializer);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public override void Initialize()
        {
            UmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false);

            //this ensures its reset
            PluginManager.Current = new PluginManager();

            //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
            PluginManager.Current.AssembliesToScan = new[]
				{
                    typeof(IDataType).Assembly,
                    typeof(tinyMCE3dataType).Assembly,
                    typeof (ContentTypeBase).Assembly
				};

            DataTypesResolver.Current = new DataTypesResolver(
                () => PluginManager.Current.ResolveDataTypes());

            base.Initialize();

            var serviceStackSerializer = new ServiceStackJsonSerializer();
            SerializationService = new SerializationService(serviceStackSerializer);
        }
Exemplo n.º 5
0
        public void Can_Write_Serialized_Macro_To_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);

            // Assert
            Assert.That(json.Success, Is.True);
            Assert.That(jsonString, Is.Not.Empty);
            Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True);
        }
Exemplo n.º 6
0
        public override void TearDown()
        {
			base.TearDown();

            //reset the app context
            DataTypesResolver.Reset();
            ApplicationContext.Current = null;
            Resolution.IsFrozen = false;
            PluginManager.Current = null;

            string path = TestHelper.CurrentAssemblyDirectory;
            AppDomain.CurrentDomain.SetData("DataDirectory", null);
            
            SerializationService = null;

            UmbracoSettings.ResetSetters();
        }
Exemplo n.º 7
0
        public override void TearDown()
        {
			base.TearDown();
            
            SerializationService = null;
        }