Licensing when unit testing

Hi,

I have a C# solution with two projects:
  • An application project which consumes RichTextBoxAdv and DocIO
  • An NUnit 3 test project which unit tests the application project
The application project is added to the test project via a project reference. The Syncfusion license is registered in the application project in App.xaml.cs : App() using the following:

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("My License Key");

A lot of my unit tests are failing because they are using the Save() method on the RichTextBoxAdv Document property to generate a string representation of the document to verify certain test cases. The problem is, this string is always coming back as "Created with a trial version of Syncfusion Essential DocIO.".

I understand I probably need to register a license for the test project somewhere? What is the recommended way to do this for a test project in the same solution as the application project? Should it be a different or the same license key? Bearing in mind, test projects do not have an App.xaml.cs file.

I tried registering a license at the start of each test, but that does not work.

Thanks,
Josh

2 Replies

PS Premkumar Sundaramoorthy Syncfusion Team March 30, 2020 01:01 PM UTC

Hi Josh,

Thanks for contacting Syncfusion support.

 
We are working to build a sample for reproduce the reported issue from our side. We will get back to you with more details on or before  1st April, 2010. 
 
Please let us know if you have any other questions.

Regards,
 
Premkumar 



PS Premkumar Sundaramoorthy Syncfusion Team April 2, 2020 04:32 AM UTC

Hi Josh,

Thanks for your patience.

The following code demonstrates how to register the license key in the Unit test project.

 
        [SetUp] 
        public void Initializing() 
        { 
         Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("License Key"); 
        } 
 
        [Test] 
        public void SaveAsText() 
        { 
            //Creates an instance of WordDocument Instance (Empty Word Document) 
            WordDocument document = new WordDocument(); 
            //Add a section & a paragraph in the empty document 
            document.EnsureMinimal(); 
            //Append text to the last paragraph of the document 
            document.LastParagraph.AppendText("Hello World"); 
 
            MemoryStream memoryStream = new MemoryStream(); 
            document.Save(memoryStream, Syncfusion.DocIO.FormatType.Txt); 
 
            string outputText = string.Empty; 
            memoryStream.Position = 0; 
 
            // Reads the stream and assigned the string to Text property 
            using (StreamReader reader = new StreamReader(memoryStream)) 
            { 
                outputText = reader.ReadToEnd(); 
            } 
 
            Assert.IsTrue(outputText == "Hello World"); 
        } 

If still, you are facing the same issue please check whether your license key is valid. And share the simple sample to reproduce the reported issue from our side.

Please let us know if you need any furter assitance.

Regards,
Premkumar


Loader.
Up arrow icon