예제 #1
0
        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");
        }
예제 #2
0
        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");
        }
예제 #3
0
        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");
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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")));
        }
예제 #7
0
        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));
        }