public void GetIndexNotExist() { _driver.Exists(Arg.Is(XmlStorageIndex.IndexName)).Returns(false); var x = new XmlStorageIndex(_driver); Assert.AreEqual(x.Count(), 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 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)); }
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>() }); }
public bool Exists(string name) { return(_driver.Exists(GetNameWithExtention(name))); }