public void WriteData() { var storage = new XmlStorage(_driver, _index); Assert.Throws <ArgumentNullException>(() => storage.Write <DataInfo>(null, "as")); Assert.Throws <ArgumentException>(() => storage.Write <DataInfo>(_info, "")); _driver.GetRandomName().Returns(TestFileName); _driver.Write(Arg.Any <string>()).Returns(x => new MemoryStream()); Assert.DoesNotThrow(() => storage.Write(_info, _info.Url)); _driver.Received(1).Write(Arg.Is(TestFileName)); _index.Received(1).Add(Arg.Any <StorageItem>()); }
public void Count() { _driver.GetRandomName().Returns(TestFileName); _driver.Write(Arg.Any <string>()).Returns(x => new MemoryStream()); var storage = new XmlStorage(_driver, new XmlStorageIndex(_driver)); Assert.DoesNotThrow(() => storage.Count()); Assert.AreEqual(0, storage.Count()); storage.Write(_info, _info.Url); Assert.AreEqual(1, storage.Count()); }
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)); }