Skip to content

Commit

Permalink
Merge pull request #116 from maythamfahmi/jwd/issue107
Browse files Browse the repository at this point in the history
BC: Added example tests back into the mix, with some additional asser…
  • Loading branch information
jwdonahue authored Oct 21, 2024
2 parents 3380863 + a898853 commit c5a2435
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Examples/AESExample/AESExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ string SimulateDecryptor(string key, byte[] encrypted)

// Copyright CryptoNet contributors.
//
// The MIT License is a permissive free software license.The original MIT License text is as follows:
// The MIT License is a permissive free software license. The original MIT License text is as follows:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 35 additions & 9 deletions Examples/Examples.UnitTests/AESExampleTests.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// <copyright file="AESExampleTests.cs"">
// Copyright (c) All Rights Reserved
// </copyright>
// <author>Maytham Fahmi and contributors</author>
// <date>17-12-2021 12:18:44</date>
// <summary>part of CryptoNet project</summary>
// Copyright and trademark notices at the end of this file.

using NUnit.Framework.Legacy;

namespace CryptoNet.Examples.UnitTests;

[ExcludeFromCodeCoverage]
[TestFixture]
public class AESExampleTests
public class AESExampleTests : ExampleTestBase
{
[Ignore("temp")]
private const string AESExampleExeName = "AESExample.exe";

//[Ignore("temp")]
[Test]
public async Task AESExampleSmokeTest()
{
// This provides a human readable temporary directory name prefix.
Expand All @@ -26,7 +24,13 @@ public async Task AESExampleSmokeTest()

using (var tmpDir = new TempDirectory(tmpDirPrefix))
{
var result = await Cli.Wrap("AESExample.exe")
ClassicAssert.IsTrue(Directory.Exists(tmpDir.DirectoryInfo.FullName));
ClassicAssert.IsTrue(File.Exists(AESExampleExeName));


ShowAvailableExecutables();

var result = await Cli.Wrap(AESExampleExeName)
.WithWorkingDirectory(tmpDir.DirectoryInfo.FullName)
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
Expand All @@ -47,3 +51,25 @@ public async Task AESExampleSmokeTest()
ClassicAssert.IsTrue(stdOut.EndsWith("Decrypted: Watson, can you hear me?"));
}
}

// Copyright CryptoNet contributors.
//
// The MIT License is a permissive free software license. The original MIT License text is as follows:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
38 changes: 38 additions & 0 deletions Examples/Examples.UnitTests/ExampleTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright and trademark notices at the end of this file.

namespace CryptoNet.Examples.UnitTests;

public class ExampleTestBase
{
public void ShowAvailableExecutables()
{
Console.WriteLine("Available .exe files in CWD:");
foreach (var fileName in Directory.GetFiles(".", "*.exe"))
{
Console.WriteLine(fileName);
}
Console.WriteLine();
}
}

// Copyright CryptoNet contributors.
//
// The MIT License is a permissive free software license. The original MIT License text is as follows:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
6 changes: 5 additions & 1 deletion Examples/Examples.UnitTests/Examples.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<PropertyGroup>
<AssemblyName>CryptoNet.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>CryptoNet.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
Expand Down
16 changes: 12 additions & 4 deletions Examples/Examples.UnitTests/RSAExampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ namespace CryptoNet.Examples.UnitTests;

[ExcludeFromCodeCoverage]
[TestFixture]
public class RSAExampleTests
public class RSAExampleTests : ExampleTestBase
{
[Ignore("temp")]
private const string RSAExampleExeName = "RSAExample.exe";

//[Ignore("temp")]
[Test]
public async Task RSAExampleSmokeTest()
{
var tmpDirPrefix = $"{nameof(AESExampleTests)}.{nameof(RSAExampleSmokeTest)}-{Guid.NewGuid().ToString("D")}";
Expand All @@ -18,7 +21,12 @@ public async Task RSAExampleSmokeTest()

using (var tmpDir = new TempDirectory())
{
var result = await Cli.Wrap("RSAExample.exe")
ClassicAssert.IsTrue(Directory.Exists(tmpDir.DirectoryInfo.FullName));
ClassicAssert.IsTrue(File.Exists(RSAExampleExeName));

ShowAvailableExecutables();

var result = await Cli.Wrap(RSAExampleExeName)
.WithWorkingDirectory(tmpDir.DirectoryInfo.FullName)
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
Expand All @@ -42,7 +50,7 @@ public async Task RSAExampleSmokeTest()

// Copyright CryptoNet contributors.
//
// The MIT License is a permissive free software license.The original MIT License text is as follows:
// The MIT License is a permissive free software license. The original MIT License text is as follows:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit c5a2435

Please sign in to comment.