-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from vicheanath/git-repo
Add Service Test
- Loading branch information
Showing
10 changed files
with
476 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.Extensions.Options; | ||
using SearchBugs.Infrastructure.Options; | ||
|
||
namespace SearchBugs.Infrastructure.UnitTests.Data; | ||
|
||
public class OptionsTest : IOptions<GitOptions>, IDisposable | ||
{ | ||
public GitOptions Value => new GitOptions | ||
{ | ||
BasePath = Path.Combine(Directory.GetCurrentDirectory(), "Repositories") | ||
}; | ||
|
||
public OptionsTest() | ||
{ | ||
if (!Directory.Exists(Value.BasePath)) | ||
{ | ||
Directory.CreateDirectory(Value.BasePath); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (Directory.Exists(Value.BasePath)) | ||
{ | ||
Directory.Delete(Value.BasePath, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
test/SearchBugs.Infrastructure.UnitTests/ServiceTest/DataEncryptionServiceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using FluentAssertions; | ||
using SearchBugs.Infrastructure.Services; | ||
|
||
namespace SearchBugs.Infrastructure.UnitTests.ServiceTest; | ||
|
||
public class DataEncryptionServiceTest | ||
{ | ||
[Fact] | ||
public void Encrypt_WhenCalled_ReturnEncryptedString() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var plainText = "Hello World"; | ||
var _32ByteKey = "XdhXLy^{8Pzs~O!Jm*MJLg^NA)4;(44m"; | ||
|
||
// Act | ||
var encryptedText = service.Encrypt(plainText, _32ByteKey); | ||
|
||
// Assert | ||
encryptedText.Should().NotBe(plainText); | ||
encryptedText.Should().NotBeNullOrEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void Decrypt_WhenCalled_ReturnDecryptedString() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var plainText = "Hello World"; | ||
var _32ByteKey = "XdhXLy^{8Pzs~O!Jm*MJLg^NA)4;(44m"; | ||
|
||
// Act | ||
var encryptedText = service.Encrypt(plainText, _32ByteKey); | ||
var decryptedText = service.Decrypt(encryptedText, _32ByteKey); | ||
|
||
// Assert | ||
decryptedText.Should().Be(plainText); | ||
} | ||
|
||
[Fact] | ||
public void Encrypt_WhenPlainTextIsNull_ThrowArgumentNullException() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var _32ByteKey = "XdhXLy^{8Pzs~O!Jm*MJLg^NA)4;(44m"; | ||
|
||
// Act | ||
Action act = () => service.Encrypt(null, _32ByteKey); | ||
|
||
// Assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("Value cannot be null. (Parameter 'plainText')"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void Encrypt_WhenKeyIsNull_ThrowArgumentNullException() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var plainText = "Hello World"; | ||
|
||
// Act | ||
Action act = () => service.Encrypt(plainText, null); | ||
|
||
// Assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("Value cannot be null. (Parameter 'key')"); | ||
} | ||
|
||
[Fact] | ||
public void Decrypt_WhenCipherTextIsNull_ThrowArgumentNullException() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var _32ByteKey = "XdhXLy^{8Pzs~O!Jm*MJLg^NA)4;(44m"; | ||
|
||
// Act | ||
Action act = () => service.Decrypt(null, _32ByteKey); | ||
|
||
// Assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("Value cannot be null. (Parameter 'cipherText')"); | ||
} | ||
|
||
[Fact] | ||
public void Decrypt_WhenKeyIsNull_ThrowArgumentNullException() | ||
{ | ||
// Arrange | ||
var service = new DataEncryptionService(); | ||
var plainText = "Hello World"; | ||
|
||
// Act | ||
Action act = () => service.Decrypt(plainText, null); | ||
|
||
// Assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("Value cannot be null. (Parameter 'key')"); | ||
} | ||
} |
Oops, something went wrong.