예제 #1
0
        public void DeserializeCache_FromSerializedCache_CacheIsCorrect()
        {
            //Arrange
            List <FileSystemItem> items = new List <FileSystemItem>
            {
                new FileSystemItem("name1", "folder1"),
                new FileSystemItem("C:\\")
            };
            DateTime        dateTime = DateTime.Now;
            FileSystemCache cache    = new FileSystemCache(items, dateTime);

            _serializer.SerializeCache(cache);

            //Act
            FileSystemCache actualCache = _serializer.DeserializeCache();

            //Assert
            //Serialization does not preserve milliseconds, so we use epsilon check.
            Assert.That(dateTime - actualCache.LastFullScanTime, Is.LessThan(new TimeSpan(0, 0, 1)));
            Assert.That(actualCache.Items.Count, Is.EqualTo(2));

            Assert.That(actualCache.Items[0].FullPath, Is.EqualTo(Path.GetFullPath("folder1")));
            Assert.That(actualCache.Items[0].Name, Is.EqualTo("name1"));

            Assert.That(actualCache.Items[1].FullPath, Is.EqualTo(Path.GetFullPath("C:\\")));
            Assert.That(actualCache.Items[1].Name, Is.EqualTo(""));
        }
예제 #2
0
        private void HandleParsingFinished(object sender, ItemEventArgs <FileSystemCache> e)
        {
            lock (_cacheSync)
            {
                FileSystemCache fullCache = e.Item;
                fullCache.LastFullScanTime = DateTime.Now;
                _cacheSerializer.SerializeCache(fullCache);

                _lastFullScanTime   = fullCache.LastFullScanTime;
                _filteredCacheItems = FilterCache(fullCache);
                _fileSystemChanges  = new FileSystemChanges();
                fullCache           = null;
                GC.Collect();

                _asyncFileSystemParser.ParsingFinished -= HandleParsingFinished;
            }
        }