Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using EPiServer.DataAbstraction;
using EPiServer.Security;
using PageTypeBuilder;
using PageTypeBuilder.Specs.Helpers.TypeBuildingDsl;
using Machine.Specifications;

Expand All @@ -17,10 +18,10 @@ public class when_a_page_type_property_is_annotated_with_property_group : Synchr
Establish context = () =>
{
var propertyGroupAttribute = new PageTypePropertyGroupAttribute
{
EditCaptionPrefix = "Property One - ",
StartSortOrderFrom = 100
};
{
EditCaptionPrefix = "Property One - ",
StartSortOrderFrom = 100
};

SyncContext.CreateAndAddPageTypeClassToAppDomain(type =>
{
Expand Down Expand Up @@ -72,9 +73,9 @@ public class when_a_page_type_property_is_annotated_with_property_group : Synchr
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-AltText")).Tab.ID.ShouldEqual(-1);
}

[Subject("Synchronization")]
public class when_a_page_type_property_is_annotated_with_property_group_with_tab_defined : SynchronizationSpecs
{

static string propertyName = "PropertyOne";
static string pageTypeName = "PageTypeName";

Expand All @@ -97,7 +98,7 @@ public class when_a_page_type_property_is_annotated_with_property_group_with_tab
prop.AddAttributeTemplate(propertyGroupAttribute);
});
});

SyncContext.AssemblyLocator.Add(typeof(when_a_page_type_property_is_annotated_with_property_group).Assembly);
};

Expand All @@ -113,6 +114,86 @@ public class when_a_page_type_property_is_annotated_with_property_group_with_tab
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-AltText")).Tab.ID.ShouldEqual(SyncContext.TabDefinitionRepository.List().Where(current => !string.IsNullOrEmpty(current.Name) && current.Name.Equals("Footer")).First().ID);
}

[Subject("Synchronization")]
public class when_a_page_type_property_is_annotated_with_property_group_with_property_attribute_values_overridden : SynchronizationSpecs
{
static string propertyName = "PropertyOne";
static string pageTypeName = "PageTypeName";

Establish context = () =>
{
var propertyGroupAttribute = new PageTypePropertyGroupAttribute
{
EditCaptionPrefix = "Property One - ",
StartSortOrderFrom = 100,
Tab = typeof(FooterTab)
};

var pageTypePropertyOverrideAttribute = new PageTypePropertyGroupPropertyOverrideAttribute
{
PropertyName = "ImageUrl",
EditCaption = "New Caption",
DefaultValue = "NewDefaultValue",
DefaultValueType = DefaultValueType.Value,
DisplayInEditMode = false,
HelpText = "NewHelpText",
Required = true,
Searchable = true,
UniqueValuePerLanguage = true
};

SyncContext.CreateAndAddPageTypeClassToAppDomain(type =>
{
type.Name = pageTypeName;
type.AddProperty(prop =>
{
prop.Name = propertyName;
prop.Type = typeof(Image);
prop.AddAttributeTemplate(propertyGroupAttribute);
prop.AddAttributeTemplate(pageTypePropertyOverrideAttribute);
});
});

SyncContext.AssemblyLocator.Add(typeof(when_a_page_type_property_is_annotated_with_property_group_with_property_attribute_values_overridden).Assembly);

};

Because of =
() => SyncContext.PageTypeSynchronizer.SynchronizePageTypes();

It should_have_a_property_one_image_url_page_type_property_with_an_updated_edit_caption =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).EditCaption.ShouldEqual("Property One - New Caption");

It should_have_a_property_one_image_url_page_type_property_with_an_updated_default_value =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).DefaultValue.ShouldEqual("NewDefaultValue");

It should_have_a_property_one_image_url_page_type_property_with_an_updated_default_value_type =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).DefaultValueType.ShouldEqual(DefaultValueType.Value);

It should_have_a_property_one_image_url_page_type_property_with_an_updated_display_edit_ui =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).DisplayEditUI.ShouldEqual(false);

It should_have_a_property_one_image_url_page_type_property_with_an_updated_help_text =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).HelpText.ShouldEqual("NewHelpText");

It should_have_a_property_one_image_url_page_type_property_with_an_updated_required =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).Required.ShouldEqual(true);

It should_have_a_property_one_image_url_page_type_property_with_an_updated_searchable =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).Searchable.ShouldEqual(true);

It should_have_a_property_one_image_url_page_type_property_with_an_updated_unique_value_per_language =
() =>
SyncContext.PageDefinitionRepository.List().FirstOrDefault(p => string.Equals(p.Name, "PropertyOne-ImageUrl")).LanguageSpecific.ShouldEqual(true);
}

