diff --git a/src/BloomExe/Book/Book.cs b/src/BloomExe/Book/Book.cs index 31029593cd8a..dd39aa8c1704 100644 --- a/src/BloomExe/Book/Book.cs +++ b/src/BloomExe/Book/Book.cs @@ -84,10 +84,19 @@ public class Book /// public bool WriteFontFaces = true; - //for moq'ing only; parameterless ctor required by Moq + // For moq'ing only; parameterless ctor required by Moq. public Book() + : this(false) { - Guard.Against(!Program.RunningUnitTests, "Only use this ctor for tests!"); + } + + // Allow specific subclasses (like ErrorBook) to bypass the unit-test guard. + protected Book(bool allowNonTestCtor) + { + if (!allowNonTestCtor) + { + Guard.Against(!Program.RunningUnitTests, "Only use this ctor for tests!"); + } } public Book(BookInfo info = null, IBookStorage storage = null) diff --git a/src/BloomExe/Book/ErrorBook.cs b/src/BloomExe/Book/ErrorBook.cs index ec2744156add..513b3d6cdde8 100644 --- a/src/BloomExe/Book/ErrorBook.cs +++ b/src/BloomExe/Book/ErrorBook.cs @@ -14,14 +14,12 @@ public class ErrorBook : Book private bool _canDelete; /// - /// this is a bit of a hack to handle representing a book for which we got an exception while loading the storage... a better architecture wouldn't have this... + /// This is a bit of a hack to handle representing a book for which we got an exception while loading the storage. + /// A better architecture wouldn't have this. /// public ErrorBook(Exception exception, string folderPath, bool canDelete) + : base(true) { - // ENHANCE: Address that a Guard fails when this constructor is called. - // This class inherits from Book. So it calls Book's default constructor here. - // But Book's default constructor has a Guard that says it's only supposed to be called from the unit tests. - // One potential route is to create an interface... IBook or ISimpleBook Exception = exception; _folderPath = folderPath; _canDelete = canDelete;