public void Constructor_SetsPageDefinitionTypeMapperProperty() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); PageTypeDefinitionValidator pageTypeValidator = new PageTypeDefinitionValidator(mapper); Assert.NotNull(pageTypeValidator.PropertiesValidator.PageDefinitionTypeMapper); }
public void NativePropertyTypes_ReturnsArrayWithPropertyTypeAtIndex(Type propertyType, int index) { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); Type[] nativePropertyTypes = mapper.NativePropertyTypes; Assert.Equal <Type>(propertyType, nativePropertyTypes[index]); }
public void GivenNativeType_GetNativeTypeID_ReturnsCorrespondingIndexFromNativePropertyTypes() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); int nativeTypeID = mapper.GetNativeTypeID(typeof(PropertyString)); Assert.Equal <Type>(mapper.NativePropertyTypes[nativeTypeID], typeof(PropertyString)); }
public void GivenType_GetDefaultPropertyType_ReturnsDefaultPropertyType(Type nativeType, Type expectedDefaultType) { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); Type returnedType = mapper.GetDefaultPropertyType(nativeType); Assert.Equal <Type>(expectedDefaultType, returnedType); }
public void GivenNonNativeType_GetNativeTypeID_ThrowsException() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); Type nonNativeType = typeof(string); Exception exception = Record.Exception(() => { mapper.GetNativeTypeID(nonNativeType); }); Assert.NotNull(exception); }
public void GivenPageTypePropertyDefinitionWithTypeSet_GetPropertyType_ReturnsThatType() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null, new NativePageDefinitionsMap()); PageTypePropertyDefinition definition = PageDefinitionSynchronizationEngineTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = typeof(PropertyImageUrl); Type returnedType = mapper.GetPropertyType(definition.PropertyType, definition.PageTypePropertyAttribute); Assert.Equal<Type>(definition.PageTypePropertyAttribute.Type, returnedType); }
public void GivenPageTypePropertyDefinitionWithNoTypeAndNonMappedPropertyType_GetPageDefinitionType_ThrowsException() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); Type unmappedType = typeof(StringBuilder); PageTypePropertyDefinition definition = new PageTypePropertyDefinition( TestValueUtility.CreateRandomString(), unmappedType, new NativePageType(), new PageTypePropertyAttribute()); Exception exception = Record.Exception(() => { mapper.GetPageDefinitionType(definition); }); Assert.NotNull(exception); }
public void GivenPageTypePropertyDefinitionWithTypeSet_GetPropertyType_ReturnsThatType() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null); PageTypePropertyDefinition definition = PageTypePropertyUpdaterTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = typeof(PropertyImageUrl); Type returnedType = mapper.GetPropertyType(definition.PropertyType, definition.PageTypePropertyAttribute); Assert.Equal <Type>(definition.PageTypePropertyAttribute.Type, returnedType); }
protected internal virtual void ValidatePageTypePropertyType(PropertyInfo propertyInfo) { PageTypePropertyAttribute pageTypePropertyAttribute = (PageTypePropertyAttribute) propertyInfo.GetCustomAttributes(typeof(PageTypePropertyAttribute), false).First(); if (PageDefinitionTypeMapper.GetPageDefinitionType( propertyInfo.DeclaringType.Name, propertyInfo.Name, propertyInfo.PropertyType, pageTypePropertyAttribute) == null) { string errorMessage = "Unable to map the type for the property {0} in {1} to a suitable EPiServer CMS property."; errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name, propertyInfo.DeclaringType.Name); throw new UnmappablePropertyTypeException(errorMessage); } }
public void GivenPageTypePropertyDefinition_GetPageDefinitionType_CallsGetPropertyType() { PageTypePropertyDefinition definition = PageTypePropertyUpdaterTestsUtility.CreatePageTypePropertyDefinition(); MockRepository fakes = new MockRepository(); PageDefinitionTypeFactory fakeFactory = fakes.Stub <PageDefinitionTypeFactory>(); PageDefinitionTypeMapper pageDefinitionTypeMapper = fakes.PartialMock <PageDefinitionTypeMapper>(fakeFactory); Type type = typeof(string); pageDefinitionTypeMapper.Stub(mapper => mapper.GetPropertyType(definition.PropertyType, definition.PageTypePropertyAttribute)).Return(type); fakes.ReplayAll(); pageDefinitionTypeMapper.GetPageDefinitionType(definition); pageDefinitionTypeMapper.AssertWasCalled(mapper => mapper.GetPropertyType(definition.PropertyType, definition.PageTypePropertyAttribute)); }
public void GivenPageTypePropertyDefinitionWithNoTypeSet_GetPropertyType_GetsDefaultPropertyTypeForDefinitionsPropertyType() { PageTypePropertyDefinition definition = PageTypePropertyUpdaterTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = null; MockRepository fakes = new MockRepository(); PageDefinitionTypeMapper pageDefinitionTypeMapper = fakes.PartialMock <PageDefinitionTypeMapper>((PageDefinitionTypeFactory)null); Type defaultType = typeof(string); pageDefinitionTypeMapper.Stub(utility => utility.GetDefaultPropertyType(definition.PropertyType)).Return(defaultType); pageDefinitionTypeMapper.Replay(); Type returnedType = pageDefinitionTypeMapper.GetDefaultPropertyType(definition.PropertyType); pageDefinitionTypeMapper.AssertWasCalled(utility => utility.GetDefaultPropertyType(definition.PropertyType)); Assert.Equal <Type>(defaultType, returnedType); }
public void GivenPageTypePropertyDefinitionWithNativeType_GetPageDefinitionType_ReturnsCorrectPageDefinitionType() { PageTypePropertyDefinition definition = PageTypePropertyUpdaterTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = typeof(PropertyString); MockRepository fakes = new MockRepository(); PageDefinitionTypeFactory fakeFactory = fakes.Stub <PageDefinitionTypeFactory>(); PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(fakeFactory); int nativeTypeID = mapper.GetNativeTypeID(definition.PageTypePropertyAttribute.Type); PageDefinitionType pageDefinitionTypeFromFactory = new PageDefinitionType(1, PropertyDataType.String, TestValueUtility.CreateRandomString()); fakeFactory.Stub(factory => factory.GetPageDefinitionType(nativeTypeID)).Return(pageDefinitionTypeFromFactory); fakeFactory.Replay(); PageDefinitionType returnedPageDefinitionType = mapper.GetPageDefinitionType(definition); Assert.Equal <PageDefinitionType>(pageDefinitionTypeFromFactory, returnedPageDefinitionType); }
public void GivenPageTypePropertyDefinitionWithNonNativeType_GetPageDefinitionType_ReturnsCorrectPageDefinitionType() { PageTypePropertyDefinition definition = PageDefinitionSynchronizationEngineTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = typeof(PropertyXhtmlString); MockRepository fakes = new MockRepository(); PageDefinitionTypeRepository fakeRepository = fakes.Stub <PageDefinitionTypeRepository>(); PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(fakeRepository, new NativePageDefinitionsMap()); PageDefinitionType pageDefinitionTypeFromFactory = new PageDefinitionType(1, PropertyDataType.String, TestValueUtility.CreateRandomString()); string typeName = definition.PageTypePropertyAttribute.Type.FullName; string assemblyName = definition.PageTypePropertyAttribute.Type.Assembly.GetName().Name; fakeRepository.Stub(factory => factory.GetPageDefinitionType(typeName, assemblyName)).Return(pageDefinitionTypeFromFactory); fakeRepository.Replay(); PageDefinitionType returnedPageDefinitionType = mapper.GetPageDefinitionType(definition); Assert.Equal <PageDefinitionType>(pageDefinitionTypeFromFactory, returnedPageDefinitionType); }
public void GivenPageTypePropertyDefinitionWithNonNativeType_GetPageDefinitionType_ReturnsCorrectPageDefinitionType() { PageTypePropertyDefinition definition = PageDefinitionSynchronizationEngineTestsUtility.CreatePageTypePropertyDefinition(); definition.PageTypePropertyAttribute.Type = typeof(PropertyXhtmlString); MockRepository fakes = new MockRepository(); PageDefinitionTypeRepository fakeRepository = fakes.Stub<PageDefinitionTypeRepository>(); PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(fakeRepository, new NativePageDefinitionsMap()); PageDefinitionType pageDefinitionTypeFromFactory = new PageDefinitionType(1, PropertyDataType.String, TestValueUtility.CreateRandomString()); string typeName = definition.PageTypePropertyAttribute.Type.FullName; string assemblyName = definition.PageTypePropertyAttribute.Type.Assembly.GetName().Name; fakeRepository.Stub(factory => factory.GetPageDefinitionType(typeName, assemblyName)).Return(pageDefinitionTypeFromFactory); fakeRepository.Replay(); PageDefinitionType returnedPageDefinitionType = mapper.GetPageDefinitionType(definition); Assert.Equal<PageDefinitionType>(pageDefinitionTypeFromFactory, returnedPageDefinitionType); }
public void GivenPageTypePropertyDefinitionWithNoTypeAndNonMappedPropertyType_GetPageDefinitionType_ThrowsException() { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null, new NativePageDefinitionsMap()); Type unmappedType = typeof(StringBuilder); PageTypePropertyDefinition definition = new PageTypePropertyDefinition( TestValueUtility.CreateRandomString(), unmappedType, new NativePageType(), new PageTypePropertyAttribute()); Exception exception = Record.Exception(() => { mapper.GetPageDefinitionType(definition); }); Assert.NotNull(exception); }
public PageTypeDefinitionValidator(PageDefinitionTypeMapper pageDefinitionTypeMapper) { PropertiesValidator = new PageTypeDefinitionPropertiesValidator(pageDefinitionTypeMapper); }
public PageTypeDefinitionValidator(PageDefinitionTypeMapper pageDefinitionTypeMapper) { PropertiesValidator = new PageTypeDefinitionPropertiesValidator(pageDefinitionTypeMapper); }
public PageTypeDefinitionPropertiesValidator(PageDefinitionTypeMapper pageDefinitionTypeMapper) { PageDefinitionTypeMapper = pageDefinitionTypeMapper; }
public void GivenType_GetDefaultPropertyType_ReturnsDefaultPropertyType(Type nativeType, Type expectedDefaultType) { PageDefinitionTypeMapper mapper = new PageDefinitionTypeMapper(null, new NativePageDefinitionsMap()); Type returnedType = mapper.GetDefaultPropertyType(nativeType); Assert.Equal<Type>(expectedDefaultType, returnedType); }
public PageTypeDefinitionPropertiesValidator(PageDefinitionTypeMapper pageDefinitionTypeMapper) { PageDefinitionTypeMapper = pageDefinitionTypeMapper; }