public void DirectTypeGettingRequiredAttributesInheritTest() { var type = typeof(NormalWithAttrClassWrapper2); var one = typeof(ModelOneAttribute); var two = typeof(ModelTwoAttribute); var three = typeof(ModelThreeAttribute); var four = typeof(ModelFourAttribute); var val1 = TypeReflections.GetAttributesRequired(type, four); val1.ShouldNotBeEmpty(); val1.Count().ShouldBe(1); Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, one)); Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, two)); Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, three)); var val2 = TypeReflections.GetAttributesRequired(type, one, ReflectionOptions.Inherit); var val3 = TypeReflections.GetAttributesRequired(type, three, ReflectionOptions.Inherit); val2.ShouldNotBeEmpty(); val3.ShouldNotBeEmpty(); val2.Count().ShouldBe(2); val3.Count().ShouldBe(1); Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, two, ReflectionOptions.Inherit)); }
public void GenericTypeGettingRequiredAttributesTest() { var type = typeof(NormalWithAttrClass); var val1 = TypeReflections.GetAttributesRequired <ModelOneAttribute>(type); var val3 = TypeReflections.GetAttributesRequired <ModelThreeAttribute>(type); val1.ShouldNotBeEmpty(); val3.ShouldNotBeEmpty(); val1.Count().ShouldBe(2); val3.Count().ShouldBe(1); Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired <ModelTwoAttribute>(type)); }