Пример #1
0
        public async Task QueueProcessorTest_QueueInput_Counter_NoCache()
        {
            var provider = new ServiceCollection()
                           .AddMemoryCache()
                           .BuildServiceProvider();
            var memoryCache = provider.GetService <IMemoryCache>();

            var diskWatcherBackgroundTaskQueue = new FakeDiskWatcherUpdateBackgroundTaskQueue();

            Task <List <FileIndexItem> > Local(Tuple <string, string, WatcherChangeTypes> value)
            {
                return(Task.FromResult(new List <FileIndexItem>()));
            }

            var queueProcessor = new QueueProcessor(diskWatcherBackgroundTaskQueue, Local, memoryCache, TimeSpan.FromMilliseconds(1));

            // Run 3 times & 1 time different
            queueProcessor.QueueInput("t", "T", WatcherChangeTypes.All);
            await Task.Delay(TimeSpan.FromMilliseconds(2));             // Sleep async

            queueProcessor.QueueInput("t", "T", WatcherChangeTypes.All);

            Assert.AreEqual(2, diskWatcherBackgroundTaskQueue.QueueBackgroundWorkItemCalledCounter);
        }
Пример #2
0
        public void QueueProcessorTest_QueueInput()
        {
            var diskWatcherBackgroundTaskQueue = new FakeDiskWatcherUpdateBackgroundTaskQueue();

            Task <List <FileIndexItem> > Local(Tuple <string, string, WatcherChangeTypes> value)
            {
                return(Task.FromResult(new List <FileIndexItem>()));
            }

            var memoryCache    = new FakeMemoryCache();
            var queueProcessor = new QueueProcessor(diskWatcherBackgroundTaskQueue, Local, memoryCache, TimeSpan.FromSeconds(5));

            queueProcessor.QueueInput("t", "T", WatcherChangeTypes.All);
            Assert.IsTrue(diskWatcherBackgroundTaskQueue.QueueBackgroundWorkItemCalled);
        }