Added more test cases
This commit is contained in:
parent
18da264119
commit
ed83878039
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Encrypter;
|
||||
@ -21,5 +22,111 @@ namespace Encrypter_Tests
|
||||
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
|
||||
Assert.That(decryptedMessage, Is.EqualTo(message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestEmptyMessage()
|
||||
{
|
||||
var message = string.Empty;
|
||||
var password = "test password";
|
||||
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password);
|
||||
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
|
||||
Assert.That(decryptedMessage, Is.EqualTo(message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestNoMessage()
|
||||
{
|
||||
string message = null;
|
||||
var password = "test password";
|
||||
|
||||
try
|
||||
{
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password);
|
||||
Assert.Fail("Should not be reached!");
|
||||
}
|
||||
catch(CryptographicException e)
|
||||
{
|
||||
Assert.That(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestTooShortPassword4Encryption()
|
||||
{
|
||||
var message = "This is a test with umlauts äüö.";
|
||||
var password = "test";
|
||||
|
||||
try
|
||||
{
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password);
|
||||
Assert.Fail("Should not be reached!");
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Assert.That(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestTooShortPassword4Decryption()
|
||||
{
|
||||
var message = "This is a test with umlauts äüö.";
|
||||
var password = "test password";
|
||||
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password);
|
||||
|
||||
try
|
||||
{
|
||||
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password[..4]);
|
||||
Assert.Fail("Should not be reached!");
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Assert.That(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSimpleEnAndDecryptionWithASCII()
|
||||
{
|
||||
var message = Encoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, Encoding.UTF8.GetBytes("This is a test without umlauts.")));
|
||||
var password = "test password";
|
||||
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password);
|
||||
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password);
|
||||
Assert.That(decryptedMessage, Is.EqualTo(message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestChangedPassword()
|
||||
{
|
||||
var message = "This is a test with umlauts äüö.";
|
||||
var password1 = "password!";
|
||||
var password2 = "password.";
|
||||
|
||||
var encryptedData = await CryptoProcessor.EncryptString(message, password1);
|
||||
|
||||
try
|
||||
{
|
||||
var decryptedMessage = await CryptoProcessor.DecryptString(encryptedData, password2);
|
||||
Assert.Fail("Should not be reached!");
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Assert.That(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSimpleExtensionMethods()
|
||||
{
|
||||
var message = "This is a test with umlauts äüö.";
|
||||
var password = "test password";
|
||||
|
||||
var encryptedData = await message.Encrypt(password);
|
||||
var decryptedMessage = await encryptedData.Decrypt(password);
|
||||
Assert.That(decryptedMessage, Is.EqualTo(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user