public class Image : PageTypePropertyGroup
{
[PageTypeProperty(EditCaption = "Image Url", SortOrder = 0)]
Expand All @@ -139,4 +220,5 @@ public override int SortIndex
get { return 1000; }
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public class when_a_page_type_property_matches_existing_page_type_property_but_e
PropertyInfo property = pageTypeType.GetProperty(propertyName);
propertyAttribute = property.GetCustomAttributes(typeof(PageTypePropertyAttribute), false).First() as PageTypePropertyAttribute;

propertyAttribute.DefaultValue = "true";
propertyAttribute.DefaultValueType = DefaultValueType.Value;

var existingPageDefinition = new PageDefinition();
existingPageDefinition.Type = SyncContext.PageDefinitionTypeRepository.GetPageDefinitionType<PropertyXhtmlString>();
existingPageDefinition.PageTypeID = existingPageType.ID;
Expand All @@ -177,8 +180,10 @@ public class when_a_page_type_property_matches_existing_page_type_property_but_e
existingPageDefinition.Tab = SyncContext.TabDefinitionRepository.GetTabDefinition(tabName);
existingPageDefinition.Required = !propertyAttribute.Required;
existingPageDefinition.Searchable = !propertyAttribute.Searchable;
existingPageDefinition.DefaultValue = "asdf";
existingPageDefinition.DefaultValueType = DefaultValueType.Inherit;

existingPageDefinition.DefaultValue = propertyAttribute.DefaultValue.ToString();
existingPageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;

existingPageDefinition.DisplayEditUI = !propertyAttribute.DisplayInEditMode;
existingPageDefinition.FieldOrder = propertyAttribute.SortOrder + 100;
existingPageDefinition.LanguageSpecific = !propertyAttribute.UniqueValuePerLanguage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void GivenName_Constructor_SetsNameProperty()
string name = TestValueUtility.CreateRandomString();
Type propertyType = typeof(string);
IPageType pageType = new NativePageType();
PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);

PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute, null);


Assert.Equal<string>(name, definition.Name);
Expand All @@ -31,7 +31,7 @@ public void GivenType_Constructor_SetsPropertyTypeProperty()
Type propertyType = typeof(string);
IPageType pageType = new NativePageType();

PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);
PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute, null);


Assert.Equal<Type>(propertyType, definition.PropertyType);
Expand All @@ -46,7 +46,7 @@ public void GivenPageType_Constructor_SetsPageTypeProperty()
IPageType pageType = new NativePageType();
pageType.GUID = Guid.NewGuid();

PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);
PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute, null);


Assert.Equal<IPageType>(pageType, definition.PageType, new PageTypeComparer());
Expand All @@ -73,10 +73,10 @@ public void GivenPageTypePropertyAttribute_Constructor_SetsPageTypePropertyAttri
Type propertyType = typeof(string);
IPageType pageType = new NativePageType();

PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);
PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute, null);


