Unit-Test erweitert, NetRevisionTask aktualisiert, ExceptionTests hinzugefügt...
This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace AMWD.Common.Tests.Extensions
|
||||
{
|
||||
[TestClass]
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public class StringExtensionsTests
|
||||
{
|
||||
[TestMethod]
|
||||
@@ -132,10 +133,12 @@ namespace AMWD.Common.Tests.Extensions
|
||||
string plain = "Hello";
|
||||
|
||||
// act
|
||||
string hex = plain.HexEncode(Encoding.UTF8);
|
||||
string hex1 = plain.HexEncode();
|
||||
string hex2 = plain.HexEncode(Encoding.Default);
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("48656c6c6f", hex);
|
||||
Assert.AreEqual("48656c6c6f", hex1);
|
||||
Assert.AreEqual("48656c6c6f", hex2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -145,10 +148,12 @@ namespace AMWD.Common.Tests.Extensions
|
||||
string hex = "48656c6c6f";
|
||||
|
||||
// act
|
||||
string plain = hex.HexDecode(Encoding.UTF8);
|
||||
string plain1 = hex.HexDecode();
|
||||
string plain2 = hex.HexDecode(Encoding.Default);
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("Hello", plain);
|
||||
Assert.AreEqual("Hello", plain1);
|
||||
Assert.AreEqual("Hello", plain2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -158,10 +163,12 @@ namespace AMWD.Common.Tests.Extensions
|
||||
string plain = "Hello";
|
||||
|
||||
// act
|
||||
string base64 = plain.Base64Encode(Encoding.UTF8);
|
||||
string base641 = plain.Base64Encode();
|
||||
string base642 = plain.Base64Encode(Encoding.Default);
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("SGVsbG8=", base64);
|
||||
Assert.AreEqual("SGVsbG8=", base641);
|
||||
Assert.AreEqual("SGVsbG8=", base642);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -171,10 +178,12 @@ namespace AMWD.Common.Tests.Extensions
|
||||
string base64 = "SGVsbG8=";
|
||||
|
||||
// act
|
||||
string plain = base64.Base64Decode(Encoding.UTF8);
|
||||
string plain1 = base64.Base64Decode();
|
||||
string plain2 = base64.Base64Decode(Encoding.Default);
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("Hello", plain);
|
||||
Assert.AreEqual("Hello", plain1);
|
||||
Assert.AreEqual("Hello", plain2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -255,18 +264,21 @@ namespace AMWD.Common.Tests.Extensions
|
||||
string validEmailWithTag = "test+tag@not.exists";
|
||||
string invalidEmailWithoutTag = "<Test Account> test@gmail.com";
|
||||
string invalidEmailWithTag = "<Test Account> test+tag@not.exists";
|
||||
string nullStr = null;
|
||||
|
||||
// act
|
||||
bool validWithoutTag = validEmailWithoutTag.IsValidEmailAddress(checkRecordExists: false);
|
||||
bool validWithTag = validEmailWithTag.IsValidEmailAddress(checkRecordExists: false);
|
||||
bool invalidWithoutTag = !invalidEmailWithoutTag.IsValidEmailAddress(checkRecordExists: false);
|
||||
bool invalidWithTag = !invalidEmailWithTag.IsValidEmailAddress(checkRecordExists: false);
|
||||
bool nullTest = nullStr.IsValidEmailAddress(checkRecordExists: false);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(validWithoutTag);
|
||||
Assert.IsTrue(validWithTag);
|
||||
Assert.IsTrue(invalidWithoutTag);
|
||||
Assert.IsTrue(invalidWithTag);
|
||||
Assert.IsFalse(nullTest);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -301,5 +313,25 @@ namespace AMWD.Common.Tests.Extensions
|
||||
Assert.IsTrue(valid);
|
||||
Assert.IsTrue(invalid);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldWorkWithNullOrEmptyString()
|
||||
{
|
||||
// arrange
|
||||
string nullStr = null;
|
||||
string emptyStr = "";
|
||||
|
||||
// act
|
||||
string hexEncodeNull = nullStr.HexEncode();
|
||||
string hexEncodeEmpty = emptyStr.HexEncode();
|
||||
string hexDecodeNull = nullStr.HexDecode();
|
||||
string hexDecodeEmpty = emptyStr.HexDecode();
|
||||
|
||||
// assert
|
||||
Assert.IsNull(hexEncodeNull);
|
||||
Assert.AreEqual("", hexEncodeEmpty);
|
||||
Assert.IsNull(hexDecodeNull);
|
||||
Assert.AreEqual("", hexDecodeEmpty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user