private PageTypeDefinitionPropertiesValidator CreateValidatorWithFakeValidatePageTypePropertyMethodCalls(PropertyInfo propertyInfo)
        {
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(validator => validator.ValidateCompilerGeneratedProperty(propertyInfo));
            propertiesValidator.Stub(validator => validator.ValidatePageTypePropertyAttribute(propertyInfo));
            propertiesValidator.Stub(validator => validator.ValidatePageTypePropertyType(propertyInfo));
            propertiesValidator.Replay();
            return(propertiesValidator);
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_CallsValidatePageTypePropertyForEachPropertyWithPageTypePropertyAttribute()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageType),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypeProperty(
                    Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();

            propertiesValidator.ValidatePageTypeProperties(definition);

            int expectedNumberOfCalls = (from property in definition.Type.GetPublicOrPrivateProperties()
                                         where property.HasAttribute(typeof(PageTypePropertyAttribute))
                                         select property).Count();

            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypeProperty(
                                                    Arg <PropertyInfo> .Is.NotNull), options => options.Repeat.Times(expectedNumberOfCalls));
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_ValidatesOk_WhenCollissionsExistsInInterfaceDefinitionsButIsTrumpedByDefinitionInPageTypeDefinition()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithClashingInterfacesWhichAlsoDefinesProperty),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();
            propertiesValidator.ValidatePageTypeProperties(definition);
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_ValidatesNotOk_WhenCollissionsExistsInInterfaceDefinitions()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithClashingInterfaces),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();
            Assert.Throws(typeof(PageTypeBuilderException), () => propertiesValidator.ValidatePageTypeProperties(definition));
        }
        public void GivenPropertyInfo_ValidatePageTypePropertyAttribute_ValidatesPageTypeAttributeTabProperty()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("StringTestProperty");
            PageTypePropertyAttribute             attribute           = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            MockRepository                        fakes               = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(validator =>
                                     validator.ValidatePageTypeAttributeTabProperty(Arg <PropertyInfo> .Is.NotNull, Arg <PageTypePropertyAttribute> .Is.NotNull));
            propertiesValidator.Replay();

            propertiesValidator.ValidatePageTypePropertyAttribute(propertyInfo);

            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypeAttributeTabProperty(propertyInfo, attribute));
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_ValidatesOk_WhenNoCollissionsInInterfaceDefinitions()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithInterface),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();

            propertiesValidator.ValidatePageTypeProperties(definition);
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_FindsCorrectNumberOfPropertisInInterface()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithInterface),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();
            propertiesValidator.ValidatePageTypeProperties(definition);
            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypePropertyType(
                                                    Arg <PropertyInfo> .Is.NotNull), options => options.Repeat.Times(1));
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_FindsCorrectPropertyInInterface()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithInterface),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();
            propertiesValidator.ValidatePageTypeProperties(definition);
            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypePropertyType(
                                                    Arg <PropertyInfo> .Matches(p => ((PageTypePropertyAttribute)
                                                                                      p.GetCustomAttributes(typeof(PageTypePropertyAttribute), false).First()).EditCaption == TestEditCaptions.FromInterfaceA)));
        }
        public void GivenPageTypeDefinition_ValidatePageTypeProperties_CanOverridePropertyFromClashingInterfacesInPageType()
        {
            PageTypeDefinition definition = new PageTypeDefinition
            {
                Type      = typeof(TestPageTypeWithClashingInterfacesWhichAlsoDefinesProperty),
                Attribute = new PageTypeAttribute()
            };
            MockRepository fakes = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(
                validator => validator.ValidatePageTypePropertyType(Arg <PropertyInfo> .Is.Anything));
            propertiesValidator.Replay();
            propertiesValidator.ValidatePageTypeProperties(definition);
            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypePropertyType(
                                                    Arg <PropertyInfo> .Matches(p => ((PageTypePropertyAttribute)
                                                                                      p.GetCustomAttributes(typeof(PageTypePropertyAttribute), false).First()).EditCaption == TestEditCaptions.FromPageType)));
            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypeProperty(
                                                    Arg <PropertyInfo> .Is.NotNull), options => options.Repeat.Times(1));
        }