Assert.Equal<PageTypePropertyAttribute>(attribute, definition.PageTypePropertyAttribute,
Assert.Equal<PageTypePropertyAttribute>(attribute, definition.PageTypePropertyAttribute,
new PageTypePropertyComparer());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static PageTypePropertyDefinition CreatePageTypePropertyDefinition()
Type type = typeof(string);
IPageType pageType = new NativePageType();
PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();
return new PageTypePropertyDefinition(name, type, pageType, attribute);
return new PageTypePropertyDefinition(name, type, pageType, attribute, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ public void GivePropertyDefinition_UpdatePageDefinition_UpdatesPageDefinitionDef
var pageDefinitionUpdater = GetPageDefinitionUpdater();
PageDefinition pageDefinitionToUpdate = new PageDefinition();
PageTypePropertyDefinition propertyDefinition = CreatePageTypePropertyDefinition();
propertyDefinition.PageTypePropertyAttribute.DefaultValue = TestValueUtility.CreateRandomString();
propertyDefinition.PageTypePropertyAttribute.DefaultValue = "true";// TestValueUtility.CreateRandomString();

// As we have had to modifiy how default value and value types are handled in definition update
// we now have to specify a default value to satisfy this test
propertyDefinition.PageTypePropertyAttribute.DefaultValueType = DefaultValueType.Value;

pageDefinitionUpdater.UpdateExistingPageDefinition(pageDefinitionToUpdate, propertyDefinition);

Expand All @@ -180,6 +184,10 @@ public void GivePropertyDefinition_UpdatePageDefinition_UpdatesPageDefinitionDef
PageTypePropertyDefinition propertyDefinition = CreatePageTypePropertyDefinition();
propertyDefinition.PageTypePropertyAttribute.DefaultValueType = defaultValueType;

// As we have had to modifiy how default value and value types are handled in definition update
// we now have to specify a default value to satisfy this test
propertyDefinition.PageTypePropertyAttribute.DefaultValue = "true";

pageDefinitionUpdater.UpdateExistingPageDefinition(pageDefinitionToUpdate, propertyDefinition);

Assert.Equal<DefaultValueType>(propertyDefinition.PageTypePropertyAttribute.DefaultValueType, pageDefinitionToUpdate.DefaultValueType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void GivenPageTypePropertyDefinitionWithNoTypeAndNonMappedPropertyType_Ge
PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null, new NativePageDefinitionsMap());
Type unmappedType = typeof(StringBuilder);
PageTypePropertyDefinition definition = new PageTypePropertyDefinition(
TestValueUtility.CreateRandomString(), unmappedType, new NativePageType(), new PageTypePropertyAttribute());
TestValueUtility.CreateRandomString(), unmappedType, new NativePageType(), new PageTypePropertyAttribute(), null);

Exception exception = Record.Exception(() => { mapper.GetPageDefinitionType(definition); });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
using EPiServer.DataAbstraction;
using PageTypeBuilder.Abstractions;
using PageTypeBuilder.Discovery;
using PageTypeBuilder.Synchronization;
using PageTypeBuilder.Synchronization.PageDefinitionSynchronization;
using Xunit;

namespace PageTypeBuilder.Tests.Synchronization
{
public class PageTypePropertyDefinitionExtensionsTests
{
[Fact]
public void GivenPageTypePropertyDefinitionWithNoEditCaption_GetEditCaptionOrName_ReturnsName()
{
string propertyName = TestValueUtility.CreateRandomString();
PageTypePropertyDefinition definition =
new PageTypePropertyDefinition(propertyName, typeof(string), new NativePageType(), new PageTypePropertyAttribute());

string returnedEditCaption = definition.GetEditCaptionOrName();

Assert.Equal<string>(propertyName, returnedEditCaption);
}

[Fact]
public void GivenPageTypePropertyDefinitionWithEditCaption_GetEditCaptionOrName_ReturnsEditCaptionFromAttribute()
{
PageTypePropertyDefinition definition =
new PageTypePropertyDefinition(
TestValueUtility.CreateRandomString(), typeof(string), new NativePageType(), new PageTypePropertyAttribute());
string editCaption = TestValueUtility.CreateRandomString();
definition.PageTypePropertyAttribute.EditCaption = editCaption;

string returnedEditCaption = definition.GetEditCaptionOrName();

Assert.Equal<string>(editCaption, returnedEditCaption);
}
}
}
namespace PageTypeBuilder.Tests.Synchronization
{
using Abstractions;
using PageTypeBuilder.Discovery;
using PageTypeBuilder.Synchronization.PageDefinitionSynchronization;
using Xunit;

public class PageTypePropertyDefinitionExtensionsTests
{
[Fact]
public void GivenPageTypePropertyDefinitionWithNoEditCaption_GetEditCaptionOrName_ReturnsName()
{
string propertyName = TestValueUtility.CreateRandomString();
PageTypePropertyDefinition definition =
new PageTypePropertyDefinition(propertyName, typeof(string), new NativePageType(), new PageTypePropertyAttribute(), null);

string returnedEditCaption = definition.GetEditCaptionOrName(false);

Assert.Equal<string>(propertyName, returnedEditCaption);
}

[Fact]
public void GivenPageTypePropertyDefinitionWithEditCaption_GetEditCaptionOrName_ReturnsEditCaptionFromAttribute()
{
PageTypePropertyDefinition definition =
new PageTypePropertyDefinition(TestValueUtility.CreateRandomString(), typeof(string), new NativePageType(), new PageTypePropertyAttribute(), null);
string editCaption = TestValueUtility.CreateRandomString();
definition.PageTypePropertyAttribute.EditCaption = editCaption;

string returnedEditCaption = definition.GetEditCaptionOrName(false);

Assert.Equal<string>(editCaption, returnedEditCaption);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void NonVirtualMemberNotification(Type type, System.Reflection.MemberInfo
public bool ShouldInterceptMethod(Type type, System.Reflection.MethodInfo memberInfo)
{
return memberInfo.IsGetterOrSetterForPropertyWithAttribute(typeof(PageTypePropertyAttribute))
&& !memberInfo.IsGetterOrSetterForPropertyWithAttribute(typeof(PageTypePropertyGroupPropertyOverrideAttribute))
&& memberInfo.IsCompilerGenerated();
}

Expand All @@ -26,7 +27,7 @@ public void NonProxyableMemberNotification(Type type, System.Reflection.MemberIn

public override bool Equals(object obj)
{
return ((obj != null) && (obj.GetType() == typeof(PageTypePropertiesProxyGenerationHook)));
return ((obj != null) && (obj.GetType() == typeof(PageTypePropertiesProxyGenerationHook)));
}

public override int GetHashCode()
Expand Down
Loading