Beispiel #1
0
        public void GivenPageTypePropertyDefinition_GetPageDefinitionType_CallsGetPropertyType()
        {
            PageTypePropertyDefinition   definition               = PageDefinitionSynchronizationEngineTestsUtility.CreatePageTypePropertyDefinition();
            MockRepository               fakes                    = new MockRepository();
            PageDefinitionTypeRepository fakeRepository           = fakes.Stub <PageDefinitionTypeRepository>();
            PageDefinitionTypeMapper     pageDefinitionTypeMapper = fakes.PartialMock <PageDefinitionTypeMapper>(fakeRepository, new NativePageDefinitionsMap());
            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));
        }
Beispiel #2
0
        public void GivenPageTypePropertyDefinitionWithNativeType_GetPageDefinitionType_ReturnsCorrectPageDefinitionType()
        {
            PageTypePropertyDefinition definition = PageDefinitionSynchronizationEngineTestsUtility.CreatePageTypePropertyDefinition();

            definition.PageTypePropertyAttribute.Type = typeof(PropertyString);
            MockRepository fakes = new MockRepository();
            PageDefinitionTypeRepository fakeRepository = fakes.Stub <PageDefinitionTypeRepository>();
            PageDefinitionTypeMapper     mapper         = new PageDefinitionTypeMapper(fakeRepository, new NativePageDefinitionsMap());
            int nativeTypeID = new NativePageDefinitionsMap().GetNativeTypeID(definition.PageTypePropertyAttribute.Type);
            PageDefinitionType pageDefinitionTypeFromFactory = new PageDefinitionType(1, PropertyDataType.String, TestValueUtility.CreateRandomString());

            fakeRepository.Stub(factory => factory.GetPageDefinitionType(nativeTypeID)).Return(pageDefinitionTypeFromFactory);
            fakeRepository.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();
            PageDefinitionTypeRepository pageDefinitionTypeRepository = fakes.Stub <PageDefinitionTypeRepository>();

            pageDefinitionTypeRepository.Stub(factory =>
                                              factory.GetPageDefinitionType("EPiServer.SpecializedProperties.PropertyXhtmlString", "EPiServer")).Return(new PageDefinitionType());
            pageDefinitionTypeRepository.Replay();
            PageTypeDefinitionPropertiesValidator propertiesValidator =
                new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeRepository, new NativePageDefinitionsMap()));

            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();
            PageDefinitionTypeRepository pageDefinitionTypeRepository = fakes.Stub <PageDefinitionTypeRepository>();

            pageDefinitionTypeRepository.Stub(factory =>
                                              factory.GetPageDefinitionType("System.Text.StringBuilder", "mscorlib")).Return(null);
            pageDefinitionTypeRepository.Replay();
            PageTypeDefinitionPropertiesValidator propertiesValidator =
                new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeRepository, new NativePageDefinitionsMap()));


            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypePropertyType(propertyInfo);
            });

            Assert.NotNull(exception);
            Assert.Equal <Type>(typeof(UnmappablePropertyTypeException), exception.GetType());
        }