Пример #1
0
 private T Read <T>(StorageItem item) where T : class
 {
     item = _index.Get(item);
     if (item != null && _driver.Exists(item.FileName))
     {
         return(BinarySerealizer.Load <T>(_driver.Read(item.FileName)));
     }
     return(null);
 }
        public void GetIndexExist(StorageItem[] items)
        {
            _driver.Exists(Arg.Is(XmlStorageIndex.IndexName)).Returns(false);

            var ind = new XmlStorageIndex(_driver);

            foreach (var storageItem in items)
            {
                ind.Add(storageItem);
            }
            ind.Save();

            _driver.Exists(Arg.Is(XmlStorageIndex.IndexName)).Returns(true);
            _driver.Read(Arg.Is(XmlStorageIndex.IndexName)).Returns(ux => File.OpenRead(XmlStorageIndex.IndexName));

            var x = new XmlStorageIndex(_driver);

            Assert.AreEqual(x.Count(), items.Length);
            Assert.DoesNotThrow(x.Save);
        }
Пример #3
0
        private static StorageIndex GetIndex(IStorageDriver driver)
        {
            StorageIndex result = null;

            if (driver.Exists(IndexName))
            {
                try
                {
                    result = XmlClassSerializer.Load <StorageIndex>(driver.Read(IndexName));
                }
                catch (Exception)
                {
                    //TODO: log exception
                }
            }
            return(result ?? new StorageIndex {
                Items = new List <StorageItem>()
            });
        }
Пример #4
0
        public void ReadFileNotExist()
        {
            _index.Get(Arg.Any <StorageItem>()).Returns(new StorageItem()
            {
                FileName = TestFileName
            });
            _driver.Exists(Arg.Is(TestFileName)).Returns(true);
            _driver.Read(Arg.Any <string>()).Returns(x => Stream.Null);

            var storage = new XmlStorage(_driver, _index);

            Assert.DoesNotThrow(() => storage.Read <DataInfo>(TestFileName));
            Assert.IsNull(storage.Read <DataInfo>(TestFileName));

            _driver.Received(2).Read(Arg.Is(TestFileName));
        }
 public Stream Read(string name)
 {
     return(_driver.Read(GetNameWithExtention(name)));
 }