public void TestThatPropertyWithoutMatchingAttributesYieldsNoAttributes() { var property = typeof(TestClassWithAttributes).GetTypeInfo().GetMember(nameof(TestClassWithAttributes.Foo))[0]; AttributeUtilities.GetAttributes <ArgumentSetAttribute>(property).Should().BeEmpty(); AttributeUtilities.GetAttributesForReflectionOnlyType <ArgumentSetAttribute>(property).Should().BeEmpty(); }
public void TestThatPropertyWithNoAttributesYieldsNoAttributes() { var field = this.GetType().GetTypeInfo().GetMember(nameof(PropertyWithNoAttributes))[0]; AttributeUtilities.GetAttributes <Attribute>(field).Should().BeEmpty(); AttributeUtilities.GetAttributesForReflectionOnlyType <Attribute>(field).Should().BeEmpty(); }
public void MethodWithAttributeYieldsAttribute() { var method = this.GetType().GetTypeInfo().GetMember(nameof(MethodWithAttributeYieldsAttribute))[0]; var attribs = AttributeUtilities.GetAttributes <TestMethodAttribute>(method).ToList(); attribs.Should().HaveCount(1); attribs[0].Should().BeOfType <TestMethodAttribute>(); }
public void CannotRetrieveAttributeFromNonMemberProviderThatFailsToReturnCustomAttribs() { var fooProp = typeof(TestClassWithAttributes).GetTypeInfo().GetProperty(nameof(TestClassWithAttributes.Foo)); fooProp.Should().NotBeNull(); var provider = Substitute.For <ICustomAttributeProvider>(); provider.GetCustomAttributes(Arg.Any <Type>(), Arg.Any <bool>()) .ReturnsForAnyArgs(call => { throw new InvalidOperationException(); }); Action a = () => AttributeUtilities.GetAttributes <NamedArgumentAttribute>(provider).ToList(); a.ShouldThrow <InvalidOperationException>(); }
public void TestThatMethodWithAttributeYieldsAttribute() { var method = this.GetType().GetTypeInfo().GetMember(nameof(TestThatMethodWithAttributeYieldsAttribute))[0]; var attribsResults = new[] { AttributeUtilities.GetAttributes <TestMethodAttribute>(method).ToList(), AttributeUtilities.GetAttributesForReflectionOnlyType <TestMethodAttribute>(method).ToList(), }; foreach (var attribs in attribsResults) { attribs.Should().ContainSingle(); attribs[0].Should().BeOfType <TestMethodAttribute>(); } }
public void CanRetrieveAttributeFromProviderThatFailsToReturnCustomAttribs() { var fooProp = typeof(TestClassWithAttributes).GetTypeInfo().GetProperty(nameof(TestClassWithAttributes.Foo)); fooProp.Should().NotBeNull(); var provider = Substitute.For <MemberInfo>(); ((ICustomAttributeProvider)provider).GetCustomAttributes(Arg.Any <Type>(), Arg.Any <bool>()) .ReturnsForAnyArgs(call => { throw new InvalidOperationException(); }); provider.CustomAttributes.ReturnsForAnyArgs(fooProp.CustomAttributes); var attribs = AttributeUtilities.GetAttributes <NamedArgumentAttribute>(provider).ToList(); attribs.Should().HaveCount(1); attribs[0].Should().BeOfType <NamedArgumentAttribute>(); attribs[0].LongName.Should().Be("LongerFoo"); }
public void TestThatTypeWithAttributesYieldsAttributes() { var type = typeof(TestClassWithAttributes); var attribsResults = new[] { AttributeUtilities.GetAttributes <ArgumentSetAttribute>(type), AttributeUtilities.GetAttributesForReflectionOnlyType <ArgumentSetAttribute>(type) }; foreach (var attribs in attribsResults) { attribs.Should().HaveCount(1); var attrib = attribs.First(); attrib.Description.Should().Be("Hello"); attrib.Examples.Should().BeEmpty(); } }
public void TestThatPropertyWithAttributesYieldsAttributes() { var property = typeof(TestClassWithAttributes).GetTypeInfo().GetMember(nameof(TestClassWithAttributes.Foo))[0]; var attribsResults = new[] { AttributeUtilities.GetAttributes <NamedArgumentAttribute>(property), AttributeUtilities.GetAttributesForReflectionOnlyType <NamedArgumentAttribute>(property) }; foreach (var attribs in attribsResults) { attribs.Should().HaveCount(1); var attrib = attribs.First(); attrib.Flags.Should().Be(ArgumentFlags.Required); attrib.LongName.Should().Be("LongerFoo"); attrib.ConflictsWith.Should().Equal(new[] { "Bar" }); } }
public void PropertyWithNoAttributesYieldsNoAttributes() { var field = this.GetType().GetTypeInfo().GetMember(nameof(PropertyWithNoAttributes))[0]; AttributeUtilities.GetAttributes <Attribute>(field).Should().BeEmpty(); }