Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug with calibre plugin

  • Loading branch information...
commit 1f551714d5b784b79a488b6f3d28bf9d1f383e78 1 parent 67c0a95
@brunomlopes authored
View
2  src/Plugins.Calibre/BookConverter.cs
@@ -14,7 +14,7 @@ public IItem FromDocumentToItem(CoreDocument document)
book.Title = document.GetString("title");
book.Authors = document.GetString("authors");
book.Id = int.Parse(document.GetString("id"));
- book.Formats.AddRange(document.GetStringList("formats"));
+ book.Formats.AddRange(document.GetStringList("format"));
return book;
}
View
20 src/Plugins.Calibre/TestItemSource.cs → src/Plugins.Calibre/Tests/MockLog.cs
@@ -1,26 +1,8 @@
using System;
using Core.Abstractions;
-using Xunit;
-using System.Linq;
-namespace Plugins.Calibre
+namespace Plugins.Calibre.Tests
{
- public class TestItemSource
- {
- [Fact]
- public void CanReturnBooksInMyPc()
- {
- var source = new CalibreBookSource();
- source.Log = new MockLog();
-
- source.Config = new Configuration();
-
- var items = source.GetItems().Result.ToList();
- Assert.NotEqual(0, items.Count);
- }
-
- }
-
internal class MockLog : ILog
{
public void Info(string format, params object[] args)
View
32 src/Plugins.Calibre/Tests/TestBookConverter.cs
@@ -0,0 +1,32 @@
+using Xunit;
+
+namespace Plugins.Calibre.Tests
+{
+ public class TestBookConverter
+ {
+ [Fact]
+ public void CanConvertABookBackAndForth()
+ {
+
+ var book = new Book()
+ {
+ Authors = "Authors",
+ Id = 42,
+ Title = "Title"
+ };
+
+ book.Formats.Add("This is a format");
+ book.Formats.Add("another.format");
+
+ var bookConverter = new BookConverter();
+ var coreDoc = bookConverter.ToDocument(new CalibreBookSource(), book);
+
+ var convertedBook = (Book)bookConverter.FromDocumentToItem(coreDoc);
+ Assert.Equal(book.Authors, convertedBook.Authors);
+ Assert.Equal(book.Title, convertedBook.Title);
+ Assert.Equal(book.Id, convertedBook.Id);
+ Assert.Equal(book.Formats, convertedBook.Formats);
+ }
+
+ }
+}
View
79 src/Plugins.Calibre/Tests/TestItemSource.cs
@@ -0,0 +1,79 @@
+using System;
+using Core.Abstractions;
+using Xunit;
+using System.Linq;
+
+namespace Plugins.Calibre
+{
+ public class TestItemSource
+ {
+ [Fact]
+ public void CanReturnBooksInMyPc()
+ {
+ var source = new CalibreBookSource();
+ source.Log = new MockLog();
+
+ source.Config = new Configuration();
+
+ var items = source.GetItems().Result.ToList();
+ Assert.NotEqual(0, items.Count);
+ }
+
+ }
+
+ public class TestBookConverter
+ {
+ [Fact]
+ public void CanConvertABookBackAndForth()
+ {
+
+ var book = new Book()
+ {
+ Authors = "Authors",
+ Id = 42,
+ Title = "Title"
+ };
+
+ book.Formats.Add("This is a format");
+ book.Formats.Add("another.format");
+
+ var bookConverter = new BookConverter();
+ var coreDoc = bookConverter.ToDocument(new CalibreBookSource(), book);
+
+ var convertedBook = (Book)bookConverter.FromDocumentToItem(coreDoc);
+ Assert.Equal(book.Authors, convertedBook.Authors);
+ Assert.Equal(book.Title, convertedBook.Title);
+ Assert.Equal(book.Id, convertedBook.Id);
+ Assert.Equal(book.Formats, convertedBook.Formats);
+ }
+
+ }
+
+ internal class MockLog : ILog
+ {
+ public void Info(string format, params object[] args)
+ {
+ Debug(format, args);
+ }
+
+ public void Warn(string format, params object[] args)
+ {
+ Debug(format, args);
+ }
+
+ public void Error(Exception exception)
+ {
+ throw exception;
+ }
+
+ public void Error(Exception exception, string format, params object[] args)
+ {
+ throw exception;
+ }
+
+ public void Debug(string format, params object[] args)
+ {
+ System.Diagnostics.Debug.WriteLine(format, args);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.