public void HashValidationFailsIfSomeEntryIsAbsent() { var directoryHash1 = new DirectoryHash(location); directoryHash1.Save(); var sb = new StringBuilder(); string directoryHashFile = Path.Combine(location, "directory.hash"); using (var sr = new StreamReader(directoryHashFile)) { var index = 0; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (index != 1) { sb.AppendLine(line); } index++; } } using (var sw = new StreamWriter(directoryHashFile)) { sw.Write(sb.ToString()); } var directoryHash = new DirectoryHash(location); Assert.Throws<HashValidationException>(directoryHash.Validate); }
public void HashIsValidatedIfNothingWasChanged() { var directoryHash = new DirectoryHash(location); directoryHash.Save(); var directoryHash2 = new DirectoryHash(location); directoryHash2.Validate(); }
/// <summary> /// Runs the task. /// </summary> /// <returns> /// true if successful; otherwise, false. /// </returns> public override bool Execute() { IList<string> filesToIgnore = null; IEnumerable<string> mandatoryFilesWithAnyContent = null; if (FilesToIgnore != null) filesToIgnore = FilesToIgnore.Select(item => item.ItemSpec).ToList(); if (FilesWithAnyContents != null) mandatoryFilesWithAnyContent = FilesWithAnyContents.Select(item => item.ItemSpec); var directoryHash = new DirectoryHash(Path, filesToIgnore, mandatoryFilesWithAnyContent); directoryHash.Save(); return true; }
public void HashValidationFailsIfSomeFileIsAbsent() { const string tempFile = "folder2/temp.file"; CreateFile(tempFile); var directoryHash = new DirectoryHash(location); directoryHash.Save(); File.Delete(Path.Combine(location, tempFile)); var directoryHash2 = new DirectoryHash(location); Assert.Throws<HashValidationException>(directoryHash2.Validate); }
public void HashIsSaved() { var directoryHash = new DirectoryHash(location); directoryHash.Save(); Assert.That(File.Exists(Path.Combine(location, "directory.hash"))); }
public void HashValidationSuccedesWhenFileWithChangingContentsAbsents() { CreateFile("optional.contents"); var directoryHash = new DirectoryHash(location, mandatoryFilesWithAnyContent: new[] { "optional.contents" }); directoryHash.Save(); File.Delete(Path.Combine(location, "optional.contents")); var directoryHash2 = new DirectoryHash(location); Assert.Throws<HashValidationException>(directoryHash2.Validate); }
public void HashValidationSuccedesWhenContentsChangesInFileWithChangingContents() { CreateFile("optional.contents"); var directoryHash = new DirectoryHash(location, mandatoryFilesWithAnyContent: new[]{"optional.contents"}); directoryHash.Save(); CreateFile("optional.contents"); var directoryHash2 = new DirectoryHash(location); Assert.DoesNotThrow(directoryHash2.Validate); }
public void HashValidationFailsIfWholeKeyHashIsAbsent() { var directoryHash1 = new DirectoryHash(location); directoryHash1.Save(); var sb = new StringBuilder(); string directoryHashFile = Path.Combine(location, "directory.hash"); using (var sr = new StreamReader(directoryHashFile)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line == null || !line.StartsWith(":::")) { sb.AppendLine(line); } } } using (var sw = new StreamWriter(directoryHashFile)) { sw.Write(sb.ToString()); } var directoryHash = new DirectoryHash(location); Assert.Throws<HashValidationException>(directoryHash.Validate); }
public void HashValidationFailsIfSomeFileIsChanged() { CreateFile("folder2/temp.file"); var directoryHash = new DirectoryHash(location); directoryHash.Save(); // Recreate file with different contents CreateFile("folder2/temp.file"); var directoryHash2 = new DirectoryHash(location); Assert.Throws<HashValidationException>(directoryHash2.Validate); }