chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
+1 vote
For print using pdfone dll, how to intialize it in test case before proceed to real code, we recieving TypeInitization error when reach following code part from test case
page_font = new PDFFont(pg_font, false, PDFFontEmbedType.Full);
asked by gnanam (4.7k points)

1 Answer

0 votes

To initialize a third-party library in your test case, you can create a fake instance of the library using a mocking framework such as TypeMock Isolator.

For example, to fake the PDFFont class from the PDFone library in your test case, you can use the Isolate.Fake.NextInstance method as follows:

var fakePDFFont = Isolate.Fake.NextInstance<PDFFont>();

// Set up any desired behavior for the fake PDFFont instance

Isolate.WhenCalled(() => fakePDFFont.SomeMethod()).WillReturn(someExpectedValue);

You can then use the fake PDFFont instance in your test case instead of creating a real instance of the PDFFont class. This will allow you to test your code without encountering the TypeInitializationError that you are seeing.

Here's an example of how you can use the fake PDFFont instance in your test case:

[Test]

public void TestPDFFontInitialization()

{

    // Create a fake PDFFont instance

    var fakePDFFont = Isolate.Fake.NextInstance<PDFFont>();

    // Set up any desired behavior for the fake PDFFont instance

    Isolate.WhenCalled(() => fakePDFFont.SomeMethod()).WillReturn(someExpectedValue);

    // Use the fake PDFFont instance in your code

    var pageFont = new PDFFont(fakePDFFont, false, PDFFontEmbedType.Full);

    // Assert that the PDFFont was initialized correctly

    Assert.AreEqual(pageFont.SomeProperty, someExpectedValue);

}

answered by Johnathon00 (190 points)
...