Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2cc3b27

Browse files
committed
Add support for Trial license
1 parent b8f7e29 commit 2cc3b27

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/ServiceStack.Text/LicenseUtils.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum LicenseType
2626
OrmLiteBusiness,
2727
RedisIndie,
2828
RedisBusiness,
29+
Trial,
2930
}
3031

3132
[Flags]
@@ -168,6 +169,10 @@ public static void RegisterLicense(string licenseKeyText)
168169
throw new LicenseException("This license has expired on {0} and is not valid for use with this release."
169170
.Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();
170171

172+
if (key.Type == LicenseType.Trial && DateTime.UtcNow > key.Expiry)
173+
throw new LicenseException("This trial license has expired on {0}."
174+
.Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();
175+
171176
__activatedLicense = key;
172177
}
173178
catch (Exception ex)
@@ -296,6 +301,7 @@ public static LicenseFeature GetLicensedFeatures(this LicenseKey key)
296301
case LicenseType.Indie:
297302
case LicenseType.Business:
298303
case LicenseType.Enterprise:
304+
case LicenseType.Trial:
299305
return LicenseFeature.All;
300306

301307
case LicenseType.TextIndie:

tests/ServiceStack.Text.Tests/LicensingTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class LicensingTests
3737
const string TestText2013Text = "1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBUZXh0LFR5cGU6VGV4dEluZGllLEhhc2g6V3liaFpUejZiMWgxTGhCcmRRSzlNc09FVUsya3Z6Z2E5VDBaRCtEWnlBd0JxM1dabVFVanNaelgwTWR5OXJMSTlmbzJ0dVVOMk9iZ2srcmswdVZGeit6Q1dreTk3SFE5OHhkOGtDRkx0LzQxR2RiU054SnFIVUlmR1hMdS9CQTVOR0lKanN3SjhXTjdyY0R0VmYyTllKK2dEaFd1RzZ4cnB1ZXhYa01WSXFrPSxFeHBpcnk6MjAxMy0wMS0wMX0=";
3838
readonly LicenseKey TestText2013 = new LicenseKey { Ref = "1001", Name = "Test Text", Type = LicenseType.TextIndie, Expiry = new DateTime(2013, 01, 01) };
3939

40+
const string TestTrial2000Text = "TRIAL302000-e1JlZjpUUklBTDMwMjAwMCxOYW1lOlRyaWFsIFRlc3QsVHlwZTpUcmlhbCxIYXNoOm4vOGhCQmk3cjFBSmV3WmNwaksyYXJBaDhObHBvRFVNR1ExZjNocmFwaERDNm5zRjY1azJ6bUI2b2xwblhtdHVVdFhNUEoxQ1prOVdWWVlNdjcrTnU3VVk0bS9CV091R1RNb2FxaUU2QWExRGpjRW91NDZHRy83c0tQeGVJcXcxK01XZXdFdm96TTRBWDhhZEs0dEEwZGF6a1dnVjZYMVJBK2tzZDVWZTZvcz0sRXhwaXJ5OjIwMDAtMDEtMDF9";
41+
readonly LicenseKey TestTrial2000 = new LicenseKey { Ref = "TRIAL302000", Name = "Trial Test", Type = LicenseType.Trial, Expiry = new DateTime(2000, 01, 01) };
42+
const string TestTrial2016Text = "TRIAL302016-e1JlZjpUUklBTDMwMjAxNixOYW1lOlRyaWFsIFRlc3QsVHlwZTpUcmlhbCxIYXNoOkFSSThkVzlHZ210NWZGZ09MTytIRi9vQ29iOWgwN1c4bGxuNHZrUm9CQ2M5aysxVlh3WWJEd2Nxais3cHhFbEwrTkgwbGF2NXoyZGdJV1NndUpXYjZrUC9aQWdqNVIvMmlHamp4ZlduQjExOWY2WHgvRzFERmQ5cndJdjNMejhzR0V5RitNcGhlN3RTbEhJVlR4UjA1amI2SDFaZHlIYjNDNFExcTJaWEFzQT0sRXhwaXJ5OjIwMTYtMDEtMDF9";
43+
readonly LicenseKey TestTrial2016 = new LicenseKey { Ref = "TRIAL302016", Name = "Trial Test", Type = LicenseType.Trial, Expiry = new DateTime(2016, 01, 01) };
44+
4045
public IEnumerable AllLicenseUseCases
4146
{
4247
get
@@ -107,6 +112,13 @@ public void Can_register_valid_licenses()
107112
Assert.That(LicenseUtils.ActivatedLicenseFeatures(), Is.EqualTo(LicenseFeature.All));
108113
}
109114

115+
[Test, Explicit("Licenses are expired")]
116+
public void Can_register_valid_trial_license()
117+
{
118+
Licensing.RegisterLicense(TestTrial2016Text);
119+
Assert.That(LicenseUtils.ActivatedLicenseFeatures(), Is.EqualTo(LicenseFeature.All));
120+
}
121+
110122
[Test]
111123
public void Can_register_valid_license()
112124
{
@@ -142,6 +154,17 @@ public void Expired_licenses_throws_LicenseException()
142154
ex.Message.Print();
143155
Assert.That(ex.Message, Is.StringStarting("This license has expired"));
144156
}
157+
158+
try
159+
{
160+
Licensing.RegisterLicense(TestTrial2000Text);
161+
Assert.Fail("Should throw Expired LicenseException");
162+
}
163+
catch (LicenseException ex)
164+
{
165+
ex.Message.Print();
166+
Assert.That(ex.Message, Is.StringStarting("This license has expired"));
167+
}
145168
}
146169

147170
[Explicit,Test]

0 commit comments

Comments
 (0)