Skip to content

Commit

Permalink
#86 rename test class to share project and test check content
Browse files Browse the repository at this point in the history
  • Loading branch information
maythamfahmi committed Oct 20, 2024
1 parent 2e869a9 commit 228d437
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 42 deletions.
1 change: 0 additions & 1 deletion CryptoNet.UnitTests/CryptoNetRsaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public void Encrypt_With_PublicKey_Decrypt_With_PrivateKey_Using_SelfGenerated_A

// Assert
Common.CheckContent(Common.ConfidentialDummyData, decryptWithPrivateKey).ShouldBeTrue();
Common.DeleteTestFiles(Common.DummyFiles);
}

[TestCase("test.docx")]
Expand Down
41 changes: 0 additions & 41 deletions CryptoNet.UnitTests/DirectoryExensionTests.cs

This file was deleted.

125 changes: 125 additions & 0 deletions CryptoNet.UnitTests/ShareProjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.IO;
using CryptoNet.Share;
using CryptoNet.Share.Extensions;
using NUnit.Framework;
using Shouldly;

namespace CryptoNet.UnitTests
{
[TestFixture]
public class ShareProjectTests
{
[Test]
public void TryGetSolutionDirectoryInfo_ShouldReturnNull_WhenNoSolutionFileExists()
{
// Act
var result = DirectoryExension.TryGetSolutionDirectoryInfo();

// Assert
result.ShouldNotBeNull();
result!.FullName.ShouldContain("CryptoNet");
}

[Test]
public void TryGetSolutionDirectoryInfo_ShouldReturnDirectoryWithTestFiles()
{
// Arrange
string solutionFilePath = Path.Combine(Common.TestFilesPath);

// Act
var result = DirectoryExension.TryGetSolutionDirectoryInfo();
var testFiles = Path.Combine(result!.FullName, "Resources", "TestFiles");
var di = new DirectoryInfo(testFiles);
var files = di.GetFiles("test.*");

// Assert
files.ShouldNotBeNull();
files.Count().ShouldBe(4);

Check failure on line 38 in CryptoNet.UnitTests/ShareProjectTests.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Count' takes 0 arguments

Check failure on line 38 in CryptoNet.UnitTests/ShareProjectTests.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Count' takes 0 arguments

Check failure on line 38 in CryptoNet.UnitTests/ShareProjectTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

No overload for method 'Count' takes 0 arguments

Check failure on line 38 in CryptoNet.UnitTests/ShareProjectTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

No overload for method 'Count' takes 0 arguments
}

[Test]
public void CheckContent_WhenContentsAreSame_ShouldReturnTrue()
{
// Arrange
string originalContent = "This is a test string";
string decryptedContent = "This is a test string";

// Act
bool result = Common.CheckContent(originalContent, decryptedContent);

// Assert
result.ShouldBeTrue("because both contents are identical, so MD5 hashes should match.");
}

[Test]
public void CheckContent_WhenContentsAreDifferent_ShouldReturnFalse()
{
// Arrange
string originalContent = "This is a test string";
string decryptedContent = "This is a different string";

// Act
bool result = Common.CheckContent(originalContent, decryptedContent);

// Assert
result.ShouldBeFalse("because contents are different, so their MD5 hashes should not match.");
}

[Test]
public void CheckContent_WhenBothContentsAreEmpty_ShouldReturnTrue()
{
// Arrange
string originalContent = "";
string decryptedContent = "";

// Act
bool result = Common.CheckContent(originalContent, decryptedContent);

// Assert
result.ShouldBeTrue("because both contents are empty, and their MD5 hashes should match.");
}

[Test]
public void CheckContent_WhenOneContentIsNull_ShouldReturnFalse()
{
// Arrange
string originalContent = "This is a test string";
string? decryptedContent = null;

// Act
bool result = Common.CheckContent(originalContent, decryptedContent!);

// Assert
result.ShouldBeFalse("because one content is null, so their MD5 hashes cannot match.");
}

[Test]
public void CheckContent_WhenBothContentsAreNull_ShouldReturnTrue()
{
// Arrange
string? originalContent = null;
string? decryptedContent = null;

// Act
bool result = Common.CheckContent(originalContent!, decryptedContent!);

// Assert
result.ShouldBeTrue("because both contents are null, so their MD5 hashes should be the same.");
}

[Test]
public void CheckContent_WhenContentsContainSpecialCharacters_ShouldReturnTrue()
{
// Arrange
string originalContent = "!@#$%^&*()_+1234567890";
string decryptedContent = "!@#$%^&*()_+1234567890";

// Act
bool result = Common.CheckContent(originalContent, decryptedContent);

// Assert
result.ShouldBeTrue("because both contents are identical even with special characters.");
}
}
}

0 comments on commit 228d437

Please sign in to comment.