Unit-Test erweitert, NetRevisionTask aktualisiert, ExceptionTests hinzugefügt...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using AMWD.Common.Tests.Utils;
|
||||
@@ -9,6 +10,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace AMWD.Common.Tests.Utilities
|
||||
{
|
||||
[TestClass]
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public class CryptographyHelperTests
|
||||
{
|
||||
private string keyFile;
|
||||
@@ -430,10 +432,15 @@ namespace AMWD.Common.Tests.Utilities
|
||||
string str2 = "Hello World!";
|
||||
string str3 = "Hallo World!";
|
||||
string str4 = "Hello World?";
|
||||
string nullStr = null;
|
||||
string strLen = "Hello World";
|
||||
|
||||
var sw = new Stopwatch();
|
||||
|
||||
// act
|
||||
bool nullCompare = CryptographyHelper.SecureEquals(nullStr, str1);
|
||||
bool lenCompare = CryptographyHelper.SecureEquals(strLen, str1);
|
||||
|
||||
sw.Start();
|
||||
bool compare1 = CryptographyHelper.SecureEquals(str1, str2);
|
||||
long time1 = sw.ElapsedMilliseconds;
|
||||
@@ -446,10 +453,12 @@ namespace AMWD.Common.Tests.Utilities
|
||||
sw.Stop();
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(nullCompare);
|
||||
Assert.IsFalse(lenCompare);
|
||||
Assert.IsTrue(compare1);
|
||||
Assert.IsFalse(compare2);
|
||||
Assert.IsFalse(compare3);
|
||||
// max. time delta: 2 ticks per character
|
||||
|
||||
Assert.AreEqual(time1, time2);
|
||||
Assert.AreEqual(time1, time3);
|
||||
Assert.AreEqual(time2, time3);
|
||||
@@ -463,6 +472,8 @@ namespace AMWD.Common.Tests.Utilities
|
||||
byte[] bytes2 = new byte[bytes1.Length];
|
||||
byte[] bytes3 = new byte[bytes1.Length];
|
||||
byte[] bytes4 = new byte[bytes1.Length];
|
||||
byte[] nullBytes = null;
|
||||
byte[] lenBytes = new byte[bytes1.Length + 1];
|
||||
|
||||
Array.Copy(bytes1, bytes2, bytes1.Length);
|
||||
Array.Copy(bytes1, bytes3, bytes1.Length);
|
||||
@@ -474,6 +485,9 @@ namespace AMWD.Common.Tests.Utilities
|
||||
var sw = new Stopwatch();
|
||||
|
||||
// act
|
||||
bool nullCompare = CryptographyHelper.SecureEquals(nullBytes, bytes1);
|
||||
bool lenCompare = CryptographyHelper.SecureEquals(lenBytes, bytes1);
|
||||
|
||||
sw.Start();
|
||||
bool compare1 = CryptographyHelper.SecureEquals(bytes1, bytes2);
|
||||
long time1 = sw.ElapsedMilliseconds;
|
||||
@@ -486,10 +500,12 @@ namespace AMWD.Common.Tests.Utilities
|
||||
sw.Stop();
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(nullCompare);
|
||||
Assert.IsFalse(lenCompare);
|
||||
Assert.IsTrue(compare1);
|
||||
Assert.IsFalse(compare2);
|
||||
Assert.IsFalse(compare3);
|
||||
// max. time delta: 2 ticks per byte
|
||||
|
||||
Assert.AreEqual(time1, time2);
|
||||
Assert.AreEqual(time1, time3);
|
||||
Assert.AreEqual(time2, time3);
|
||||
@@ -501,6 +517,28 @@ namespace AMWD.Common.Tests.Utilities
|
||||
|
||||
#region Instance
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldCreateDefaultFile()
|
||||
{
|
||||
// arrange
|
||||
string executingAssemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
string filePath = Path.Combine(executingAssemblyDir, "crypto.key");
|
||||
|
||||
// act
|
||||
bool fileExistsBefore = File.Exists(filePath);
|
||||
var helper = new CryptographyHelper();
|
||||
bool fileExistsAfter = File.Exists(filePath);
|
||||
string content = fileExistsAfter ? File.ReadAllText(filePath) : null;
|
||||
File.Delete(filePath);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(fileExistsBefore);
|
||||
Assert.IsNotNull(helper);
|
||||
Assert.IsTrue(fileExistsAfter);
|
||||
Assert.IsTrue(!string.IsNullOrWhiteSpace(content));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldEncryptAesUsingKeyFile()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace AMWD.Common.Tests.Utilities
|
||||
{
|
||||
[TestClass]
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public class DelayedTaskTests
|
||||
{
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user