tests/DotNetCommon.Test/Extensions/TypeExtensions/GettingAllPropertiesWithAttributes.cs

(完整代码) 1KB

namespace DotNetCommon.Test.Extensions.TypeExtensions
{
    using System.Linq;
    using System.Reflection;
    using NUnit.Framework;
    using Shouldly;

    [TestFixture]
    public sealed class GettingAllPropertiesWithAttributes : Context
    {
        [OneTimeSetUp]
        public void SetUp()
        {
            When_getting_properties_with_specific_attribute_for_type<SampleChild, MyAttribute>(true);
        }

        [Test]
        public void Then_property_infos_should_not_be_null_or_empty()
        {
            PropertesWithAttribute.ShouldNotBeNull();
            PropertesWithAttribute.ShouldNotBeEmpty();
        }

        [Test]
        public void Then_property_infos_should_have_correct_count()
        {
            PropertesWithAttribute.Count().ShouldBe(3);
        }

        [Test]
        public void Then_correct_attributes_should_have_been_returned()
        {
            PropertesWithAttribute.Single(p => p.Name.Equals("ParentId"))
                .GetCustomAttribute<MyAttribute>()
                .Name.ShouldBe("_parentId");
            
            PropertesWithAttribute.Single(p => p.Name.Equals("ChildId"))
                .GetCustomAttribute<MyAttribute>()
                .Name.ShouldBe("_childId");
            
            PropertesWithAttribute.Single(p => p.Name.Equals("ChildAge"))
                .GetCustomAttribute<MyAttribute>()
                .Name.ShouldBe("_childAge");
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。