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