tests/DotNetCommon.Test/Accessors/AccessorPropertyTests.cs

(开头部分) 8KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

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

    [TestFixture]
    public class AccessorPropertyTests
    {
        [Test]
        public void When_checking_invalid_input()
        {
            string nullStr = null;
            PropertyInfo nullPropInfo = null;

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildSetter<Person, string>(nullStr))
                .Message.ShouldBe("String must not be null, empty or whitespace.");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildSetter<Person, string>(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildGetter<Person, string>(nullStr))
                .Message.ShouldBe("String must not be null, empty or whitespace.");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildGetter<Person, string>(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildSetter<Person>(nullStr))
                .Message.ShouldBe("String must not be null, empty or whitespace.");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildSetter<Person>(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildGetter<Person>(nullStr))
                .Message.ShouldBe("String must not be null, empty or whitespace.");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildGetter<Person>(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildSetter(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");

            Should.Throw<ArgumentException>(() => AccessorBuilder.BuildGetter(nullPropInfo))
                .Message.ShouldBe("Value cannot be null. (Parameter 'propertyInfo')");
        }

        [Test]
        public void When_getting_getters_class()
        {
            var nameGetterOne = AccessorBuilder.BuildGetter<Person, string>("Name");
            var nameGetterTwo = AccessorBuilder.BuildGetter<Person, string>("Name");

            nameGetterOne.ShouldNotBeSameAs(nameGetterTwo);

            var jobGetter = AccessorBuilder.BuildGetter<Person, string>("Job", true);

            jobGetter.ShouldNotBe(nameGetterOne);
后面还有 196 行代码,解锁后查看完整代码

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

AI 解读

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

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