Esempio n. 1
0
        public void ShouldNotAllowDifferentPageType_BecauseOfAllowedTypes()
        {
            var page = new StandardPage
            {
                Items = _contentReferences
            };

            var differentPageTypeContentReference = new ContentReference(2000);

            page.Items.Add(differentPageTypeContentReference);

            _contentLoader.Get <IContent>(differentPageTypeContentReference).Returns(new DifferentPage());

            var attribute = new InjectedAllowedTypesAttribute(_contentLoader)
            {
                AllowedTypes = new[] { typeof(StandardPage) }
            };

            var validationContext = new ValidationContext(page)
            {
                MemberName = nameof(page.Items)
            };
            var result = attribute.RunValidation(page.Items, validationContext);

            result.ShouldNotBeNull();
        }
Esempio n. 2
0
        public void MergeAttributes_FirstArgumentNull()
        {
            var injectedAllowedTypesAttribute = new InjectedAllowedTypesAttribute(_contentLoader)
            {
                AllowedTypes = new[] { typeof(DifferentPage) }
            };

            var result = InjectedAllowedTypes.MergeAttributes(null, injectedAllowedTypesAttribute);

            result.AllowedTypes.ShouldBe(new[] { typeof(DifferentPage) });
        }
Esempio n. 3
0
        public void MergeAttributes_ShouldContainBothSpecifiedAndInjectedAttribute_Distinct()
        {
            var allowedTypesAttribute = new AllowedTypesAttribute
            {
                AllowedTypes = new[] { typeof(StandardPage) }
            };

            var injectedAllowedTypesAttribute = new InjectedAllowedTypesAttribute(_contentLoader)
            {
                AllowedTypes = new[] { typeof(DifferentPage), typeof(StandardPage) }
            };

            var result = InjectedAllowedTypes.MergeAttributes(allowedTypesAttribute, injectedAllowedTypesAttribute);

            result.AllowedTypes.ShouldBe(new[] { typeof(StandardPage), typeof(DifferentPage) });
        }
Esempio n. 4
0
        public void ShouldAllowStandardPageType_BecauseOfAllowedTypes()
        {
            var page = new StandardPage
            {
                Items = _contentReferences
            };

            var attribute = new InjectedAllowedTypesAttribute(_contentLoader)
            {
                AllowedTypes = new[] { typeof(StandardPage) }
            };

            var validationContext = new ValidationContext(page)
            {
                MemberName = nameof(page.Items)
            };
            var result = attribute.RunValidation(page.Items, validationContext);

            result.ShouldBeNull();
        }
Esempio n. 5
0
        public void ShouldNotAllowDifferentPage_BecauseOfRestrictedTypesInterface()
        {
            var page = new StandardPage
            {
                Items = _contentReferences
            };

            var attribute = new InjectedAllowedTypesAttribute(_contentLoader)
            {
                RestrictedTypes = new[] { typeof(IContainable) }
            };

            var validationContext = new ValidationContext(page)
            {
                MemberName = nameof(page.Items)
            };
            var result = attribute.RunValidation(page.Items, validationContext);

            result.ShouldNotBeNull();
        }