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 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. 3
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();
        }