Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made AbstractLicenseValidator implement IDisposable #4

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Rhino.Licensing.AdminTool.Tests</RootNamespace>
<AssemblyName>Rhino.Licensing.AdminTool.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -41,7 +41,8 @@
<Reference Include="Caliburn.ShellFramework">
<HintPath>..\SharedLibs\Caliburn.ShellFramework.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Testability">
<Reference Include="Caliburn.Testability, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Caliburn.Testability.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Windsor">
Expand Down Expand Up @@ -88,6 +89,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
Expand All @@ -108,7 +110,10 @@
<Compile Include="Dialogs\OpenFileDialogTests.cs" />
<Compile Include="Dialogs\SaveFileDialogTests.cs" />
<Compile Include="Models\LicenseModelTests.cs" />
<Compile Include="Properties\AssemblyInfo.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 @@ -118,10 +123,15 @@
<Compile Include="Services\ProjectServiceTests.cs" />
<Compile Include="Startup\InstallersTests.cs" />
<Compile Include="ViewModels\AboutViewModelTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\DialogViewModelTests.cs" />
<Compile Include="ViewModels\ProjectViewModelTests.cs" />
<Compile Include="ViewModels\ShellViewModelTests.cs" />
<Compile Include="ViewModels\IssueLicenseViewModelTests.cs" />
<Compile Include="ViewModels\ProjectViewModelTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ViewModels\ShellViewModelTests.cs">
<SubType>Code</SubType>
</Compile>
<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;
}
}
}
}