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); }
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 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); }