public void TestGetDocumentMetaInfo_on_doc1() { string pdf_filename = MiscTestHelpers.GetNormalizedPathToAnyTestDataTestFile(@"fixtures/1.Doc-Many.Metadata.Formats/0001-LDA-paper/2004.04.PNAS.ef997ae1b01762b57b75d8c22fb8cec87406.pdf"); ASSERT.FileExists(pdf_filename); PDFDocumentMuPDFMetaInfo info = MuPDFRenderer.GetDocumentMetaInfo(pdf_filename, null, ProcessPriorityClass.Normal); ASSERT.AreEqual <int>(8, info.PageCount); ASSERT.AreEqual <bool>(false, info.DocumentIsCorrupted); ASSERT.IsLessOrEqual(10000, info.raw_multipurp_text.Length); TestJSONoutputIsCorrectForPDFdoc1(info.raw_decoded_json); object json_doc = JsonConvert.DeserializeObject(info.raw_multipurp_text); string json_text = JsonConvert.SerializeObject(json_doc, Formatting.Indented).Replace("\r\n", "\n"); // Perform comparison via ApprovalTests->BeyondCompare (that's what I use for *decades* now) //ApprovalTests.Approvals.VerifyJson(json_out); --> becomes the code below: ApprovalTests.Approvals.Verify( new QiqqaApprover(json_text, pdf_filename), ApprovalTests.Approvals.GetReporter() ); info.ClearRawContent(); ASSERT.IsNull(info.raw_multipurp_text); ASSERT.IsNull(info.raw_decoded_json); }
public void TestCallAsyncFireAndForget_Completed() { try { // output "hello world" as method returns early ASSERT.AreEqual(ExampleFireAndForgetFunc(() => { Thread.Sleep(100); return(false); // don't throw exception }), "hello world"); } catch { // Exception is NOT caught here ASSERT.Fail("exception should not be caught here"); } ASSERT.IsNull(caught_ex); Thread.Sleep(500); ASSERT.IsNull(caught_ex); ASSERT.IsFalse(faulted, "faulted"); ASSERT.IsTrue(completed, "completed"); ASSERT.IsFalse(canceled, "cancelled"); }
public void SerializeBasicLibrary() { // TODO: overrule DB directory etc by overriding LIBRARY_BASE_PATH et al... // set up a clean library with the default two manual files: WebLibraryDetail new_web_library_detail = new WebLibraryDetail(); new_web_library_detail.Id = "UnitTest"; new_web_library_detail.Title = "Local UnitTest Library"; new_web_library_detail.Description = "This is the library that comes with your Qiqqa unit test(s)."; new_web_library_detail.Deleted = false; new_web_library_detail.Xlibrary = new Library(new_web_library_detail); PDFDocument doc2 = QiqqaManualTools.AddManualsToLibrary(new_web_library_detail); ASSERT.IsNotNull(doc2); ASSERT.AreEqual <int>(new_web_library_detail.Xlibrary.PDFDocuments.Count, 2); string json = JsonConvert.SerializeObject(doc2, Formatting.Indented); // Perform comparison via ApprovalTests->BeyondCompare (that's what I use for *decades* now) string json_out = JsonConvert.SerializeObject(doc2, Formatting.Indented).Replace("\r\n", "\n"); string path = GetNormalizedPathToSerializationTestFile("PDFDocument/SerializeBasicLibrary/Manual-Doc-02-serialized.json"); //ApprovalTests.Approvals.VerifyJson(json_out); --> becomes the code below: ApprovalTests.Approvals.Verify( new QiqqaApprover(json_out, path), ApprovalTests.Approvals.GetReporter() ); //new_web_library_detail.library.Dispose(); ASSERT.IsTrue(true); }
public void TestCallAsyncFireAndForget_Canceled() { try { var cts = new CancellationTokenSource(400); // output "hello world" as method returns early ASSERT.AreEqual(ExampleFireAndForgetFunc(() => { while (!cts.Token.IsCancellationRequested) { Thread.Sleep(20); } cts.Token.ThrowIfCancellationRequested(); return(false); // don't throw exception }), "hello world"); } catch { // Exception is NOT caught here ASSERT.Fail("exception should not be caught here"); } ASSERT.IsNull(caught_ex); Thread.Sleep(500); ASSERT.IsNull(caught_ex); ASSERT.IsFalse(faulted, "faulted"); ASSERT.IsTrue(completed, "completed"); ASSERT.IsTrue(canceled, "cancelled"); }
public void Test_Conversion_To_And_From_BibTeX_Text() { string s1 = TestStringS1; string s2 = BibTexCharacterMap.ASCIIToBibTex(s1); string s3 = BibTexCharacterMap.BibTexToASCII(s2); ASSERT.AreEqual(s1, s3); }
public void TypecastToObjectAllowsNULLCheck() { ASSERT.AreEqual <int>(TypecastToObjectAllowsNULLCheckHelper <int>(5), 3); ASSERT.AreEqual <int>(TypecastToObjectAllowsNULLCheckHelper <string>("help"), 3); ASSERT.AreEqual <int>(TypecastToObjectAllowsNULLCheckHelper <string>(null), -7); int?nullable_int = null; int?nullable_int2 = 4; ASSERT.AreEqual <int>(TypecastToObjectAllowsNULLCheckHelper <int?>(nullable_int), -7); ASSERT.AreEqual <int>(TypecastToObjectAllowsNULLCheckHelper <int?>(nullable_int2), 3); }
// Helper function: these tests should exhibit that the decoded JSON is okay and matched the first PDF document sample private void TestJSONoutputIsCorrectForPDFdoc1(List <MultiPurpDocumentInfoObject> infos_list) { ASSERT.AreEqual <int>(infos_list.Count, 1); var info = infos_list[0]; ASSERT.IsNotNull(info.GlobalInfo); ASSERT.IsNotNull(info.DocumentFilePath); ASSERT.IsNull(info.GatheredErrors); var globalinfo = info.GlobalInfo; ASSERT.AreEqual <int>(1, globalinfo.Chapters.Value); ASSERT.AreEqual <int>(0, globalinfo.DocumentOutlines.Count); ASSERT.AreEqual <int>(4, globalinfo.Info.Count); ASSERT.IsTrue(globalinfo.GatheredErrors.Log.Contains("first object in xref is not free")); ASSERT.AreEqual <string>("PDF-1.3", globalinfo.Version); ASSERT.AreEqual <int>(1, info.PageInfoSeries.Count); var pageSeries = info.PageInfoSeries[0]; ASSERT.AreEqual <string>("AllPages", pageSeries.InfoMode); ASSERT.IsNull(pageSeries.GatheredErrors); ASSERT.IsNotNull(pageSeries.DocumentGeneralInfo); var ginf = pageSeries.DocumentGeneralInfo; ASSERT.AreEqual <string>("PDF 1.3", ginf.Format); ASSERT.AreEqual <bool>(false, ginf.WasRepaired.Value); ASSERT.AreEqual <int>(4, ginf.MetaInfoDictionary.Count); ASSERT.AreEqual <int>(1, pageSeries.PageSequence.Count); MultiPurpPageSequenceItem seq = pageSeries.PageSequence[0]; ASSERT.IsNotNull(seq); ASSERT.AreEqual <int>(1, seq.FirstPage.Value); ASSERT.AreEqual <int>(8, seq.LastPage.Value); var pages = seq.Info; ASSERT.IsNotNull(pages); ASSERT.AreEqual <int>(8, pages.Count); var p1 = pages[0]; ASSERT.AreEqual <int>(11, p1.Fonts.Count); ASSERT.AreEqual <int>(1, p1.PageNumber.Value); ASSERT.IsNull(p1.PageError); var p8 = pages[7]; ASSERT.AreEqual <int>(8, p8.Fonts.Count); ASSERT.AreEqual <int>(8, p8.PageNumber.Value); ASSERT.IsNull(p8.PageError); }
public void TestCallAsyncFireAndForget_ImmediateThrow() { try { // output "hello world" as method returns early ASSERT.AreEqual(ExampleFireAndForgetFunc(), "hello world"); } catch { // Exception is NOT caught here ASSERT.Fail("exception should not be caught here"); } //ASSERT.IsNull(caught_ex); Thread.Sleep(500); ASSERT.IsNotNull(caught_ex); ASSERT.IsTrue(faulted, "faulted"); ASSERT.IsTrue(completed, "completed"); ASSERT.IsFalse(canceled, "cancelled"); }
public void NullableTypeBehaviour() { ASSERT.AreEqual <int>(NullableTypeTestHelperA(), -7); ASSERT.AreEqual <int>(NullableTypeTestHelperA(4), 4); ASSERT.AreEqual <int>(NullableTypeTestHelperA(null), -7); }