Permalink
Browse files

Throw specific exception when license is expired

  • Loading branch information...
1 parent 21ef407 commit 21ce79654cc81800ee9227ccceb6ba4b2f859d92 @brunomlopes brunomlopes committed Feb 24, 2011
@@ -55,6 +55,26 @@ public void Gen_and_validate_with_attributes()
}
[Fact]
+ public void Throws_date_exception_when_license_is_expired()
+ {
+ var guid = Guid.NewGuid();
+ var generator = new LicenseGenerator(public_and_private);
+ var expiration = DateTime.Now.AddDays(-1);
+ var key = generator.Generate("Oren Eini", guid, expiration,
+ new Dictionary<string, string>
+ {
+ {"prof", "llb"},
+ {"reporting", "on"}
+ }, LicenseType.Trial);
+
+ var path = Path.GetTempFileName();
+ File.WriteAllText(path, key);
+
+ var validator = new LicenseValidator(public_only, path);
+ Assert.Throws<LicenseExpiredException>(() => validator.AssertValidLicense());
+ }
+
+ [Fact]
public void Cannot_validate_hacked_license()
{
const string hackedLicense =
@@ -192,8 +192,9 @@ private bool HasExistingLicense()
if (result)
ValidateUsingNetworkTime();
-
- return result;
+ else
+ throw new LicenseExpiredException("Expiration Date : " + ExpirationDate);
+ return true;
}
catch (RhinoLicensingException)
{
@@ -0,0 +1,44 @@
+using System;
+using System.Runtime.Serialization;
+
+namespace Rhino.Licensing
+{
+ ///<summary>
+ /// Thrown when license is found but is past it's expiration date
+ ///</summary>
+ public class LicenseExpiredException : RhinoLicensingException
+ {
+ /// <summary>
+ /// Creates a new instance of <seealso cref="RhinoLicensingException"/>.
+ /// </summary>
+ public LicenseExpiredException()
+ {
+ }
+
+ /// <summary>
+ /// Creates a new instance of <seealso cref="RhinoLicensingException"/>.
+ /// </summary>
+ /// <param name="message">error message</param>
+ public LicenseExpiredException(string message) : base(message)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new instance of <seealso cref="RhinoLicensingException"/>.
+ /// </summary>
+ /// <param name="message">error message</param>
+ /// <param name="inner">inner exception</param>
+ public LicenseExpiredException(string message, Exception inner) : base(message, inner)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new instance of <seealso cref="RhinoLicensingException"/>.
+ /// </summary>
+ /// <param name="info">serialization information</param>
+ /// <param name="context">streaming context</param>
+ public LicenseExpiredException(SerializationInfo info, StreamingContext context) : base(info, context)
+ {
+ }
+ }
+}
@@ -78,6 +78,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractLicenseValidator.cs" />
+ <Compile Include="LicenseExpiredException.cs" />
<Compile Include="InvalidationType.cs" />
<Compile Include="StringLicenseValidator.cs" />
<Compile Include="FloatingLicenseNotAvialableException.cs" />

0 comments on commit 21ce796

Please sign in to comment.