From bf842c5ec22429738787cf48772a501d5dd1c573 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Wed, 13 May 2015 21:22:35 +0100 Subject: [PATCH] Added more tests, added an InteralVisibleTo property into the Assembly so we would see Internal classes. --- Client.Tests/Client.Tests.csproj | 3 ++ .../Core/Compression/JpgCompressionTests.cs | 27 ++++++++++++++ Client.Tests/Core/Encryption/AES.Tests.cs | 35 +++++++++++++++++-- Client.Tests/Core/Information/GeoIPTests.cs | 23 ++++++++++++ Client/Properties/AssemblyInfo.cs | 2 ++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 Client.Tests/Core/Compression/JpgCompressionTests.cs create mode 100644 Client.Tests/Core/Information/GeoIPTests.cs diff --git a/Client.Tests/Client.Tests.csproj b/Client.Tests/Client.Tests.csproj index 45ae9808..48a8d01c 100644 --- a/Client.Tests/Client.Tests.csproj +++ b/Client.Tests/Client.Tests.csproj @@ -39,6 +39,7 @@ 3.5 + @@ -53,8 +54,10 @@ + + diff --git a/Client.Tests/Core/Compression/JpgCompressionTests.cs b/Client.Tests/Core/Compression/JpgCompressionTests.cs new file mode 100644 index 00000000..59235f35 --- /dev/null +++ b/Client.Tests/Core/Compression/JpgCompressionTests.cs @@ -0,0 +1,27 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using xClient.Core.Compression; +using xClient.Core.Helper; + +namespace xClient.Tests.Core.Compression +{ + [TestClass] + public class JpgCompressionTests + { + [TestMethod] + public void EncryptAndDecryptStringTest() + { + var quality = Int64.MaxValue; + var jpg = new JpgCompression(quality); + var bitmap = new Bitmap(200, 200); + + var result = jpg.Compress(bitmap); + + Assert.IsNotNull(result); + CollectionAssert.AllItemsAreNotNull(result); + } + } +} \ No newline at end of file diff --git a/Client.Tests/Core/Encryption/AES.Tests.cs b/Client.Tests/Core/Encryption/AES.Tests.cs index 6c737813..0e72f3d3 100644 --- a/Client.Tests/Core/Encryption/AES.Tests.cs +++ b/Client.Tests/Core/Encryption/AES.Tests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; using xClient.Core.Encryption; using xClient.Core.Helper; @@ -8,7 +9,7 @@ namespace xClient.Tests.Core.Encryption public class AESTests { [TestMethod] - public void EncryptAndDecryptTest() + public void EncryptAndDecryptStringTest() { var input = Helper.GetRandomName(100); var password = Helper.GetRandomName(50); @@ -21,5 +22,35 @@ public void EncryptAndDecryptTest() Assert.IsTrue(input == decrypted); } + + [TestMethod] + public void EncryptAndDecryptByteArrayTest() + { + var input = Helper.GetRandomName(100); + var inputByte = GetBytes(input); + + var password = Helper.GetRandomName(50); + var passwordByte = GetBytes(password); + var encrypted = AES.Encrypt(inputByte, passwordByte); + + Assert.IsNotNull(encrypted); + Assert.AreNotEqual(encrypted, input); + + var decrypted = AES.Decrypt(encrypted, passwordByte); + + //The decryption method is adding on 9 blank bytes. + var realDecrypted = decrypted.Take(200).ToArray(); + + CollectionAssert.AreEqual(inputByte,realDecrypted); + } + + + private static byte[] GetBytes(string str) + { + byte[] bytes = new byte[str.Length * sizeof(char)]; + System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); + return bytes; + } + } } \ No newline at end of file diff --git a/Client.Tests/Core/Information/GeoIPTests.cs b/Client.Tests/Core/Information/GeoIPTests.cs new file mode 100644 index 00000000..fea49649 --- /dev/null +++ b/Client.Tests/Core/Information/GeoIPTests.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.CompilerServices; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using xClient.Core.Information; + + +namespace xClient.Tests.Core.Information +{ + [TestClass] + public class GeoIPTests + { + [TestMethod] + public void EncryptAndDecryptStringTest() + { + var ipInformation = new GeoIP(); + Assert.IsNotNull(ipInformation.City); + Assert.IsNotNull(ipInformation.Country); + Assert.IsNotNull(ipInformation.CountryCode); + Assert.IsNotNull(ipInformation.Region); + Assert.IsNotNull(ipInformation.WanIp); + } + } +} \ No newline at end of file diff --git a/Client/Properties/AssemblyInfo.cs b/Client/Properties/AssemblyInfo.cs index 959db35f..2122f939 100644 --- a/Client/Properties/AssemblyInfo.cs +++ b/Client/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden @@ -12,6 +13,7 @@ [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +[assembly: InternalsVisibleTo("Client.Tests")] // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von