public void ProcessShouldSetAreaControllerRendererIfDescendantOfAreaControllerTemplate() { // Arrange var builder = new Template.Builder("Area Controller Template", Constants.Templates.AreaController, new TemplateCollection()); var fieldList = new FieldList { {Constants.Fields.Controller.Action, "Index"}, {Constants.Fields.Controller.Name, "HelloWorld"}, {Constants.Fields.Controller.Area, "MyArea"}, {Constants.Fields.Controller.UseChildActionBehavior, "1"} }; var innerItem = new TestItem(fieldList); var rendering = new Rendering { RenderingItem = new RenderingItem(innerItem)}; _args.Rendering = rendering; _args.RenderingTemplate = builder.Template; _controller.ControllerRunner = new Mock<IControllerRunner>().Object; // Act _controller.Process(_args); // Assert Assert.That(_args.Result, Is.InstanceOf<AreaControllerRenderer>(), "Rendering should be an AreaControllerRenderer"); }
public void IsDerived_ItemIsOfGivenTemplate_ReturnsTrue() { // setup #region Setup var baseTemplateId = ID.NewID; var itemId = ID.NewID; var item = Substitute.For <Item>( itemId, new ItemData( new ItemDefinition(itemId, "Item Of Template", baseTemplateId, ID.NewID), this.Language, Version.Parse(1), new FieldList() ), this.Database); var template = new Template.Builder("Base Template", baseTemplateId, new TemplateCollection()).Template; this.TemplateManager.GetTemplate(baseTemplateId, this.Database).Returns(template); this.TemplateManager.GetTemplate(item).Returns(template); #endregion // act var isDerived = this.ItemExtensions.IsDerived(item, baseTemplateId); // assert isDerived.Should().BeTrue(); }
public void ProcessShouldSetAreaControllerRendererIfDescendantOfAreaControllerTemplate() { // Arrange var builder = new Template.Builder("Area Controller Template", Constants.Templates.AreaController, new TemplateCollection()); var fieldList = new FieldList { { Constants.Fields.Controller.Action, "Index" }, { Constants.Fields.Controller.Name, "HelloWorld" }, { Constants.Fields.Controller.Area, "MyArea" }, { Constants.Fields.Controller.UseChildActionBehavior, "1" } }; var innerItem = new TestItem(fieldList); var rendering = new Rendering { RenderingItem = new RenderingItem(innerItem) }; _args.Rendering = rendering; _args.RenderingTemplate = builder.Template; _controller.ControllerRunner = new Mock <IControllerRunner>().Object; // Act _controller.Process(_args); // Assert Assert.That(_args.Result, Is.InstanceOf <AreaControllerRenderer>(), "Rendering should be an AreaControllerRenderer"); }
public TemplateSection.Builder Build(Template.Builder builder) { var sectionBuilder = builder.AddSection(SectionName, Id); sectionBuilder.SetSortorder(SortOrder); return(sectionBuilder); }
public override TemplateCollection GetTemplates(CallContext context) { var owner = new TemplateCollection(); var database = GetDatabase(context); var templatesRoot = database.GetItems(ItemIDs.TemplateRoot.ToString()); var templates = new List <Template>(templatesRoot.Count()); foreach (var syncItem in templatesRoot) { if (ID.IsNullOrEmpty(ID.Parse(syncItem.ID)) || syncItem.ID.Equals(TemplateIDs.TemplateFolder.ToString())) { continue; } var templateBuilder = new Template.Builder(syncItem.Name, ID.Parse(syncItem.ID), owner); templateBuilder.SetFullName(syncItem.ItemPath); var dataSection = templateBuilder.AddSection("Data", ID.NewID); foreach (var syncField in syncItem.SharedFields) { if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName)) { continue; } if (syncField.FieldID.Equals(FieldIDs.BaseTemplate.ToString())) { templateBuilder.SetBaseIDs(syncField.FieldValue); } else { dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID)); } } var version = syncItem.GetLatestVersions().FirstOrDefault(); foreach (var syncField in version.Fields) { if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName)) { continue; } dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID)); } templates.Add(templateBuilder.Template); } owner.Reset(templates.ToArray()); return(owner); }
public Template.Builder BuildTemplate(TemplateCollection owner) { var builder = new Template.Builder(TemplateName, Id, owner); builder.SetFullName(TemplateName); builder.SetBaseIDs(BaseIdsValue); return(builder); }
public void ProcessShouldDoNothingIfRenderingTemplateIsNotDescendantOfAreaControllerTemplate() { // Arrange var builder = new Template.Builder("Dummy Template", new ID(Guid.NewGuid()), new TemplateCollection()); _args.RenderingTemplate = builder.Template; // Act _controller.Process(_args); // Assert Assert.That(_args.Result, Is.Null, "Rendering should not be assigned"); }
public void ProcessShouldDoNothingIfRenderingTemplateIsNotDescendantOfAreaControllerTemplate() { // Arrange var builder = new Template.Builder("Dummy Template", new ID(Guid.NewGuid()), new TemplateCollection()); _args.RenderingTemplate = builder.Template; // Act _controller.Process(_args); // Assert Assert.That(_args.Result, Is.Null, "Rendering should not be assigned"); }
public static Template CreateTemplate(ID templateId, ID baseTemplateId, TemplateCollection templateCollection) { var builder = new Template.Builder($"test-{templateId}", templateId, templateCollection); if (baseTemplateId != (ID)null) { builder.SetBaseIDs(baseTemplateId.ToString()); } var template = builder.Template; templateCollection.Add(template); return(template); }
public static BaseTemplateManager CreateTemplateManager(params ID[] templateIds) { var templates = new List <Template>(); var templateCollection = new TemplateCollection(); foreach (var id in templateIds) { var builder = new Template.Builder($"test-{id}", id, templateCollection); var template = builder.Template; templates.Add(template); } return(CreateTemplateManager(templates.ToArray())); }
public FakeTemplate(string templateName = null, ID templateId = null, Database database = null, TemplateEngine engine = null) { string name = string.IsNullOrEmpty(templateName) ? "fakeTemplate" : templateName; ID id = templateId ?? ID.NewID; Database db = database ?? FakeUtil.FakeDatabase(); this.Database = db; templateEngine = engine ?? Substitute.For <TemplateEngine>(db); templateBuilder = new Template.Builder(name, id, templateEngine); templateBuilder.SetName(name); templateBuilder.SetID(id); templateEngine.GetTemplate(id).Returns(this); templateEngine.GetTemplate(name).Returns(this); }
protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates) { var builder = new Template.Builder(ft.Name, ft.ID, templates); var section = builder.AddSection("Data", ID.NewID); foreach (var field in ft.Fields) { var newField = section.AddField(field.Name, field.ID); newField.SetShared(field.Shared); newField.SetType(field.Type); } builder.SetBaseIDs(string.Join("|", ft.BaseIDs ?? new ID[] { } as IEnumerable <ID>)); return(builder.Template); }
public void AddTemplate(Item item, IEnumerable<Item> baseTeamplates) { Template.Builder builder = new Template.Builder(item.Name, item.ID, new TemplateCollection()); StringBuilder strnBuilder = new StringBuilder(); foreach (Item baseTemplate in baseTeamplates) { strnBuilder.Append(string.Format("{0}|", baseTemplate.ID)); } if (baseTeamplates.Any()) { string idsString = strnBuilder.ToString().TrimEnd('|'); builder.SetBaseIDs(idsString); } _templateCollection.Add(builder.Template); _idCollection.Add(item.ID); }
public void AddTemplate(Item item, IEnumerable <Item> baseTeamplates) { Template.Builder builder = new Template.Builder(item.Name, item.ID, new TemplateCollection()); StringBuilder strnBuilder = new StringBuilder(); foreach (Item baseTemplate in baseTeamplates) { strnBuilder.Append(string.Format("{0}|", baseTemplate.ID)); } if (baseTeamplates.Any()) { string idsString = strnBuilder.ToString().TrimEnd('|'); builder.SetBaseIDs(idsString); } _templateCollection.Add(builder.Template); _idCollection.Add(item.ID); }
public override TemplateCollection GetTemplates(CallContext context) { var templates = new TemplateCollection(); foreach (var ft in this.DataStorage.FakeTemplates.Values) { var builder = new Template.Builder(ft.Name, ft.ID, new TemplateCollection()); var section = builder.AddSection("Data", ID.NewID); foreach (var field in ft.Fields) { section.AddField(field.Name, field.ID); } templates.Add(builder.Template); } return templates; }
protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates) { var builder = new Template.Builder(ft.Name, ft.ID, templates); var section = builder.AddSection("Data", ID.NewID); foreach (var field in ft.Fields) { if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard()) { continue; } var newField = section.AddField(field.Name, field.ID); newField.SetShared(field.Shared); newField.SetType(field.Type); } builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable <ID>) : TemplateIDs.StandardTemplate.ToString()); return(builder.Template); }
public void IsDerived_ItemInheritsBaseTemplate_ReturnsTrue() { // setup #region Setup var itemTemplateId = ID.NewID; var baseTemplateId = ID.NewID; var itemId = ID.NewID; var item = Substitute.For <Item>( itemId, new ItemData( new ItemDefinition(itemId, "Item Of Base Template", itemTemplateId, ID.Null), this.Language, Version.Parse(1), new FieldList() ), this.Database); var baseTemplate = new Template.Builder("Base Template", baseTemplateId, this.TemplateEngine).Template; var itemTemplateItem = new Template.Builder("Item Template", itemTemplateId, this.TemplateEngine); itemTemplateItem.SetBaseIDs(baseTemplateId.ToString()); var itemTemplate = itemTemplateItem.Template; this.TemplateEngine.GetTemplate(itemTemplateId).Returns(itemTemplate); this.TemplateEngine.GetTemplate(baseTemplateId).Returns(baseTemplate); this.TemplateManager.GetTemplate(itemTemplateId, this.Database).Returns(itemTemplate); this.TemplateManager.GetTemplate(baseTemplateId, this.Database).Returns(baseTemplate); this.TemplateManager.GetTemplate(item).Returns(itemTemplate); #endregion // act var isDerived = this.ItemExtensions.IsDerived(item, baseTemplateId); // assert isDerived.Should().BeTrue(); }
private (ResolveItems sut, Mock <Item> dataItem, Mock <IEntryManager>) CreateResolveItems(ID dataItemTemplateId, ID entryTemplateId, ID commentTemplateId) { var settings = Mock.Of <IWeBlogSettings>(x => x.EntryTemplateIds == new[] { entryTemplateId } && x.CommentTemplateIds == new[] { commentTemplateId } ); var dataItemMock = ItemFactory.CreateItem(templateId: dataItemTemplateId); var entryTemplateBuilder = new Template.Builder("entry", entryTemplateId, new TemplateCollection()); var commentTemplateBuilder = new Template.Builder("comment", commentTemplateId, new TemplateCollection()); var templateManager = Mock.Of <BaseTemplateManager>(x => x.GetTemplate(settings.EntryTemplateIds.First(), dataItemMock.Object.Database) == entryTemplateBuilder.Template && x.GetTemplate(settings.CommentTemplateIds.First(), dataItemMock.Object.Database) == commentTemplateBuilder.Template ); var entryManager = new Mock <IEntryManager>(); var sut = new ResolveItems(settings, templateManager, entryManager.Object); return(sut, dataItemMock, entryManager); }
protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates) { var builder = new Template.Builder(ft.Name, ft.ID, templates); var sectionName = "Data"; var sectionId = ID.NewID; var sectionItem = ft.Children.FirstOrDefault(i => i.TemplateID == TemplateIDs.TemplateSection); if (sectionItem != null) { sectionName = sectionItem.Name; sectionId = sectionItem.ID; } var section = builder.AddSection(sectionName, sectionId); foreach (var field in ft.Fields) { if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard()) { continue; } var newField = section.AddField(field.Name, field.ID); newField.SetShared(field.Shared); newField.SetType(field.Type); newField.SetSource(field.Source); } if (ft.ID != TemplateIDs.StandardTemplate) { builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable <ID>) : TemplateIDs.StandardTemplate.ToString()); } return(builder.Template); }
public FakeItem WithTemplate(ID templateId) { Item.Template.ID.Returns(templateId); Item.TemplateID.Returns(templateId); var runtimeSettings = Substitute.For <ItemRuntimeSettings>(Item); runtimeSettings.TemplateDatabase.Returns(Item.Database); Item.RuntimeSettings.Returns(runtimeSettings); var engines = Substitute.For <DatabaseEngines>(Item.Database); var templateEngine = Substitute.For <TemplateEngine>(Item.Database); var template = new Template.Builder(templateId.ToString(), templateId, new TemplateCollection()); templateEngine.GetTemplate(templateId).Returns(template.Template); engines.TemplateEngine.Returns(templateEngine); Item.Database.Engines.Returns(engines); Item.Database.GetTemplate(templateId).Returns(d => Item.Template); return(this); }
public override TemplateCollection GetTemplates(CallContext context) { var owner = new TemplateCollection(); var database = GetDatabase(context); var templatesRoot = database.GetItems(ItemIDs.TemplateRoot.ToString()); var templates = new List<Template>(templatesRoot.Count()); foreach (var syncItem in templatesRoot) { if (ID.IsNullOrEmpty(ID.Parse(syncItem.ID)) || syncItem.ID.Equals(TemplateIDs.TemplateFolder.ToString())) { continue; } var templateBuilder = new Template.Builder(syncItem.Name, ID.Parse(syncItem.ID), owner); templateBuilder.SetFullName(syncItem.ItemPath); var dataSection = templateBuilder.AddSection("Data", ID.NewID); foreach (var syncField in syncItem.SharedFields) { if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName)) { continue; } if (syncField.FieldID.Equals(FieldIDs.BaseTemplate.ToString())) { templateBuilder.SetBaseIDs(syncField.FieldValue); } else { dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID)); } } var version = syncItem.GetLatestVersions().FirstOrDefault(); foreach (var syncField in version.Fields) { if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName)) { continue; } dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID)); } templates.Add(templateBuilder.Template); } owner.Reset(templates.ToArray()); return owner; }
protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates) { var builder = new Template.Builder(ft.Name, ft.ID, templates); var section = builder.AddSection("Data", ID.NewID); foreach (var field in ft.Fields) { if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard()) { continue; } var newField = section.AddField(field.Name, field.ID); newField.SetShared(field.Shared); newField.SetType(field.Type); } builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable<ID>) : TemplateIDs.StandardTemplate.ToString()); return builder.Template; }
protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates) { var builder = new Template.Builder(ft.Name, ft.ID, templates); var sectionName = "Data"; var sectionId = ID.NewID; var sectionItem = ft.Children.FirstOrDefault(i => i.TemplateID == TemplateIDs.TemplateSection); if (sectionItem != null) { sectionName = sectionItem.Name; sectionId = sectionItem.ID; } var section = builder.AddSection(sectionName, sectionId); foreach (var field in ft.Fields) { if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard()) { continue; } var newField = section.AddField(field.Name, field.ID); newField.SetShared(field.Shared); newField.SetType(field.Type); newField.SetSource(field.Source); } if (ft.ID != TemplateIDs.StandardTemplate) { builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable<ID>) : TemplateIDs.StandardTemplate.ToString()); } return builder.Template; }