Added more tests, added an InteralVisibleTo property into the Assembly so we would see Internal classes.

This commit is contained in:
Jamie Rees 2015-05-13 21:22:35 +01:00
parent e4c8ef7374
commit bf842c5ec2
5 changed files with 88 additions and 2 deletions

View File

@ -39,6 +39,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -53,8 +54,10 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Core\Compression\JpgCompressionTests.cs" />
<Compile Include="Core\Encryption\AES.Tests.cs" />
<Compile Include="Core\Encryption\SHA256.Tests.cs" />
<Compile Include="Core\Information\GeoIPTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -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);
}
}
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}
}

View File

@ -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