public void GetItemsTest() { var dataSource = new OpdsData() { Data = new[] { MockupNamingDataSource.GetDetailedItems() } }; var item = mockSource.GetItems(dataSource).Items.Single().Value; Assert.IsNotNull(item); Assert.AreEqual(new DateTime(2012, 1, 1), item.LastUpdatedTime.DateTime); Assert.AreEqual(2, item.Links.Count); Assert.IsInstanceOfType(item.Links.First(), typeof(OpdsLink)); foreach (var link in item.Links) { if (link.RelationshipType != null && link.RelationshipType == OpdsRelations.OpenAcquisition) { Assert.AreEqual("application/epub+zip", link.MediaType); } } Assert.AreEqual("CNY", (item.Links.First() as OpdsLink).Prices.Single().CurrencyCode); Assert.AreEqual(5M, (item.Links.First() as OpdsLink).Prices.Single().Price); Assert.AreEqual(new DataEntry().ISBN, (item as OpdsItem).ISBN); // type of ISBN var xml = item.ToXml(); Assert.IsTrue(xml.Contains(":type=\"URI\"")); }
public void TestStartup() { mockSource = TestInitializer.Container.GetExportedValue <IOpdsItemConverter>(); Assert.IsNotNull(mockSource); itemsDataSource = new OpdsData() { Data = MockupNamingDataSource.GetItems() }; }
/// <summary> /// /// </summary> /// <returns></returns> public override OpdsData Process() { var id = Id ?? String.Empty; var root = Path.Combine(RootFolder, id); var items = new List <object>(); var result = new OpdsData() { Data = items }; if (!Directory.Exists(root)) { throw new ArgumentException("id"); } foreach (var path in Directory.GetFiles(root)) { if (OpdsHelper.IsFileSupported(path)) { // Path will be used as Id. var item = GetFileOpdsInfo(path, Path.Combine(id, Path.GetFileName(path))); items.Add(item); } } foreach (var path in Directory.GetDirectories(root)) { var directoryInfo = new DirectoryInfo(path); items.Add(new { Id = Path.Combine(id, Path.GetFileName(path)), Title = directoryInfo.Name, UpdateTime = directoryInfo.LastWriteTime, OpdsDataType = OpdsDataType.Category, }); } return(result); }
/// <summary> /// 处理文件搜索请求 /// </summary> /// <returns></returns> public override OpdsData Process() { var id = Id ?? String.Empty; var root = Path.Combine(RootFolder, id); var items = new List <object>(); var result = new OpdsData() { Data = items }; foreach (var file in Directory.GetFiles(root, KeyWord, SearchOption.AllDirectories)) { if (OpdsHelper.IsFileSupported(file)) { // Path will be used as Id. var item = GetFileOpdsInfo(file, Path.Combine(id, Path.GetFileName(file))); items.Add(item); } } return(result); }