using System; using System.Text; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Linq; using Sarand.Net.Standard.Base.Data; namespace Sacs.UnitTests.Net.Standard.Base.Data { //======================================================================= [TestClass] public class SacsAesIvCrypter_Tester { //------------------------------------------------------------------- // Data members. private static Random random = new Random(); //------------------------------------------------------------------- // Construction. public SacsAesIvCrypter_Tester () { } //------------------------------------------------------------------- /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get; set; } //------------------------------------------------------------------- #region Additional test attributes // // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion //------------------------------------------------------------------- [TestMethod] public void SacsAesIvCrypter_Test () { for (int i = 0; i < 200; i++) { String data = RandomString(random.Next(10, 2048), true); int dataLength = data.Length; String key = RandomString(random.Next(10, 128), true); int keyLength = key.Length; String encrypted = SacsAesIvCrypter.Encrypt(data, key); int encryptedLength = encrypted.Length; Assert.AreEqual(data, SacsAesIvCrypter.Decrypt(encrypted, key)); } } //------------------------------------------------------------------- /// Generate random alphanumeric string public static String RandomString (int length, bool includeLowerCase = true, bool includeSymbols = true) { String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; if (includeLowerCase) chars += "abcdefghijklmnopqrstuvwxyz"; if (includeSymbols) chars += "`¬!\"£$%^&*()-=_+{}[];:'@#~<>?/.,\\| "; return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); } //------------------------------------------------------------------- } //======================================================================= }