public void Locator_Should_Discover_Two_Definitions_From_TabAuthorizedTypedPageData()
        {
            var typedPageData = new TabAuthorizedTypedPageData();
            TabDefinitionCollection tabDefinitions = new FakeTabDefinitionRepository().List();
            typedPageData.Property.Add(new PropertyString
                                           {
                                               Name = "PageName",
                                               OwnerTab = tabDefinitions.First(t => t.Name == "MetaData").ID
                                           });

            SetupTabBasedPropertiesAndPropertyGroupPageDataProperties(typedPageData);

            _locator = new AuthorizedPropertyDefinitionLocator(typedPageData, typedPageData.GetType(), new FakeTabDefinitionRepository());
            var actualDefinitionList = _locator.GetAuthorizedPropertyDefinitions();
            Assert.IsTrue(actualDefinitionList.Count == 2);
            
            //This is testing differnet functionality - should be a different test
            //var propertyOneDefinition = actualDefinitionList.Single(d => d.PropertyName == "Property1");
            //Assert.IsTrue(propertyOneDefinition.AuthorizedPrincipals.Contains("Role1"));

            //This is testing differnet functionality - should be a different test
            //var pageCategoryDefinition = actualDefinitionList.Single(d => d.PropertyName == "PageName");
            //Assert.IsTrue(pageCategoryDefinition.AuthorizedPrincipals.Contains("Role2"));
        }
        private void SetupTabBasedPropertiesAndPropertyGroupPageDataProperties(TypedPageData typedPageData)
        {
            TabDefinitionCollection tabDefinitions = new FakeTabDefinitionRepository().List();
            Type type = typedPageData.GetType();

            foreach (PropertyInfo property in AttributedTypesUtility.GetPublicOrPrivateProperties(type)
                .Where(AttributedTypesUtility.PropertyHasAttribute<PageTypePropertyAttribute>))
            {
                int tabDefinitionId = -1;
                PageTypePropertyAttribute pageTypePropertyAttribute = AttributedTypesUtility.GetAttributesFromProperty<PageTypePropertyAttribute>(property).First();
                
                if (pageTypePropertyAttribute.Tab != null)
                {
                    Tab tab = Activator.CreateInstance(pageTypePropertyAttribute.Tab) as Tab;
                    TabDefinition tabDefinition = tabDefinitions.FirstOrDefault(t => t.Name == tab.Name);

                    if (tabDefinition != null)
                        tabDefinitionId = tabDefinition.ID;
                }

                typedPageData.Property.Add(new PropertyString { Name = property.Name, OwnerTab = tabDefinitionId });
            }

            foreach (PropertyInfo propertyGroupProperty in AttributedTypesUtility.GetPublicOrPrivateProperties(type)
                .Where(AttributedTypesUtility.PropertyHasAttribute<PageTypePropertyGroupAttribute>))
            {
                foreach (PropertyInfo property in AttributedTypesUtility.GetPublicOrPrivateProperties(propertyGroupProperty.PropertyType)
                    .Where(AttributedTypesUtility.PropertyHasAttribute<PageTypePropertyAttribute>))
                    {
                        int tabDefinitionId = -1;
                        PageTypePropertyGroupAttribute pageTypePropertyGroupAttribute = AttributedTypesUtility.GetAttributesFromProperty<PageTypePropertyGroupAttribute>(propertyGroupProperty).First();

                        if (pageTypePropertyGroupAttribute.Tab != null)
                        {
                            Tab tab = Activator.CreateInstance(pageTypePropertyGroupAttribute.Tab) as Tab;
                            TabDefinition tabDefinition = tabDefinitions.FirstOrDefault(t => t.Name == tab.Name);

                            if (tabDefinition != null)
                                tabDefinitionId = tabDefinition.ID;
                        }

                        typedPageData.Property.Add(new PropertyString
                                                       {
                                                           Name = string.Format("{0}-{1}", propertyGroupProperty.Name, property.Name),
                                                           OwnerTab = tabDefinitionId
                                                       });
                    }
            }
        }