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 MergeAttributes_FirstArgumentNull() { var injectedAllowedTypesAttribute = new InjectedAllowedTypesAttribute(_contentLoader) { AllowedTypes = new[] { typeof(DifferentPage) } }; var result = InjectedAllowedTypes.MergeAttributes(null, injectedAllowedTypesAttribute); result.AllowedTypes.ShouldBe(new[] { typeof(DifferentPage) }); }
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) }); }
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(); }