Skip to content

Commit

Permalink
Merge pull request #18 from livioc/merge_HR_master
Browse files Browse the repository at this point in the history
Merge with hibernating-rhinos/rhino-licensing master
  • Loading branch information
ayende committed May 25, 2016
2 parents d7d2746 + d9884ba commit 1fc90c9
Show file tree
Hide file tree
Showing 94 changed files with 33,650 additions and 1,313 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Rhino-Licensing
A software licensing framework [https://www.hibernatingrhinos.com/oss/rhino-licensing](https://www.hibernatingrhinos.com/oss/rhino-licensing) [http://ayende.com](http://ayende.com)

how to build
---------------
The solution can be directly compiled with visual studio
note: the psake build is currently broken

To create the nuget package run buildNuget.bat


how to run the tests
---------------
Please note that in order to run the tests you must either run them in the context of the administrator or run the following command:
netsh http add urlacl url=http://+:19292/license user=YOUR_USER_NAME


acknowledgements
---------------
Rhino Licensing is making use of the excellent log4net logging framework
5 changes: 3 additions & 2 deletions Rhino.Licensing.AdminTool.Tests/Base/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ public class TestBase
{
static TestBase()
{
var app = new App();
app.InitializeComponent();
//seem to hang when upgraded to PSAKE 4.0
//var app = new App();
//app.InitializeComponent();
}
}
}
Binary file modified Rhino.Licensing.AdminTool.Tests/Properties/AssemblyInfo.cs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
<Compile Include="Dialogs\SaveFileDialogTests.cs" />
<Compile Include="Models\LicenseModelTests.cs" />
<Compile Include="Services\BoolToVisibilityConverterTests.cs" />
<Compile Include="Services\ExpirationDateConverterTests.cs" />
<Compile Include="Services\ExportServiceTests.cs" />
<Compile Include="Services\StatusServiceTests.cs" />
<Compile Include="Startup\ContainerTests.cs" />
<Compile Include="Startup\GuyWireTests.cs" />
Expand All @@ -123,8 +125,10 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\DialogViewModelTests.cs" />
<Compile Include="ViewModels\IssueLicenseViewModelTests.cs" />
<Compile Include="ViewModels\ProjectViewModelTests.cs" />
<Compile Include="ViewModels\ShellViewModelTests.cs" />
<Compile Include="ViewModels\UserDataViewModelTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rhino.Licensing.AdminTool\Rhino.Licensing.AdminTool.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Rhino.Licensing.AdminTool.Tests.Services
{
public class DialogServiceTests
{
public class DialogServiceTests
{
[Fact]
public void Can_Show_OpenFileDialog()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Globalization;
using Rhino.Licensing.AdminTool.ValueConverters;
using Xunit;

namespace Rhino.Licensing.AdminTool.Tests.Services
{
public class ExpirationDateConverterTests
{
[Fact]
public void Returns_Never_If_No_Date_Specified()
{
var converter = new ExpirationDateConverter();

var value = converter.Convert(null, GetType(), null, CultureInfo.InvariantCulture);

Assert.Equal("Never", value);
}

[Fact]
public void Convertes_Date_Using_Provided_Culture()
{
var converter = new ExpirationDateConverter();
var culture = new CultureInfo("en-au");

var value = converter.Convert(new DateTime(2000, 1, 1), GetType(), null, culture);

Assert.Equal("1/01/2000 12:00 AM", value);
}

[Fact]
public void Object_Of_Non_Date_Type_Passed_In_Will_Be_Returned()
{
var converter = new ExpirationDateConverter();
var culture = new CultureInfo("en-au");

var value = converter.Convert("String Value", GetType(), null, culture);

Assert.Equal("String Value", value);
}

[Fact]
public void Converts_Date_Using_Invariant_Culture_When_No_Culture_Provided()
{
var converter = new ExpirationDateConverter();
CultureInfo culture = null;

var value = converter.Convert(new DateTime(2000, 1, 1), GetType(), null, culture);

Assert.Equal("01/01/2000 00:00", value);
}

[Fact]
public void Does_One_Way_Conversion()
{
var converter = new ExpirationDateConverter();

Assert.Throws<NotImplementedException>(() => converter.ConvertBack(this, typeof(object), this, CultureInfo.InvariantCulture));
}
}
}
78 changes: 78 additions & 0 deletions Rhino.Licensing.AdminTool.Tests/Services/ExportServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
using Rhino.Licensing.AdminTool.Model;
using Rhino.Licensing.AdminTool.Services;
using Xunit;

namespace Rhino.Licensing.AdminTool.Tests.Services
{
public class ExportServiceTests
{
[Fact]
public void Exports_LicenseInfo_To_File()
{
var service = new ExportService() as IExportService;
var product = new Product { Id = Guid.NewGuid() };
var license = new License { ID = Guid.NewGuid(), LicenseType = LicenseType.Standard, OwnerName = "License Owner", ExpirationDate = new DateTime(2020, 1, 1) };
var path = Path.GetTempFileName();
var file = new FileInfo(path);

service.Export(product, license, file);

var reader = file.OpenText();
var content = reader.ReadToEnd();

Assert.NotNull(content);
Assert.Contains("<name>License Owner</name>", content);
Assert.Contains("type=\"Standard\"", content);
Assert.Contains("expiration=\"2020-01-01T00:00:00.0000000\"", content);
}

[Fact]
public void Exports_With_MaxDate_If_No_Expiration_Date_Is_Set()
{
var service = new ExportService() as IExportService;
var product = new Product { Id = Guid.NewGuid(), Name = "My Product", };
var license = new License { ID = Guid.NewGuid(), LicenseType = LicenseType.Standard, OwnerName = "License Owner", ExpirationDate = null };
var path = Path.GetTempFileName();
var file = new FileInfo(path);

service.Export(product, license, file);

var reader = file.OpenText();
var content = reader.ReadToEnd();

Assert.NotNull(content);
Assert.Contains("expiration=\"9999-12-31T23:59:59.9999999\"", content);
}

[Fact]
public void Exports_With_User_Defined_KeyValues_When_Available()
{
var service = new ExportService() as IExportService;
var product = new Product { Id = Guid.NewGuid(), Name = "My Product", };
var license = new License
{
LicenseType = LicenseType.Standard,
OwnerName = "License Owner",
ExpirationDate = null,
};

license.Data.Add(new UserData { Key = "KeyOne", Value = "ValueOne"});
license.Data.Add(new UserData { Key = "KeyTwo", Value = "ValueTwo"});

var path = Path.GetTempFileName();
var file = new FileInfo(path);

service.Export(product, license, file);

var reader = file.OpenText();
var content = reader.ReadToEnd();

Assert.NotNull(content);
Assert.Contains("KeyOne=\"ValueOne\"", content);
Assert.Contains("KeyTwo=\"ValueTwo\"", content);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Rhino.Licensing.AdminTool.Model;
using Rhino.Licensing.AdminTool.Services;
using Xunit;
using Xunit.Extensions;

namespace Rhino.Licensing.AdminTool.Tests.Services
{
Expand Down
12 changes: 0 additions & 12 deletions Rhino.Licensing.AdminTool.Tests/ViewModels/AboutViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
using System.Reflection;
using Caliburn.Testability;
using Rhino.Licensing.AdminTool.ViewModels;
using Rhino.Licensing.AdminTool.Views;
using Xunit;
using Rhino.Licensing.AdminTool.Extensions;

namespace Rhino.Licensing.AdminTool.Tests.ViewModels
{
public class AboutViewModelTests
{
[Fact]
public void Properties_Are_Bound()
{
var validator = Validator.For<AboutView, AboutViewModel>()
.Validate();

validator.AssertWasBound(x => x.Version);
validator.AssertWasBound(x => x.Copyright);
}

[Fact]
public void Version_Property_Returns_Value_From_AssemblyInfo()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Rhino.Licensing.AdminTool.ViewModels;
using Xunit;

namespace Rhino.Licensing.AdminTool.Tests.ViewModels
{
public class IssueLicenseViewModelTests
{
[Fact]
public void Notifies_All_Screen_When_Selected_License_Changes()
{
var userData = new UserDataViewModel() as IUserDataViewModel;
var licenseInfo = new LicenseInfoViewModel() as ILicenseInfoViewModel;

var vm = new IssueLicenseViewModel(userData, licenseInfo);

Assert.Same(vm.CurrentLicense, userData.CurrentLicense);
Assert.Same(vm.CurrentLicense, licenseInfo.CurrentLicense);
}

[Fact]
public void Closing_ViewModel_Calls_TryClose_With_True_DialogResult()
{
var userData = new UserDataViewModel() as IUserDataViewModel;
var licenseInfo = new LicenseInfoViewModel() as ILicenseInfoViewModel;

var vm = new TestableIssueLicenseViewModel(userData, licenseInfo);
vm.Accept();

Assert.NotNull(vm.SelectedDialogResult);
Assert.True(vm.SelectedDialogResult.Value);
}

[Fact]
public void Can_Accept_New_License_When_OwnerName_Is_Filled()
{
var userData = new UserDataViewModel() as IUserDataViewModel;
var licenseInfo = new LicenseInfoViewModel() as ILicenseInfoViewModel;

var vm = new TestableIssueLicenseViewModel(userData, licenseInfo);

var defaultCanAccept = vm.CanAccept;
vm.CurrentLicense.OwnerName = "John Doe";
var canAccept = vm.CanAccept;

Assert.False(defaultCanAccept);
Assert.True(canAccept);
}

private class TestableIssueLicenseViewModel : IssueLicenseViewModel
{
public TestableIssueLicenseViewModel(IUserDataViewModel userDataViewModel, ILicenseInfoViewModel licenseInfoViewModel)
: base(userDataViewModel, licenseInfoViewModel)
{
}

public bool? SelectedDialogResult { get; set; }

public override void TryClose(bool? dialogResult)
{
SelectedDialogResult = dialogResult;
}
}
}
}
Loading

0 comments on commit 1fc90c9

Please sign in to comment.