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 GivenAttributeWithMappableTypeSpecified_ValidatePageTypePropertyType_DoesNotThrowException() { PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithValidTypeSpecified"); PageTypePropertyAttribute attribute = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First(); MockRepository fakes = new MockRepository(); PageDefinitionTypeFactory pageDefinitionTypeFactory = fakes.Stub <PageDefinitionTypeFactory>(); pageDefinitionTypeFactory.Stub(factory => factory.GetPageDefinitionType("EPiServer.SpecializedProperties.PropertyXhtmlString", "EPiServer")).Return(new PageDefinitionType()); pageDefinitionTypeFactory.Replay(); PageTypeDefinitionPropertiesValidator propertiesValidator = new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeFactory)); Exception exception = Record.Exception(() => { propertiesValidator.ValidatePageTypePropertyType(propertyInfo); }); Assert.Null(exception); }
public void GivenAttributeWithMappableTypeAndUnmappableTypeSpecified_ValidatePageTypePropertyType_ThrowsException() { PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithInvalidTypeSpecified"); PageTypePropertyAttribute attribute = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First(); MockRepository fakes = new MockRepository(); PageDefinitionTypeFactory pageDefinitionTypeFactory = fakes.Stub <PageDefinitionTypeFactory>(); pageDefinitionTypeFactory.Stub(factory => factory.GetPageDefinitionType("System.Text.StringBuilder", "mscorlib")).Return(null); pageDefinitionTypeFactory.Replay(); PageTypeDefinitionPropertiesValidator propertiesValidator = new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeFactory)); Exception exception = Record.Exception(() => { propertiesValidator.ValidatePageTypePropertyType(propertyInfo); }); Assert.NotNull(exception); Assert.Equal <Type>(typeof(UnmappablePropertyTypeException), exception.GetType()); }