We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Testing an embedded licence in a .Net assembly

We would like to test a licence inside an unit test. So, an automatic test that should test the licence and ensure that it is valid either not expired.


Our licence is embedded inside an assembly with some protection (encryption) like suggested by you (Aspose). But, before the deployment we would like to ensure that all will work without a red warning showing that the Aspose licence is expired neither any other problems related to the licenses or runtime-like issues.

We’re experiencing a red warning in a valid and not expired licence which we are waiting help in another question (thread), but regardless that it will work soon (after your help), we want to block the deploy if there are some Aspose runtime issue.

Is that possible ? How ?

Hi Luciano,

Thanks for your inquiry. I suggest you please read following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsnet/Including+the+License+File+as+an+Embedded+Resource
http://www.aspose.com/docs/display/wordsnet/Applying+a+License
http://www.aspose.com/docs/display/wordsnet/When+to+Apply+a+License

Please create a standalone/runnable simple application (for example a Console Application Project) that demonstrates the issue which you are facing.

You can try using code like the following to check whether license is set or not:

///

/// Returns true if the Aspose.Words license is set.

///

private static bool IsLicenseSet()

{

// We will insert this text at the beggining of the document.

// If the license set this text will be in th efirt paragraph,

// if not an evaluation watermark will be in the first paragraph.

const string text = "This is text used to check if the license is set";

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write(text);

// Save and open the document. If Aspose.Words works in evaluation mode it will add a watermark.

using (MemoryStream docStream = new MemoryStream())

{

doc.Save(docStream, SaveFormat.Doc);

docStream.Position = 0;

doc = new Document(docStream);

}

// Check text of the first paragraph.

return (doc.FirstSection.Body.FirstParagraph.ToTxt().Trim() == text);

}





I would like to have some test cases, like as one to test an invalid license, an expired license, and a live valid license.


After the license has applied, is there a way to clear/reset, or apply a new one ?

Hi Luciano,

Thanks for your inquiry.

luciano.moreira:

I would like to have some test cases, like as one to test an invalid license, an expired license, and a live valid license.

In this case, I suggest you please enclose the License.SetLicense method in try catch block and check the exception. If a license is not valid for a product, you will get ‘The license is not valid for this product.’ If the subscription of license is expired, you will get the following exception.

The subscription included in this license allows free upgrades until 16 Nov 2012, but this version of the product was released on 31 Jul 2014. Please renew the subscription or use a previous version of the product.

Moreover, to check an
expiration date of your license open the license file using notepad. You
will see the following tags:


20140118

It means that you can free upgrade to version of Aspose.Words published before 01/18/2014.
luciano.moreira:

After the license has applied, is there a way to clear/reset, or apply a new one ?

You can use the same License.SetLicense method to rest the new license file. Please call this method with new license file. Could you please share the reason why you want to reset the license?

Automated tests run usually in the same context (outside our control), so each case to test (valid, invalid, expired) can be ‘contaminated’ with some static data stored by Aspose.Words (like license data) from the last unit test run.


So, a way to clear all static data stored by Aspose.Words before each run would be nice, but if I can ‘reset’ the license just calling SetLicense, it can meet our needs anyway.

Hi Luciano,

Thanks for your inquiry.

luciano.moreira:

but if I can ‘reset’ the license just calling SetLicense, it can meet our needs anyway.

Yes, you can call the SetLicense to set the license again. Could you please share why you want to reset the license? Calling License.SetLicense multiple times is not harmful, but simply wastes processor time.
luciano.moreira:

So, a way to clear all static data stored by Aspose.Words before each run would be nice

I have logged this feature request as WORDSNET-10728 in our issue tracking system. Our development team will look into the
possibility of implementation of this requested feature. Once we have
any information about this feature, we will update you via this forum thread.

Please let us know if you have any more queries.

Hi Luciano,

luciano.moreira:

So, a way to clear all static data stored by Aspose.Words before each run would be nice

Further to my last post, please use an empty string in License.SetLicense method to switch to evaluation mode. In this case, you can achieve your requirements. So, we are closing WORDSNET-10728.

Please let us know if you have any more queries.