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 void ReadFileNotIndexed() { var storage = new XmlStorage(_driver, new XmlStorageIndex(_driver)); Assert.DoesNotThrow(() => storage.Read <DataInfo>(TestFileName)); _driver.DidNotReceive().Read(Arg.Is(TestFileName)); }
public void ReadFile() { _driver.GetRandomName().Returns(TestFileName); _driver.Write(Arg.Is(TestFileName)).Returns(ux => File.Create(TestFileName)); var storage = new XmlStorage(_driver, _index); storage.Write(_info, _info.Url); _driver.Exists(Arg.Is(TestFileName)).Returns(true); _index.Get(Arg.Is <StorageItem>(item => item.FileName == TestFileName)).Returns(new StorageItem() { FileName = TestFileName }); _driver.Read(Arg.Is(TestFileName)).Returns(ux => File.OpenRead(TestFileName)); Assert.DoesNotThrow(() => storage.Read <DataInfo>(TestFileName)); Assert.IsNotNull(storage.Read <DataInfo>(TestFileName)); _driver.Received(2).Read(Arg.Is(TestFileName)); }
public void ReadFileCorrupted() { _index.Get(Arg.Is <StorageItem>(item => item.FileName == TestFileName)).Returns(new StorageItem() { FileName = TestFileName }); _driver.Exists(Arg.Is(TestFileName)).Returns(true); _driver.Read(Arg.Any <string>()).Returns(x => new MemoryStream()); var storage = new XmlStorage(_driver, _index); Assert.Throws <SerializationException>(() => storage.Read <DataInfo>(TestFileName)); }
public void ReadFileArgs() { var storage = new XmlStorage(_driver, new XmlStorageIndex(_driver)); Assert.Throws <ArgumentException>(() => storage.Read <DataInfo>("")); }