Skip to content

Commit

Permalink
Portable Tests
Browse files Browse the repository at this point in the history
Tests now rellay on NUnit and are fully compatible with Mono
  • Loading branch information
lumip authored Dec 15, 2019
2 parents 6c2bdec + d4e6078 commit dc37ac3
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 427 deletions.
55 changes: 30 additions & 25 deletions CompactEC.Tests/CompactEC.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{22FD5C5A-FC60-4F60-B44E-47405CCED477}</ProjectGuid>
<ProjectGuid>{FAD092CB-98B1-4206-A8BC-77AFDDA6CEBB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CompactEC.Tests</RootNamespace>
<AssemblyName>CompactEC.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -42,33 +39,43 @@
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
<Reference Include="Moq, Version=4.13.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.13.1\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.12.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.12.0\lib\net45\Moq.dll</HintPath>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net46\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CryptoGroupTests.cs" />
<Compile Include="CryptoGroupAlgebraTests.cs" />
<Compile Include="CryptoGroupElementTests.cs" />
<Compile Include="CryptoGroupTests.cs" />
<Compile Include="DefaultECParrameterTests.cs" />
<Compile Include="ECPointTests.cs" />
<Compile Include="ECGroupAlgebraTests.cs" />
<Compile Include="ECPointTests.cs" />
<Compile Include="FixedFactorLengthCryptoGroupAlgebraTests.cs" />
<Compile Include="MultiplicativeGroupAlgebraIntegratedTests.cs" />
<Compile Include="MultiplicativeGroupAlgebraTests.cs" />
Expand All @@ -83,14 +90,12 @@
<Name>CompactEC</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>
84 changes: 42 additions & 42 deletions CompactEC.Tests/CryptoGroupAlgebraTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Numerics;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Moq;
using Moq.Protected;

Expand All @@ -15,15 +15,15 @@ interface CryptoGroupAlgebraProtectedMembers
int MultiplyScalarUnsafe(int e, BigInteger k, int factorBitLength);
}

[TestClass]
[TestFixture]
public class CryptoGroupAlgebraTests
{
[TestMethod]
[DataRow(0, 0)]
[DataRow(1, 1)]
[DataRow(2, 2)]
[DataRow(15, 4)]
[DataRow(16, 5)]
[Test]
[TestCase(0, 0)]
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(15, 4)]
[TestCase(16, 5)]
public void TestBitLength(int valueInt, int expectedBitLength)
{
var value = new BigInteger(valueInt);
Expand All @@ -32,12 +32,12 @@ public void TestBitLength(int valueInt, int expectedBitLength)
Assert.AreEqual(expectedBitLength, result);
}

[TestMethod]
[DataRow(0, 0)]
[DataRow(1, 1)]
[DataRow(2, 2)]
[DataRow(15, 4)]
[DataRow(16, 5)]
[Test]
[TestCase(0, 0)]
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(15, 4)]
[TestCase(16, 5)]
public void TestOrderBitLength(int orderInt, int expectedBitLength)
{
var order = new BigInteger(orderInt);
Expand All @@ -50,15 +50,15 @@ public void TestOrderBitLength(int orderInt, int expectedBitLength)
Assert.AreEqual(expectedBitLength, result);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
[DataRow(2)]
[DataRow(3)]
[DataRow(4)]
[DataRow(5)]
[DataRow(6)]
[DataRow(12)]
[Test]
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
[TestCase(4)]
[TestCase(5)]
[TestCase(6)]
[TestCase(12)]
public void TestMultiplyScalar(int scalarInt)
{
// this also tests the implementation in MultiplyScalarUnsafe
Expand Down Expand Up @@ -90,25 +90,25 @@ public void TestMultiplyScalar(int scalarInt)
Assert.AreEqual(expected, result);
}

[TestMethod]
[Test]
public void TestMultiplyScalarRejectsNegativeScalar()
{
int element = 5;
var index = BigInteger.MinusOne;

var algebraMock = new Mock<CryptoGroupAlgebra<int>>(MockBehavior.Strict);

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.Throws<ArgumentOutOfRangeException>(
() => algebraMock.Object.MultiplyScalar(element, index)
);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
[DataRow(2)]
[DataRow(4)]
[DataRow(7)]
[Test]
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
[TestCase(4)]
[TestCase(7)]
public void TestMultiplyScalarWithSmallFactor(int factorInt)
{
int element = 5;
Expand Down Expand Up @@ -137,7 +137,7 @@ public void TestMultiplyScalarWithSmallFactor(int factorInt)
Assert.AreEqual(expected, result);
}

[TestMethod]
[Test]
public void TestMultiplyScalarWithSmallFactorSizeRejectsNegativeScalars()
{
int element = 5;
Expand All @@ -146,15 +146,15 @@ public void TestMultiplyScalarWithSmallFactorSizeRejectsNegativeScalars()

var algebraMock = new Mock<CryptoGroupAlgebra<int>>(MockBehavior.Strict);

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.Throws<ArgumentOutOfRangeException>(
() => algebraMock.Object.MultiplyScalar(element, index, factorBitLength)
);
}

[TestMethod]
[DataRow(8)]
[DataRow(9)]
[DataRow(123)]
[Test]
[TestCase(8)]
[TestCase(9)]
[TestCase(123)]
public void TestMultiplyScalarWithSmallFactorSizeRejectsLargerFactors(int factorInt)
{
var k = new BigInteger(factorInt);
Expand All @@ -163,13 +163,13 @@ public void TestMultiplyScalarWithSmallFactorSizeRejectsLargerFactors(int factor

var algebraMock = new Mock<CryptoGroupAlgebra<int>>(MockBehavior.Strict);

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.Throws<ArgumentOutOfRangeException>(
() => algebraMock.Object.MultiplyScalar(element, k, factorBitLength)
);
}


[TestMethod]
[Test]
public void TestGenerateElement()
{
var order = new BigInteger(7);
Expand Down Expand Up @@ -198,20 +198,20 @@ public void TestGenerateElement()
);
}

[TestMethod]
[Test]
public void TestGenerateElementRejectsNegativeIndex()
{
var index = BigInteger.MinusOne;

var algebraMock = new Mock<CryptoGroupAlgebra<int>>() { CallBase = true };
algebraMock.Setup(alg => alg.Generator).Returns(1);

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.Throws<ArgumentOutOfRangeException>(
() => algebraMock.Object.GenerateElement(index)
);
}

[TestMethod]
[Test]
public void TestNegate()
{
var order = new BigInteger(17);
Expand Down
Loading

0 comments on commit dc37ac3

Please sign in to comment.