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

(开头部分) 5KB

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

namespace DotNetCommon.Test.Extensions.TypeExtensions
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using NUnit.Framework;
    using Shouldly;
    using DotNetCommon.Extensions;

    [TestFixture]
    public sealed class GettingArgumentTypeOfGenericTypeTests
    {
        [Test]
        public void When_checking_type_of_null()
        {
            Type[] result;

            var e = Should.Throw<ArgumentNullException>(() =>
            {
                ((Type) null).TryGetGenericArguments(out result);
            });

            e.Message.ShouldBe("Value cannot be null. (Parameter 'type')");
            e.ParamName.ShouldBe("type");
        }

        [Test]
        public void When_checking_type_of_non_generic_class()
        {
            Type[] result;
            typeof(NonGenericType)
                .TryGetGenericArguments(out result)
                .ShouldBeFalse();

            result.ShouldBeNull();
        }

        [Test]
        public void When_checking_type_of_generic_class_with_single_argument()
        {
            Type[] result;
            typeof(SingleGenericType<string>)
                .TryGetGenericArguments(out result)
                .ShouldBeTrue();

            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
            result[0].ShouldBe(typeof(string));
        }

        [Test]
        public void When_checking_type_of_generic_class_with_double_arguments()
        {
            Type[] result;
            typeof(DoubleGenericType<int, string>)
                .TryGetGenericArguments(out result)
                .ShouldBeTrue();

            result.ShouldNotBeNull();
            result.Length.ShouldBe(2);
后面还有 130 行代码,解锁后查看完整代码

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

AI 解读

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

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