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_SingleTablesSingleQuery() { var dataLoaderMock = new FakeDataLoader(); var storeProxy = CreateFakeStoreProxy(); ITableDataLoaderFactory factory = new CachingTableDataLoaderFactory(dataLoaderMock, null, storeProxy); // First call var table = new TableDescription("table", Enumerable.Empty <ColumnDescription>()); factory.CreateTableDataLoader(table); // Second call (should return the ITableDataLoader from cache) factory.CreateTableDataLoader(table); Assert.AreEqual(1, dataLoaderMock.CreateTableDataLoaderCallCount); Assert.AreEqual(1, storeProxy.CachedItemReturnCount); }
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); }
public void CachingDataLoaderFactory_MoreTablesMoreQuery() { var dataLoaderMock = new FakeDataLoader(); var storeProxy = CreateFakeStoreProxy(); ITableDataLoaderFactory factory = new CachingTableDataLoaderFactory(dataLoaderMock, null, storeProxy); // First call var table1 = new TableDescription("table1", Enumerable.Empty <ColumnDescription>()); factory.CreateTableDataLoader(table1); // Second call (another table, the cache should not be used) var table2 = new TableDescription("table2", Enumerable.Empty <ColumnDescription>()); factory.CreateTableDataLoader(table2); Assert.AreEqual(2, dataLoaderMock.CreateTableDataLoaderCallCount); Assert.AreEqual(0, storeProxy.CachedItemReturnCount); }