public void GetFileHash_FailsForMissingFile() { GetFileHash task = new GetFileHash { Files = new[] { new TaskItem(Path.Combine(AppContext.BaseDirectory, "this_does_not_exist.txt")) }, BuildEngine = _mockEngine, }; task.Execute().ShouldBeFalse(); _mockEngine.Log.ShouldContain("MSB3954"); }
public void GetFileHash_FailsForUnknownHashEncoding() { GetFileHash task = new GetFileHash { Files = new[] { new TaskItem(TestBinary.LoremFilePath) }, BuildEngine = _mockEngine, HashEncoding = "blue", }; task.Execute().ShouldBeFalse(); _mockEngine.Log.ShouldContain("MSB3951"); }
public void GetFileHash_FailsForUnknownAlgorithmName() { GetFileHash task = new GetFileHash { Files = new[] { new TaskItem(TestBinary.LoremFilePath) }, BuildEngine = _mockEngine, Algorithm = "BANANA", }; task.Execute().ShouldBeFalse(); _mockEngine.Log.ShouldContain("MSB3953"); }
public void ComputesFileChecksum(string algoritm, string hash) { var task = new GetFileHash { Files = new[] { new TaskItem(Path.Combine(AppContext.BaseDirectory, "TestResources", "lorem.bin")) }, BuildEngine = new MockEngine(), Algorithm = algoritm, }; Assert.True(task.Execute(), "Task should pass"); Assert.Equal(hash, task.Hash); }
public void GetFileHash_ComputesCorrectChecksumForOneFile(TestBinary testBinary) { GetFileHash task = new GetFileHash { Files = new[] { new TaskItem(testBinary.FilePath) }, BuildEngine = _mockEngine, Algorithm = testBinary.HashAlgorithm, HashEncoding = testBinary.HashEncoding, }; task.Execute().ShouldBeTrue(); task.Hash.ShouldBe(testBinary.FileHash); }
public void ComputesFileChecksumInGroup(string algoritm, string hash) { var task = new GetFileHash { Files = new[] { new TaskItem(Path.Combine(AppContext.BaseDirectory, "TestResources", "lorem.bin")), new TaskItem(Path.Combine(AppContext.BaseDirectory, "TestResources", "lorem.bin")), }, BuildEngine = new MockEngine(), Algorithm = algoritm, }; Assert.True(task.Execute(), "Task should pass"); Assert.Equal(2, task.Items.Length); Assert.All(task.Items, i => Assert.Equal(hash, i.GetMetadata("FileHash"))); }
public void GetFileHash_ComputesCorrectChecksumForManyFiles(TestBinary testBinary) { GetFileHash task = new GetFileHash { Files = new[] { new TaskItem(testBinary.FilePath), new TaskItem(testBinary.FilePath), }, BuildEngine = _mockEngine, Algorithm = testBinary.HashAlgorithm, HashEncoding = testBinary.HashEncoding, }; task.Execute().ShouldBeTrue(); task.Items.Length.ShouldBe(2); task.Items.ShouldAllBe(i => string.Equals(testBinary.FileHash, i.GetMetadata("FileHash"), StringComparison.Ordinal)); }