示例#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);
        }
        public void Cannot_Add_Duplicate_Macros()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current))
            {
                var macro = new Macro("test1", "Test", "~/usercontrol/blah.ascx", "MyAssembly", "test.xslt", "~/views/macropartials/test.cshtml");
                repository.AddOrUpdate(macro);

                Assert.Throws<SqlCeException>(unitOfWork.Commit);
            }

        }
        public void Can_Create()
        {
            // Arrange
            var macroService = ServiceContext.MacroService;

            // Act
            var macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
            macroService.Save(macro);

            //assert
            Assert.IsTrue(macro.HasIdentity);
            Assert.Greater(macro.Id, 0);
            var result = macroService.GetById(macro.Id);
            Assert.AreEqual("test", result.Alias);
            Assert.AreEqual("Test", result.Name);
            Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.ScriptPath);
            Assert.AreEqual(1234, result.CacheDuration);
        }
示例#4
0
        /// <summary>
        /// Creates a new macro given the name
        /// </summary>
        /// <param name="Name">Userfriendly name</param>
        /// <returns>The newly macro</returns>
        public static Macro MakeNew(string Name)
        {
            var macro = new Umbraco.Core.Models.Macro
            {
                Name  = Name,
                Alias = Name.Replace(" ", String.Empty)
            };

            ApplicationContext.Current.Services.MacroService.Save(macro);

            var newMacro = new Macro(macro);

            //fire new event
            var e = new NewEventArgs();

            newMacro.OnNew(e);

            return(newMacro);
        }
        public void Can_Perform_Add_On_MacroRepository()
        {
            // Arrange
            var provider = new FileUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);

            // Act
            var macro = new Macro { Alias = "testMacro", CacheByPage = false, CacheByMember = false, DontRender = true, Name = "Test Macro", 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() });

            repository.AddOrUpdate(macro);
            unitOfWork.Commit();

            // Assert
            Assert.That(macro.CreateDate, Is.GreaterThan(DateTime.MinValue));
            Assert.That(macro.UpdateDate, Is.GreaterThan(DateTime.MinValue));
        }
示例#6
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));
        }
示例#7
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);
        }
        private IMacro CreateMacro(string alias, string name)
        {
            var macro = new Macro
            {
                Alias = alias,
                CacheByPage = false,
                CacheByMember = false,
                DontRender = true,
                Name = name,
                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() });

            return macro;
        }
示例#9
0
		public static Macro MakeNew(string Name) 
		{
		    var macro = new Umbraco.Core.Models.Macro
		        {
                    Name = Name,
                    Alias = Name.Replace(" ", String.Empty)
		        };

		    ApplicationContext.Current.Services.MacroService.Save(macro);

            var newMacro = new Macro(macro);
           
            //fire new event
            var e = new NewEventArgs();
            newMacro.OnNew(e);
            
            return newMacro;
		}
        public void Can_Delete()
        {
            // Arrange
            var macroService = ServiceContext.MacroService;
            var macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
            macroService.Save(macro);

            // Act
            macroService.Delete(macro);

            //assert
            var result = macroService.GetById(macro.Id);
            Assert.IsNull(result);
        }
        public void Can_Update_Property()
        {
            // Arrange
            var macroService = ServiceContext.MacroService;
            IMacro macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
            macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah"));
            macroService.Save(macro);

            // Act
            macro.Properties.First().Alias = "new Alias";
            macro.Properties.First().Name = "new Name";
            macro.Properties.First().SortOrder = 1;
            macro.Properties.First().EditorAlias = "new";
            macroService.Save(macro);

            macro = macroService.GetById(macro.Id);

            //assert
            Assert.AreEqual(1, macro.Properties.Count());
            Assert.AreEqual("new Alias", macro.Properties.First().Alias);
            Assert.AreEqual("new Name", macro.Properties.First().Name);
            Assert.AreEqual(1, macro.Properties.First().SortOrder);
            Assert.AreEqual("new", macro.Properties.First().EditorAlias);

        }
        public void Can_Update()
        {
            // Arrange
            var macroService = ServiceContext.MacroService;
            IMacro macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
            macroService.Save(macro);

            // Act
            macro.Name = "New name";
            macro.Alias = "NewAlias";
            macroService.Save(macro);


            macro = macroService.GetById(macro.Id);

            //assert
            Assert.AreEqual("New name", macro.Name);
            Assert.AreEqual("NewAlias", macro.Alias);

        }
        public void Can_Add_Remove_Macro_Properties()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current))
            {
                var macro = new Macro("newmacro", "A new macro", "~/usercontrol/test1.ascx", "MyAssembly1", "test1.xslt", "~/views/macropartials/test1.cshtml");
                var prop1 = new MacroProperty("blah1", "New1", 4, "test.editor");
                var prop2 = new MacroProperty("blah2", "New2", 3, "test.editor");

                //add/remove a few to test the collection observable
                macro.Properties.Add(prop1);
                macro.Properties.Add(prop2);
                macro.Properties.Remove(prop1);
                macro.Properties.Remove("blah2");
                macro.Properties.Add(prop2);
                
                repository.AddOrUpdate(macro);
                unitOfWork.Commit();

                // Assert
                var result = repository.Get(macro.Id);
                
                Assert.AreEqual(1, result.Properties.Count());
                Assert.AreEqual("blah2", result.Properties.Single().Alias);

            }
        }
        public void Can_Remove_Macro_Property()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current))
            {
                var macro = new Macro("newmacro", "A new macro", "~/usercontrol/test1.ascx", "MyAssembly1", "test1.xslt", "~/views/macropartials/test1.cshtml");
                macro.Properties.Add(new MacroProperty("blah1", "New1", 4, "test.editor"));
                repository.AddOrUpdate(macro);
                unitOfWork.Commit();

                var result = repository.Get(macro.Id);
                result.Properties.Remove("blah1");
                repository.AddOrUpdate(result);
                unitOfWork.Commit();

                // Assert
                result = repository.Get(macro.Id);
                Assert.AreEqual(0, result.Properties.Count());
                
            }
        }
        public void Can_Perform_Add_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current))
            {
                // Act
                var macro = new Macro("test", "Test", "~/usercontrol/blah.ascx", "MyAssembly", "test.xslt", "~/views/macropartials/test.cshtml");
                macro.Properties.Add(new MacroProperty("test", "Test", 0, "test"));
                repository.AddOrUpdate(macro);
                unitOfWork.Commit();

                // Assert
                Assert.That(macro.HasIdentity, Is.True);
                Assert.That(macro.Id, Is.EqualTo(4));//With 3 existing entries the Id should be 4   
                Assert.Greater(macro.Properties.Single().Id, 0);
            }
        }