Esempio n. 1
0
 public void SetUp()
 {
     clockSources  = new LazyPool <BaseClockSource>(() => new BaseClockSource());
     machines      = new LazyPool <Machine>(() => new Machine());
     syncDomain    = new SynchronizationDomain();
     temporaryFile = new Lazy <string>(Path.GetTempFileName);
 }
Esempio n. 2
0
        public static void Take_Inner_Returns_Null()
        {
            // Arrange
            var mockInnerPool = new Mock <IPool <string> >(MockBehavior.Strict);

            mockInnerPool.Setup(inner => inner.Name).Returns("Mock");
            mockInnerPool.Setup(inner => inner.Take("state")).Returns((string)null);
            var decoratedPool = new LazyPool <string>(mockInnerPool.Object, state =>
            {
                Assert.Equal("state", (string)state);
                return("x");
            }, ReleaseFactory);

            // Act
            var result = decoratedPool.Take("state");

            // Assert
            Assert.Equal("x", result);
        }
Esempio n. 3
0
        public void TestPoolingLazyAndFifo()
        {
            // FIX: Reset global count due other tests running before
            Foo.GlobalCount = 0;

            using (var pool = new LazyPool <Foo>(PoolSize, p => new Foo(p))) {
                // All objects should be lazy loaded
                Assert.True(Foo.GlobalCount == 0);
                Assert.True(pool.LazyLoadedItemCount == 0);

                // Fetch 2 objects
                var foo  = pool.Acquire();
                var foo2 = pool.Acquire();
                // They should be initialized
                Assert.True(Foo.GlobalCount == 2);
                Assert.True(pool.LazyLoadedItemCount == 2);
                Assert.True(foo != null);
                Assert.True(foo2 != null);

                // Release them
                foo.Dispose();
                foo2.Dispose();
            }
        }
Esempio n. 4
0
        public void TestPoolingLazyAndFifo()
        {
            // FIX: Reset global count due other tests running before
            Foo.GlobalCount = 0;

            using (var pool = new LazyPool<Foo>(PoolSize, p => new Foo(p))) {
                // All objects should be lazy loaded
                Assert.True(Foo.GlobalCount == 0);
                Assert.True(pool.LazyLoadedItemCount == 0);

                // Fetch 2 objects
                var foo = pool.Acquire();
                var foo2 = pool.Acquire();
                // They should be initialized
                Assert.True(Foo.GlobalCount == 2);
                Assert.True(pool.LazyLoadedItemCount == 2);
                Assert.True(foo != null);
                Assert.True(foo2 != null);

                // Release them
                foo.Dispose();
                foo2.Dispose();
            }
        }
Esempio n. 5
0
 public void SetUp()
 {
     clockSources = new LazyPool<BaseClockSource>(() => new BaseClockSource());
     machines = new LazyPool<Machine>(() => new Machine());
     syncDomain = new SynchronizationDomain();
     temporaryFile = new Lazy<string>(Path.GetTempFileName);
 }
Esempio n. 6
0
 public LazyPoolTest()
 {
     DecoratedPool = new LazyPool <string>(MockInnerPool.Object, CreateFactory, ReleaseFactory);
 }