60 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Livia.Models;
 | 
						|
 | 
						|
namespace Livia.Tests.Models;
 | 
						|
 | 
						|
public class AesOperationTests(IAesOperation aesOperation)
 | 
						|
{
 | 
						|
    [Theory]
 | 
						|
    [InlineData("", "")]
 | 
						|
    [InlineData("", "    ")]
 | 
						|
    [InlineData("     ", "    ")]
 | 
						|
    [InlineData("123465", "    ")]
 | 
						|
    public void EncryptString_InvalidKey_EmptyString(string key, string text)
 | 
						|
    {
 | 
						|
        string result = aesOperation.EncryptString(key, text);
 | 
						|
        Assert.Equal(string.Empty, result);
 | 
						|
    }
 | 
						|
 | 
						|
    [Fact]
 | 
						|
    public void EncryptString_0key_EncryptedString()
 | 
						|
    {
 | 
						|
        string result = aesOperation.EncryptString("00000000000000000000000000000000", "");
 | 
						|
        Assert.Equal("AxjghOFmbmmYkcePiqmJYA==", result);
 | 
						|
 | 
						|
        result = aesOperation.EncryptString("00000000000000000000000000000000", "abc");
 | 
						|
        Assert.Equal("5mTKIdERZle61IWzOzuB9g==", result);
 | 
						|
    }
 | 
						|
 | 
						|
    [Theory]
 | 
						|
    [InlineData("", "")]
 | 
						|
    [InlineData("", "    ")]
 | 
						|
    [InlineData("     ", "    ")]
 | 
						|
    public void DecryptString_InvalidKey_EmptyString(string key, string text)
 | 
						|
    {
 | 
						|
        string result = aesOperation.DecryptString(key, text);
 | 
						|
        Assert.Equal(string.Empty, result);
 | 
						|
    }
 | 
						|
 | 
						|
    [Fact]
 | 
						|
    public void DecryptString_0key_DecryptedString()
 | 
						|
    {
 | 
						|
        string result = aesOperation.DecryptString("00000000000000000000000000000000", "AxjghOFmbmmYkcePiqmJYA==");
 | 
						|
        Assert.Equal("", result);
 | 
						|
 | 
						|
        result = aesOperation.DecryptString("00000000000000000000000000000000", "5mTKIdERZle61IWzOzuB9g==");
 | 
						|
        Assert.Equal("abc", result);
 | 
						|
    }
 | 
						|
 | 
						|
    [Theory]
 | 
						|
    [InlineData("")]
 | 
						|
    [InlineData("123")]
 | 
						|
    [InlineData("Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. " +
 | 
						|
                "This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. " +
 | 
						|
                "It came as a joyous daybreak to end the long night of their captivity.")]
 | 
						|
    public void EncryptDecryptString_0key_TextSame(string text)
 | 
						|
    {
 | 
						|
        string encrypted = aesOperation.EncryptString("00000000000000000000000000000000", text);
 | 
						|
        string result = aesOperation.DecryptString("00000000000000000000000000000000", encrypted);
 | 
						|
        Assert.Equal(text, result);
 | 
						|
    }
 | 
						|
} |