tests/DotNetCommon.Test/EasyPool/EasyPoolTests.cs

(开头部分) 7KB

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

namespace DotNetCommon.Test.EasyPool
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using NUnit.Framework;
    using Shouldly;

    [TestFixture]
    internal sealed class EasyPoolTests
    {
        [Test]
        public void When_creating_a_pool_with_null_factory()
        {
            var ex = Should.Throw<ArgumentNullException>(() => new EasyPool<string>(null, null, 10));
            ex.Message.ShouldBe("Value cannot be null. (Parameter 'factory')");
            ex.ParamName.ShouldBe("factory");
        }

        [Test]
        public void When_returning_more_than_max_pool_size()
        {
            Func<SomeObject> factory = () => new SomeObject();
            const int MaxCount = 1;
            using (IEasyPool<SomeObject> pool = new EasyPool<SomeObject>(factory, null, MaxCount))
            {
                pool.Count.ShouldBe(0);

                var obj1 = new SomeObject();

                pool.Return(obj1).ShouldBeTrue();

                pool.Count.ShouldBe(1);

                var obj2 = new SomeObject();

                pool.Return(obj2).ShouldBeFalse();

                pool.Count.ShouldBe(1);

                var pooledObj = pool.Get();
                pooledObj.ShouldBe(obj1);

                pool.Count.ShouldBe(0);
            }
        }

        [Test]
        public void When_getting_and_renting_items_from_the_pool_with_null_reset()
        {
            Func<SomeObject> factory = () => new SomeObject { Name = "Foo", Number = 1 };

            using (IEasyPool<SomeObject> pool = new EasyPool<SomeObject>(factory, null, 5))
            {
                pool.Count.ShouldBe(0);

                var obj1 = pool.Get();

                obj1.ShouldNotBeNull();
                obj1.Name.ShouldBe("Foo");
后面还有 172 行代码,解锁后查看完整代码

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

AI 解读

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

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