public void CachingDataLoaderFactory_InvokesLatch()
        {
            var latchMock = new DataLoaderConfigurationLatchMock();
            var dataLoaderStub = new FakeDataLoader();
            var table = new TableDescription("table", Enumerable.Empty<ColumnDescription>());
            var storeProxy = CreateFakeStoreProxy();

            ITableDataLoaderFactory factory =
                new CachingTableDataLoaderFactory(dataLoaderStub, latchMock, storeProxy);

            // The latch should not have been invoked yet
            Assert.AreEqual(0, latchMock.AcquireCallCount);
            Assert.AreEqual(0, latchMock.ReleaseCallCount);

            using (factory)
            {
                // This invocation should make the factory using the latch
                factory.CreateTableDataLoader(table);

                // The latch should have been acquired
                Assert.AreEqual(1, latchMock.AcquireCallCount);
                Assert.AreEqual(0, latchMock.ReleaseCallCount);
            }

            // The latch should have been released
            Assert.AreEqual(1, latchMock.AcquireCallCount);
            Assert.AreEqual(1, latchMock.ReleaseCallCount);
        }
        public void CachingDataLoaderFactory_IgnoresLatch()
        {
            var latchMock = new DataLoaderConfigurationLatchMock();
            var stub = new FakeDataLoader();
            var storeProxy = CreateFakeStoreProxy();
            var table = new TableDescription("table", Enumerable.Empty<ColumnDescription>());

            ITableDataLoaderFactory factory =
                new CachingTableDataLoaderFactory(stub, latchMock, storeProxy);

            using (factory)
            {
                // The CreateTableDataLoader is not invoked
            }

            // The latch should not have been invoked
            Assert.AreEqual(0, latchMock.AcquireCallCount);
        }
        public void CachingDataLoaderFactory_ReturnsSameData()
        {
            var latchMock = new DataLoaderConfigurationLatchMock();
            var stub = new FakeDataLoader();
            var storeProxy = CreateFakeStoreProxy();
            var table = new TableDescription("table", Enumerable.Empty<ColumnDescription>());

            CachingTableDataLoaderFactory factory =
                new CachingTableDataLoaderFactory(stub, latchMock, storeProxy);

            var data1 = factory.CreateTableDataLoader(table).GetData();

            var data2 = factory.CreateTableDataLoader(table).GetData();

            Enumerable.SequenceEqual(data1, data2);

            // The returned datasets should be exactly the same (same reference)
            Assert.AreEqual(data1, data2);
        }