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