コード例 #1
0
ファイル: TestArrayPool.cs プロジェクト: UniDi/UniDi
        public void RunTest()
        {
            var pool = ArrayPool <string> .GetPool(2);

            pool.Clear();
            pool.ClearActiveCount();

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 0);

            var arr1 = pool.Spawn();

            Assert.IsEqual(arr1.Length, 2);

            arr1[0] = "asdf";
            arr1[1] = "zbx";

            Assert.IsEqual(pool.NumActive, 1);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 1);

            pool.Despawn(arr1);

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 1);
            Assert.IsEqual(pool.NumTotal, 1);

            var arr2 = pool.Spawn();

            Assert.IsEqual(arr2.Length, 2);
            Assert.IsNull(arr2[0]);
            Assert.IsNull(arr2[1]);

            Assert.IsEqual(arr2.Length, 2);
            Assert.IsEqual(arr2, arr1);

            Assert.IsEqual(pool.NumActive, 1);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 1);

            var arr3 = pool.Spawn();

            Assert.IsNotEqual(arr2, arr3);

            Assert.IsEqual(pool.NumActive, 2);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 2);

            pool.Despawn(arr3);
            pool.Despawn(arr2);

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 2);
            Assert.IsEqual(pool.NumTotal, 2);

            Assert.Throws(() => pool.Despawn(arr3));
        }
コード例 #2
0
        public void TestAllInterfaces()
        {
            Container.BindInterfacesTo <Foo>().AsSingle().NonLazy();

            Assert.IsNull(Container.TryResolve <Foo>());

            Assert.IsNotNull(Container.Resolve <IFoo>());
            Assert.IsNotNull(Container.Resolve <IQux>());
        }
コード例 #3
0
 public void Init(
     Test0 test0,
     [InjectOptional]
     Test2 test2)
 {
     Assert.That(!HasInitialized);
     Assert.IsNotNull(test1);
     Assert.IsNull(test2);
     Assert.IsNull(this.test0);
     this.test0     = test0;
     HasInitialized = true;
 }
コード例 #4
0
ファイル: TestStaticMemoryPool.cs プロジェクト: UniDi/UniDi
        public void RunTest()
        {
            var pool = Foo.Pool;

            pool.Clear();
            pool.ClearActiveCount();

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 0);

            var foo = pool.Spawn("asdf");

            Assert.IsEqual(pool.NumActive, 1);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 1);

            Assert.IsEqual(foo.Value, "asdf");
            pool.Despawn(foo);
            Assert.IsNull(foo.Value);

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 1);
            Assert.IsEqual(pool.NumTotal, 1);

            var foo2 = pool.Spawn("zxcv");

            Assert.That(ReferenceEquals(foo, foo2));
            Assert.IsEqual(foo2.Value, "zxcv");

            Assert.IsEqual(pool.NumActive, 1);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 1);

            var foo3 = pool.Spawn("bar");

            Assert.That(!ReferenceEquals(foo2, foo3));

            Assert.IsEqual(pool.NumActive, 2);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 2);

            pool.Despawn(foo3);
            pool.Despawn(foo2);

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 2);
            Assert.IsEqual(pool.NumTotal, 2);

            Assert.Throws(() => pool.Despawn(foo3));
        }
コード例 #5
0
ファイル: TestAllInjectionTypes.cs プロジェクト: UniDi/UniDi
            public void PostInjectBase()
            {
                Assert.IsNull(BaseStaticFieldPublic);
                Assert.IsNull(BaseStaticFieldPrivate);
                Assert.IsNull(BaseStaticFieldProtected);
                Assert.IsNull(BaseStaticPropertyPublic);
                Assert.IsNull(BaseStaticPropertyPrivate);
                Assert.IsNull(BaseStaticPropertyProtected);

                Assert.IsNotNull(BaseFieldPublic);
                Assert.IsNotNull(BaseFieldPrivate);
                Assert.IsNotNull(BaseFieldProtected);
                Assert.IsNotNull(BasePropertyPublic);
                Assert.IsNotNull(BasePropertyPrivate);
                Assert.IsNotNull(BasePropertyProtected);

                BaseTypeMethodInjectCount = InjectCounter++;

                _didPostInjectBase = true;
            }
コード例 #6
0
ファイル: TestAllInjectionTypes.cs プロジェクト: UniDi/UniDi
            public void PostInject()
            {
                Assert.IsNull(DerivedStaticFieldPublic);
                Assert.IsNull(DerivedStaticFieldPrivate);
                Assert.IsNull(DerivedStaticFieldProtected);
                Assert.IsNull(DerivedStaticPropertyPublic);
                Assert.IsNull(DerivedStaticPropertyPrivate);
                Assert.IsNull(DerivedStaticPropertyProtected);

                Assert.IsNotNull(DerivedFieldPublic);
                Assert.IsNotNull(DerivedFieldPrivate);
                Assert.IsNotNull(DerivedFieldProtected);
                Assert.IsNotNull(DerivedPropertyPublic);
                Assert.IsNotNull(DerivedPropertyPrivate);
                Assert.IsNotNull(DerivedPropertyProtected);
                Assert.IsNotNull(ConstructorParam);

                _derivedTypeMethodInjectCount = InjectCounter++;

                _didPostInject = true;
            }
コード例 #7
0
ファイル: TestLazy.cs プロジェクト: UniDi/UniDi
        public void TestOptional2()
        {
            Container.Bind <Qux>().AsSingle();

            Assert.IsNull(Container.Resolve <Qux>().Bar.Value);
        }