public void GenerationIsCorrect() { this.SetupTest("DefaultProjectNotSet"); this.Generate("Windows"); _assert.True(File.Exists(this.GetPath(@"Module.Windows.sln"))); var solutionContents = this.ReadFile(@"Module.Windows.sln"); var consoleAIndex = solutionContents.IndexOf("ConsoleA"); var consoleBIndex = solutionContents.IndexOf("ConsoleB"); _assert.NotEqual(-1, consoleAIndex); _assert.NotEqual(-1, consoleBIndex); _assert.True(consoleAIndex < consoleBIndex, "Console A must appear before Console B"); this.SetupTest("DefaultProjectExplicitlySet"); this.Generate("Windows"); _assert.True(File.Exists(this.GetPath(@"Module.Windows.sln"))); solutionContents = this.ReadFile(@"Module.Windows.sln"); consoleAIndex = solutionContents.IndexOf("ConsoleA"); consoleBIndex = solutionContents.IndexOf("ConsoleB"); _assert.NotEqual(-1, consoleAIndex); _assert.NotEqual(-1, consoleBIndex); _assert.True(consoleBIndex < consoleAIndex, "Console B must appear before Console A"); }
public void TestFilteredPropagationInOrder() { var event1 = new BasicEvent { Original = 1 }; var event2 = new BasicEvent { Original = 2 }; var binder = new FilteredStaticEventBinder(); var engine = new DefaultEventEngine <IGameContext>(new StandardKernel(), new[] { binder }); engine.Fire(null, event1); _staticAssert.Equal(1, event1.HitValue); engine.Fire(null, event2); _staticAssert.NotEqual(2, event2.HitValue); }
public void GenerationIsCorrect() { this.SetupTest("PackageResolutionDoesNotOccurInSubmodulesTwice"); var src = this.SetupSrcPackage(); try { // Make sure the Package directory is removed so we have a clean test every time. if (Directory.Exists(this.GetPath("Package"))) { PathUtils.AggressiveDirectoryDelete(this.GetPath("Package")); } var platform = "Windows"; if (Path.DirectorySeparatorChar == '/') { platform = "Linux"; if (Directory.Exists("/Library")) { platform = "MacOS"; } } var stdout = this.Generate( platform: platform, args: "--redirect http://protobuild.org/hach-que/TestEmptyPackage local-git://" + src, capture: true).Item1; var idxSubmoduleGeneration = stdout.IndexOf("Invoking submodule generation for Submodule", System.StringComparison.InvariantCulture); _assert.NotEqual(-1, idxSubmoduleGeneration); var substrStdout = stdout.Substring(idxSubmoduleGeneration); var idxPackageResolution = substrStdout.IndexOf("Starting resolution of packages for " + platform + "...", System.StringComparison.InvariantCulture); // We should not see any package resolution we invoke submodule generation. _assert.Equal(-1, idxPackageResolution); } finally { PathUtils.AggressiveDirectoryDelete(src); } }
public void ReaderHeader_WithPrivateKey() { using (var options = new SymmetricEncryptionProviderOptions()) using (var engine = new SymmetricEncryptionProvider()) { byte[] privateKey = null; using (var rng = new RandomNumberGenerator()) { privateKey = rng.NextBytes(20); } byte[] data = null; var header1 = engine.GenerateHeader(options, privateKey: privateKey); data = new byte[header1.Bytes.Memory.Length]; header1.Bytes.Memory.CopyTo(data); var ms = new MemoryStream(data); using (var header = engine.ReadHeader(ms, options, privateKey)) { ms.Position = 0; var data2 = new byte[header.Bytes.Memory.Length]; header.Bytes.Memory.CopyTo(data2); assert.Equal(data.Length, data2.Length); assert.Equal(data, data2); assert.NotNull(header); assert.Equal(1, header.Version); assert.Equal(SymmetricAlgorithmType.AES, header.SymmetricAlgorithmType); assert.Equal(KeyedHashAlgorithmType.HMACSHA256, header.KeyedHashAlgorithmType); assert.Equal(0, header.MetaDataSize); assert.NotEqual(0, header.SigningSaltSize); assert.NotEqual(0, header.SymmetricSaltSize); assert.NotEqual(0, header.IvSize); assert.NotEqual(0, header.HashSize); assert.NotEqual(0, header.Iterations); assert.NotNull(header.SymmetricKey); assert.NotNull(header.IV); assert.NotNull(header.SigningKey); assert.NotNull(header.Bytes); assert.Ok(!header.SymmetricKey.Memory.IsEmpty); assert.Ok(!header.IV.Memory.IsEmpty); assert.Ok(!header.SigningKey.Memory.IsEmpty); var temp = new byte[header.SymmetricKey.Memory.Length]; header.SymmetricKey.Memory.CopyTo(temp); assert.NotEqual(privateKey, temp); assert.Ok(!header.Bytes.Memory.IsEmpty); ms.Position = 0; using (var br = new BinaryReader(ms)) { assert.Equal(1, br.ReadInt16()); assert.Equal((short)SymmetricAlgorithmType.AES, br.ReadInt16()); assert.Equal((short)KeyedHashAlgorithmType.HMACSHA256, br.ReadInt16()); assert.Equal(header.MetaDataSize, br.ReadInt32()); assert.Equal(header.Iterations, br.ReadInt32()); assert.Equal(header.SymmetricSaltSize, br.ReadInt16()); assert.Equal(header.SigningSaltSize, br.ReadInt16()); assert.Equal(header.IvSize, br.ReadInt16()); assert.Equal(header.SymmetricKeySize, br.ReadInt16()); assert.Equal(header.HashSize, br.ReadInt16()); assert.Equal(header.Version, header1.Version); assert.Equal(header.KeyedHashAlgorithmType, header1.KeyedHashAlgorithmType); assert.Equal(header.SymmetricAlgorithmType, header1.SymmetricAlgorithmType); assert.Equal(header.MetaDataSize, header1.MetaDataSize); assert.Equal(header.Iterations, header1.Iterations); assert.Equal(header.SymmetricSaltSize, header1.SymmetricSaltSize); assert.Equal(header.SigningSaltSize, header1.SigningSaltSize); assert.Equal(header.IvSize, header1.IvSize); assert.Equal(header.SymmetricKeySize, header1.SymmetricKeySize); assert.Equal(header.HashSize, header1.HashSize); byte[] metadata = null; byte[] symmetricSalt = null; byte[] signingSalt = null; byte[] iv = null; byte[] symmetricKey = null; byte[] hash = null; // header values // 1. version // 2. metadataSize // 3. iterations // 4. symmetricSaltSize // 5. signingSaltSize // 6. ivSize // 7. symmetricKeySize // 8. hashSize // header values // 1. metadata (optional) // 2. symmetricSalt (optional) // 3. signingSalt (optional) // 4. iv // 5. symmetricKey (optional) // 6. hash if (header.MetaDataSize > 0) { metadata = br.ReadBytes(header.MetaDataSize); } if (header.SymmetricSaltSize > 0) { assert.Equal(options.SaltSize / 8, header.SymmetricSaltSize); var name = System.Security.Cryptography.HashAlgorithmName.SHA256; symmetricSalt = br.ReadBytes(header.SymmetricSaltSize); using (var generator = new Rfc2898DeriveBytes(privateKey, symmetricSalt, options.Iterations, name)) { symmetricKey = generator.GetBytes(options.KeySize / 8); var p1 = new byte[header.SymmetricKey.Memory.Length]; var p2 = new byte[header1.SymmetricKey.Memory.Length]; header.SymmetricKey.Memory.CopyTo(p1); header1.SymmetricKey.Memory.CopyTo(p2); assert.Equal(p1, p2); assert.Equal(symmetricKey, p1); } symmetricKey = null; } if (header.SigningSaltSize > 0) { signingSalt = br.ReadBytes(header.SigningSaltSize); var name = System.Security.Cryptography.HashAlgorithmName.SHA256; using (var generator = new Rfc2898DeriveBytes(privateKey, signingSalt, options.Iterations, name)) { var signingKey = generator.GetBytes(options.KeySize / 8); var p1 = new byte[header.SymmetricKey.Memory.Length]; header.SigningKey.Memory.CopyTo(p1); assert.Equal(signingKey, p1); } } if (header.IvSize > 0) { iv = br.ReadBytes(header.IvSize); var iv2 = new byte[header.IvSize]; header.IV.Memory.CopyTo(iv2); assert.Equal(iv, iv2); } if (header.SymmetricKeySize > 0) { symmetricKey = br.ReadBytes(header.SymmetricKeySize); } if (header.HashSize > 0) { hash = br.ReadBytes(header.HashSize); var hash2 = new byte[header.HashSize]; header.Hash.Memory.CopyTo(hash2); assert.Equal(hash, hash2); } assert.Null(metadata); assert.NotNull(hash); assert.NotNull(signingSalt); assert.NotNull(symmetricSalt); // header property has a copy but does not // write it to the file header when a private key // is provided. assert.Null(symmetricKey); assert.NotNull(iv); assert.NotEmpty(hash); assert.NotEmpty(signingSalt); assert.NotEmpty(symmetricSalt); assert.NotEmpty(iv); } } } }
/// <summary> /// Verifies that two sequences are not equivalent, using a custom equality comparer. /// </summary> /// <typeparam name="T">The type of the objects to be compared</typeparam> /// <param name="expected">The expected object</param> /// <param name="actual">The actual object</param> /// <param name="comparer">The comparer used to compare the two objects</param> /// <exception cref="NotEqualException">Thrown when the objects are equal</exception> public static void NotEqual <T>(this IAssert assert, IEnumerable <T> expected, IEnumerable <T> actual, IEqualityComparer <T> comparer) { assert.NotEqual <IEnumerable <T> >(expected, actual, GetEqualityComparer <IEnumerable <T> >(true, new AssertEqualityComparerAdapter <T>(comparer))); }
/// <summary> /// Verifies that two sequences are not equivalent, using a default comparer. /// </summary> /// <typeparam name="T">The type of the objects to be compared</typeparam> /// <param name="expected">The expected object</param> /// <param name="actual">The actual object</param> /// <exception cref="NotEqualException">Thrown when the objects are equal</exception> public static void NotEqual <T>(this IAssert assert, IEnumerable <T> expected, IEnumerable <T> actual) { assert.NotEqual <IEnumerable <T> >(expected, actual, GetEqualityComparer <IEnumerable <T> >(true)); }
/// <summary> /// Verifies that two objects are not equal, using a default comparer. /// </summary> /// <typeparam name="T">The type of the objects to be compared</typeparam> /// <param name="expected">The expected object</param> /// <param name="actual">The actual object</param> /// <exception cref="NotEqualException">Thrown when the objects are equal</exception> public static void NotEqual <T>(this IAssert assert, T expected, T actual) { assert.NotEqual(expected, actual, GetEqualityComparer <T>()); }