public void SetAndGetFileTimestampsOnlyAffectSymlink() { string originalFile = GetFullPath("somefile.txt"); File.WriteAllText(originalFile, "Important Data"); string intermediateLink = GetFullPath("someLinkThatWillChange.lnk"); XAssert.IsTrue(FileUtilities.TryCreateSymbolicLink(intermediateLink, originalFile, isTargetFile: true)); var test = new DateTime(2001, 12, 31, 1, 1, 1, DateTimeKind.Utc); FileUtilities.SetFileTimestamps(intermediateLink, new FileTimestamps(test)); var originalTimestamps = FileUtilities.GetFileTimestamps(originalFile); var symlinkTimestamps = FileUtilities.GetFileTimestamps(intermediateLink); // We dont look at last changed and access time as the test process touches the permissions of the output file and // the system indexes the files so the access time changes too! XAssert.AreEqual(test, symlinkTimestamps.CreationTime); XAssert.AreEqual(test, symlinkTimestamps.LastWriteTime); XAssert.AreNotEqual(originalTimestamps.CreationTime, symlinkTimestamps.CreationTime); XAssert.AreNotEqual(originalTimestamps.LastWriteTime, symlinkTimestamps.LastWriteTime); }
public async Task WriteAllBytesCallback() { const string Target = "target"; Usn closeUsn = default(Usn); await FileUtilities.WriteAllBytesAsync( GetFullPath(Target), Encoding.UTF8.GetBytes("Target"), onCompletion : stream => { Usn?maybeCloseUsn = FileUtilities.TryWriteUsnCloseRecordByHandle(stream); XAssert.IsNotNull(maybeCloseUsn); closeUsn = maybeCloseUsn.Value; }); XAssert.IsTrue(File.Exists(GetFullPath(Target))); XAssert.AreEqual("Target", File.ReadAllText(GetFullPath(Target))); XAssert.AreNotEqual(0, closeUsn, "Completion callback skipped"); using (FileStream dest = File.OpenRead(GetFullPath(Target))) { Usn usn = FileUtilities.ReadFileUsnByHandle(dest.SafeFileHandle).Value.Usn; XAssert.AreEqual(closeUsn, usn, "CLOSE usn should have been written during the callback."); } }
public void ReadEarliestUsnRecords() { WithVolumeHandle( volumeHandle => { QueryUsnJournalData journalState = QueryJournal(volumeHandle); byte[] buffer = new byte[4096]; ReadUsnJournalResult readJournalResult = FileUtilities.TryReadUsnJournal(volumeHandle, buffer, journalState.UsnJournalId, startUsn: new Usn(0)); XAssert.AreEqual(ReadUsnJournalStatus.Success, readJournalResult.Status); XAssert.IsFalse(readJournalResult.NextUsn.IsZero); XAssert.IsTrue(readJournalResult.NextUsn >= journalState.FirstUsn); XAssert.AreNotEqual(0, readJournalResult.Records.Count, "It is unlikely that this journal should be empty, since this test's execution has written to the volume."); var firstRecord = readJournalResult.Records.First(); XAssert.IsTrue(firstRecord.Usn == journalState.FirstUsn); XAssert.IsTrue(firstRecord.Usn < readJournalResult.NextUsn); var lastUsn = firstRecord.Usn; foreach (UsnRecord record in readJournalResult.Records.Skip(1)) { XAssert.IsTrue(record.Usn > lastUsn, "Expected USNs to be monotically increasing."); lastUsn = record.Usn; XAssert.IsTrue(record.Usn >= journalState.FirstUsn); XAssert.IsTrue(record.Usn < readJournalResult.NextUsn); } }); }
public void TestBasicIdentity() { string fullAPath = WriteFile(TestFileAName, TestFileAName); string fullBPath = WriteFile(TestFileBName, TestFileBName); using (var streamA = File.Open(fullAPath, FileMode.Open)) using (var streamB = File.Open(fullBPath, FileMode.Open)) { var idA = VersionedFileIdentity.TryQuery(streamA.SafeFileHandle); var idB = VersionedFileIdentity.TryQuery(streamB.SafeFileHandle); XAssert.IsTrue(idA.Succeeded); XAssert.IsTrue(idB.Succeeded); XAssert.AreEqual(idA.Result.VolumeSerialNumber, idB.Result.VolumeSerialNumber); XAssert.AreNotEqual( idA.Result.FileId, idB.Result.FileId, I($"FileID for {TestFileAName}: {idA.Result.FileId.ToString()} -- FileID for {TestFileBName}: {idB.Result.FileId.ToString()}")); if (OperatingSystemHelper.IsUnixOS) { // Due to precision, A & B may have the same version. XAssert.IsTrue(idA.Result.Usn <= idB.Result.Usn); } else { XAssert.AreNotEqual(idA.Result.Usn, idB.Result.Usn); XAssert.IsTrue(idA.Result.Usn < idB.Result.Usn); } } }
public void DirectoryAndFileSerialsAgree() { XAssert.IsTrue(Directory.Exists(TemporaryDirectory)); SafeFileHandle directoryHandle = OpenTemporaryDirectory(); using (directoryHandle) { using (FileStream fileStream = File.Create(GetFullPath("Junk"))) { uint directoryShortSerial = FileUtilities.GetShortVolumeSerialNumberByHandle(directoryHandle); XAssert.AreNotEqual(0, directoryShortSerial, "A volume serial of zero (volume handle) is very unlikely"); uint fileShortSerial = FileUtilities.GetShortVolumeSerialNumberByHandle(fileStream.SafeFileHandle); XAssert.AreNotEqual(0, fileShortSerial, "File reports a volume short serial of zero (unlikely), and this disagrees with the volume serial"); XAssert.AreEqual(directoryShortSerial, fileShortSerial, "File and volume short serials disagree"); ulong directorySerial = FileUtilities.GetVolumeSerialNumberByHandle(directoryHandle); XAssert.AreEqual(directoryShortSerial, unchecked ((uint)directorySerial), "Directory long and short serials disagree"); ulong fileSerial = FileUtilities.GetVolumeSerialNumberByHandle(fileStream.SafeFileHandle); XAssert.AreEqual(fileShortSerial, unchecked ((uint)fileSerial), "File long and short serials disagree"); } } }
public void TestPipOutputFingerprinting(FileExistence existence, FileExistence anotherExistence) { // Arrange var pathTable = m_context.PathTable; var executable = FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, X("/x/pkgs/tool.exe"))); AbsolutePath outputPath = AbsolutePath.Create(pathTable, X("/x/obj/working/out.bin")); FileArtifactWithAttributes output = new FileArtifactWithAttributes(outputPath, rewriteCount: 1, fileExistence: existence); Process process = DefaultBuilder.WithOutputs(output).Build(); Process processSecondVersion = DefaultBuilder.WithOutputs(output.CreateNextWrittenVersion()).Build(); var outputWithDifferenceExistence = new FileArtifactWithAttributes(outputPath, rewriteCount: 1, fileExistence: anotherExistence); var processWithDifferenceExistence = DefaultBuilder.WithOutputs(outputWithDifferenceExistence).Build(); var fingerprinter = CreateFingerprinter(executable); // Act var fingerprint = fingerprinter.ComputeFingerprint(process); // Assert XAssert.AreEqual(fingerprint, fingerprinter.ComputeFingerprint(processSecondVersion), "RewriteCount should not affect the fingerprint"); XAssert.AreNotEqual(fingerprint, fingerprinter.ComputeFingerprint(processWithDifferenceExistence), "Two process with the same output path but with different attributes should produce different fingerprints"); }
public void ValidateTempDirectoryCleaned(int tempArtifactType) { FileArtifact src = CreateSourceFile(); FileArtifact tempOut = CreateOutputFileArtifact(TempRoot); // Produces file, which is not listed as output, in temporary directory var ops = new Operation[] { Operation.ReadFile(src), Operation.WriteFile(tempOut, doNotInfer: true), // appends random content Operation.WriteFile(tempOut, System.Environment.NewLine, doNotInfer: true), // append new line Operation.WriteFile(CreateOutputFileArtifact()) }; Process pip = CreateAndScheduleTempDirProcess(ops, tempArtifactType, TempRootPath, tempOut.Path); RunScheduler().AssertCacheMiss(pip.PipId); RunScheduler().AssertCacheHit(pip.PipId); // Store output to compare string[] outA = File.ReadAllLines(ArtifactToString(tempOut)); XAssert.IsTrue(outA.Length == 1); // Trigger cache miss File.WriteAllText(ArtifactToString(src), "src"); RunScheduler().AssertCacheMiss(pip.PipId); // Store output to compare string[] outB = File.ReadAllLines(ArtifactToString(tempOut)); XAssert.IsTrue(outB.Length == 1); // If temp folder was cleaned correctly between runs, outA and outB will be different XAssert.AreNotEqual(outA[0], outB[0]); }
/// <summary> /// To be "changed", a node must have the same name, but different values. /// </summary> private void AssertChanged(string propertyName, ChangeList <JsonNode> changeList) { JsonNode removed = null; JsonNode added = null; for (int i = 0; i < changeList.Count; ++i) { var change = changeList[i]; if (change.Value.Name != propertyName) { continue; } switch (change.ChangeType) { case ChangeList <JsonNode> .ChangeType.Removed: removed = change.Value; break; case ChangeList <JsonNode> .ChangeType.Added: added = change.Value; break; } } XAssert.AreNotEqual(null, removed); XAssert.AreNotEqual(null, added); XAssert.AreNotEqual(removed, added); }
private void VerifyDestinationVersion(ConditionalUpdateResult updateResult, VersionedFileIdentityAndContentInfo originalDestinationInfo) { if (!updateResult.Elided) { XAssert.AreNotEqual( originalDestinationInfo.FileContentInfo.Hash, updateResult.DestinationInfo.FileContentInfo.Hash, "The copy / write should have changed the hash"); XAssert.AreNotEqual(originalDestinationInfo.FileContentInfo, updateResult.DestinationInfo.FileContentInfo); XAssert.AreNotEqual( originalDestinationInfo.Identity.ToWeakIdentity(), updateResult.DestinationInfo.Identity.ToWeakIdentity(), "Expected an identity change due to the copy"); XAssert.AreNotEqual(originalDestinationInfo, updateResult.DestinationInfo); } else { XAssert.AreEqual(originalDestinationInfo.FileContentInfo.Hash, updateResult.DestinationInfo.FileContentInfo.Hash); XAssert.AreEqual(originalDestinationInfo.FileContentInfo, updateResult.DestinationInfo.FileContentInfo); XAssert.AreEqual( originalDestinationInfo.Identity.ToWeakIdentity(), updateResult.DestinationInfo.Identity.ToWeakIdentity(), "Expected identity to stay the same due to copy / write elision"); } }
public void TestStashingAndUnstashing(RepoConfig repoCfg) { using var helper = Clone(repoCfg); var file = helper.GetPath(@"src\files\changingFile.txt"); XAssert.FileExists(file); TestOutput.WriteLine("Modifying file: " + file); File.AppendAllText(file, "hi"); var modifiedContent = File.ReadAllText(file); var result = helper.TrackPath(file); XAssert.AreEqual(PathExistence.ExistsAsFile, result.Existence); // stash changes, assert that 'Change' or 'Delete' USN entry was recorded helper.Git("stash"); helper.SnapCheckPoint(); XAssert.AreNotEqual(modifiedContent, File.ReadAllText(file)); helper.AssertDeleteOrChangeFile(file); // unfortunately, GVFS projection seems to change even though it probably shoudn't // helper.AssertNoChange(helper.GetGvfsProjectionFilePath()); // must re-track the same path because now it could be a different physical file helper.TrackPath(file); // unstash changes, assert that 'Change' or 'Delete' USN entry was recorded and that GVFS projection hasn't changed helper.Git("stash pop"); helper.SnapCheckPoint(); XAssert.AreEqual(modifiedContent, File.ReadAllText(file)); helper.AssertDeleteOrChangeFile(file); // unfortunately, GVFS projection seems to change even though it probably shouldn't // helper.AssertNoChange(helper.GetGvfsProjectionFilePath()); }
public void TestBuildManifestDataHashCodes() { List <BuildManifestFile> outputs0 = new List <BuildManifestFile>(); outputs0.Add(new BuildManifestFile("relativePath", "vsohash", "sha256Hash")); BuildManifestData data0 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs0); int hashCode0 = data0.GetHashCode(); List <BuildManifestFile> outputs1 = new List <BuildManifestFile>(); outputs1.Add(new BuildManifestFile("relativePath", "vsohash", "sha256Hash")); BuildManifestData data1 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs1); int hashCode1 = data1.GetHashCode(); XAssert.AreEqual(hashCode0, hashCode1); XAssert.AreEqual(data0, data1); List <BuildManifestFile> outputs2 = new List <BuildManifestFile>(); outputs2.Add(new BuildManifestFile("relativePath2", "vsohash", "sha256Hash")); BuildManifestData data2 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs2); XAssert.AreNotEqual(data0, data2); }
public async Task CopyIfContentMismatchedAsyncWithMismatchedDestination() { const string TargetContent = "Target!!!!!!!!!"; var fileContentTable = FileContentTable.CreateNew(); WriteFile(FileA, TargetContent); WriteFile(FileB, "Nope"); FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin sourceInfo = await fileContentTable.GetAndRecordContentHashAsync(GetFullPath(FileA)); XAssert.AreEqual(FileContentTableExtensions.ContentHashOrigin.NewlyHashed, sourceInfo.Origin); FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin targetInfo = await fileContentTable.GetAndRecordContentHashAsync(GetFullPath(FileB)); XAssert.AreEqual(FileContentTableExtensions.ContentHashOrigin.NewlyHashed, targetInfo.Origin); XAssert.AreNotEqual( sourceInfo.VersionedFileIdentityAndContentInfo.FileContentInfo.Hash, targetInfo.VersionedFileIdentityAndContentInfo.FileContentInfo.Hash); await VerifyCopyIfContentMismatchedAsync( fileContentTable, FileA, FileB, sourceInfo.VersionedFileIdentityAndContentInfo.FileContentInfo, expectedCopy : true, originalDestinationInfo : targetInfo.VersionedFileIdentityAndContentInfo); }
public async Task CreateEmptyCache() { const string TestName = nameof(CreateEmptyCache); string testCacheId = MakeCacheId(TestName); ICache cache = await CreateCacheAsync(testCacheId); XAssert.AreNotEqual(default(Guid), cache.CacheGuid); if (ImplementsTrackedSessions) { foreach (var sessions in cache.EnumerateCompletedSessions()) { XAssert.Fail("There should not be any sessions in this cache!"); } } // Check that a second cache does not have the same GUID string testCacheId2 = testCacheId + "Two"; ICache cache2 = await CreateCacheAsync(testCacheId2); XAssert.AreNotEqual(cache.CacheGuid, cache2.CacheGuid); await ShutdownCacheAsync(cache2, testCacheId2); await ShutdownCacheAsync(cache, testCacheId); }
public void ChangeFileWithMaterialization(RepoConfig repoCfg) { using var helper = Clone(repoCfg); // track an existing file var file = helper.GetPath(@"src\files\changingFile.txt"); var result = helper.TrackPath(file); XAssert.AreEqual(PathExistence.ExistsAsFile, result.Existence); var oldContent = File.ReadAllText(file); // switch to a new branch where that file is modified using var reseter = helper.GitCheckout("changingFile1"); // materialize the file (by probing it) before snapping USN entries helper.AssertFileOnDisk(file); helper.SnapCheckPoint(); // assert that the file exists and has different content in the new branch XAssert.FileExists(file); XAssert.AreNotEqual(oldContent, File.ReadAllText(file)); // assert that the journal recorded a change // (it doesn't matter to us whether that change is 'Delete' or 'Change') helper.AssertDeleteOrChangeFile(file); }
public void ChangeFile(RepoConfig repoCfg) { using var helper = Clone(repoCfg); // track an existing file var file = helper.GetPath(@"src\files\changingFile.txt"); XAssert.FileExists(file); var oldContent = File.ReadAllText(file); helper.TrackPath(file); // switch to a new branch where that file is modified using var reseter = helper.GitCheckout("changingFile1"); // snap USN entries before doing any checks (because they can modify the journal too) helper.SnapCheckPoint(); // assert that the file exists and has different content in the new branch XAssert.FileExists(file); XAssert.AreNotEqual(oldContent, File.ReadAllText(file)); // assert that the journal recorded a change // (it doesn't matter to us whether that change is 'Delete' or 'Change') helper.AssertDeleteOrChangeFile(file); }
public async Task TryLoadContentWithSomeButNotAllAvailable() { ContentHash availableHash = await AddContent("Very useful data"); ContentHash unavailableHash = HashContent("If only we had this"); ContentHash alsoAvailableHash = await AddContent("Even more very useful data"); XAssert.AreNotEqual(availableHash, unavailableHash); XAssert.AreNotEqual(availableHash, alsoAvailableHash); XAssert.AreNotEqual(alsoAvailableHash, unavailableHash); Possible <ContentAvailabilityBatchResult> possiblyLoaded = await ContentCache.TryLoadAvailableContentAsync(new List <ContentHash>() { availableHash, unavailableHash, alsoAvailableHash }); XAssert.IsTrue(possiblyLoaded.Succeeded); ContentAvailabilityBatchResult result = possiblyLoaded.Result; XAssert.IsFalse(result.AllContentAvailable); XAssert.AreEqual(3, result.Results.Length); XAssert.IsTrue(result.Results[0].IsAvailable); XAssert.AreEqual(availableHash, result.Results[0].Hash); XAssert.IsFalse(result.Results[1].IsAvailable); XAssert.AreEqual(unavailableHash, result.Results[1].Hash); XAssert.IsTrue(result.Results[2].IsAvailable); XAssert.AreEqual(alsoAvailableHash, result.Results[2].Hash); }
public void DBEventCountVerification() { Configuration.Logging.LogExecution = true; var fileOne = FileArtifact.CreateOutputFile(Combine(TestDirPath, "foo.txt")); var fileTwo = FileArtifact.CreateOutputFile(Combine(TestDirPath, "bar.txt")); var dirOne = Path.Combine(ReadonlyRoot, "baz"); Directory.CreateDirectory(dirOne); File.WriteAllText(Path.Combine(dirOne, "abc.txt"), "text"); File.WriteAllText(Path.Combine(dirOne, "xyz.txt"), "text12"); var pipA = CreateAndSchedulePipBuilder(new[] { Operation.WriteFile(fileOne), }).Process; var pipB = CreateAndSchedulePipBuilder(new[] { Operation.WriteFile(fileTwo), }).Process; var pipC = CreateAndSchedulePipBuilder(new[] { Operation.ReadFile(fileOne), Operation.WriteFile(CreateOutputFileArtifact()) }).Process; var pipD = CreateAndSchedulePipBuilder(new[] { Operation.EnumerateDir(new DirectoryArtifact(AbsolutePath.Create(Context.PathTable, dirOne), 0, false)), Operation.WriteFile(CreateOutputFileArtifact()) }).Process; var buildA = RunScheduler().AssertSuccess(); var analyzerRes = RunAnalyzer(buildA).AssertSuccess(); var dataStore = new XldbDataStore(storeDirectory: OutputDirPath.ToString(Context.PathTable)); // As per Mike's offline comment, non-zero vs zero event count tests for now until we can rent out some mac machines // and figure out the true reason why the windows and mac event log counts differ by so much // For these tests, there should be a non-zero number of events logged XAssert.AreNotEqual(0, dataStore.GetFileArtifactContentDecidedEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetPipExecutionPerformanceEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetDirectoryMembershipHashedEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetProcessExecutionMonitoringReportedEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetProcessFingerprintComputationEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetBuildSessionConfigurationEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetPipExecutionStepPerformanceReportedEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetPipCacheMissEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetStatusReportedEvents().Count()); XAssert.AreNotEqual(0, dataStore.GetBxlInvocationEvents().Count()); // For these tests, there should be no events logged XAssert.AreEqual(0, dataStore.GetPipExecutionDirectoryOutputsEvents().Count()); XAssert.AreEqual(0, dataStore.GetWorkerListEvents().Count()); XAssert.AreEqual(0, dataStore.GetDependencyViolationReportedEvents().Count()); }
public void Empty() { var seg = StringSegment.Empty; XAssert.AreEqual(0, seg.Length); XAssert.IsTrue(seg.IndexOf("AB") < 0); XAssert.AreEqual(seg, seg); XAssert.AreNotEqual(new StringSegment("ABC"), seg); }
public void TestBuildManifestFileHashCodes() { BuildManifestFile file0 = new BuildManifestFile("relativePath", "vsohash", "sha256Hash"); BuildManifestFile file1 = new BuildManifestFile("relativePath", "vsohash", "sha256Hash"); BuildManifestFile file2 = new BuildManifestFile("relativePath2", "vsohash", "sha256Hash"); XAssert.AreEqual(file0.GetHashCode(), file1.GetHashCode()); XAssert.AreEqual(file0, file1); XAssert.AreNotEqual(file0, file2); }
public async Task CorruptionRecovery() { const string TestName = nameof(CorruptionRecovery); string testCacheId = MakeCacheId(TestName); ICache cache = await CreateCacheAsync(testCacheId); string testSessionId = "Session1-" + testCacheId; ICacheSession session = await CreateSessionAsync(cache, testSessionId); // Use the testname to generate a CAS items. CasHash item = (await session.AddToCasAsync(TestName.AsStream())).Success(); // Verify that we can read the content after it was added in // this session since it was pinned using (Stream stream = (await session.GetStreamAsync(item)).Success()) { XAssert.AreEqual(TestName, stream.AsString(), "Failed to read back matching content from cache"); } ValidateContentStatus goodStatus = (await session.ValidateContentAsync(item)).Success(); // We can have implemented ValidateContent and not have a way to test corruption but // we must have implemented ValidateCotent if we have a way to test corruption if (CanTestCorruption || (goodStatus != ValidateContentStatus.NotSupported)) { // We should have returned Ok since the content was not corrupted XAssert.AreEqual(ValidateContentStatus.Ok, goodStatus, "Content should have matched in hash at this point!"); // NoItem should always be valid XAssert.AreEqual(ValidateContentStatus.Ok, (await session.ValidateContentAsync(CasHash.NoItem)).Success(), "NoItem should always be valid!"); // Now, only if we can test corruption (which requires that we can corrupt an item) // do we go down this next path if (CanTestCorruption) { await CorruptCasEntry(cache, item); using (Stream stream = (await session.GetStreamAsync(item)).Success()) { XAssert.AreNotEqual(TestName, stream.AsString(), "Failed to corrupt CAS entry!"); } ValidateContentStatus corruptedStatus = (await session.ValidateContentAsync(item)).Success(); // At this point, caches can do a number of possible things // They can not return OK or NotImplemented (since we already checked that earlier) XAssert.AreNotEqual(ValidateContentStatus.Ok, corruptedStatus, "The item was corrupted - something should have happened"); XAssert.AreNotEqual(ValidateContentStatus.NotSupported, corruptedStatus, "It was implemented a moment earlier"); } } await CloseSessionAsync(session, testSessionId); await ShutdownCacheAsync(cache, testCacheId); }
public void IncorrectSwitchDoesNotFailLogger() { var result = RunMSBuild($"Win32ManifestFile='does/not/exist'", out string standardOutput); // The run should fail XAssert.AreNotEqual(0, result); // The reason should be because an unexpected task attribute (MSB4064), but not because of a logger failure XAssert.ContainsNot(standardOutput, "InvalidOperationException"); XAssert.Contains(standardOutput, "MSB4064"); }
public void TestPartialSealDirectoryMembersAffectFingerprints() { ContentFingerprint fingerprint1 = CreateFingerprintForPartialSealWithMember("f.txt"); ContentFingerprint fingerprint2 = CreateFingerprintForPartialSealWithMember("f.txt"); XAssert.AreEqual(fingerprint1, fingerprint2); fingerprint1 = CreateFingerprintForPartialSealWithMember("f.txt"); fingerprint2 = CreateFingerprintForPartialSealWithMember("g.txt"); XAssert.AreNotEqual(fingerprint1, fingerprint2); }
public void TryRemoveDirectory() { string rootDir = GetFullPath("Directory"); Directory.CreateDirectory(rootDir); Directory.CreateDirectory(Path.Combine(rootDir, "subdir1")); int hresult; XAssert.IsFalse(FileUtilities.TryRemoveDirectory(rootDir, out hresult)); XAssert.AreNotEqual(0, hresult); }
public void Empty() { RunForEncoding(isAscii => { var seg = StringSegment.Empty; XAssert.AreEqual(0, seg.Length); XAssert.IsTrue(seg.IndexOf("AB") < 0); XAssert.AreEqual(seg, seg); XAssert.AreNotEqual(CreateSegment("ABC", isAscii), seg); }); }
public void CanOpenDirectoryAndGetShortSerial() { XAssert.IsTrue(Directory.Exists(TemporaryDirectory)); SafeFileHandle directoryHandle = OpenTemporaryDirectory(); using (directoryHandle) { uint serial = FileUtilities.GetShortVolumeSerialNumberByHandle(directoryHandle); XAssert.AreNotEqual(0, serial, "A volume serial of zero is very unlikely"); } }
public void TestCompositeSharedOpaqueMembersAffectFingerprints() { ContentFingerprint fingerprint1 = CreateFingerprintForCompositeSharedOpaque(@"\\root", @"\\root\so1", @"\\root\so2"); ContentFingerprint fingerprint2 = CreateFingerprintForCompositeSharedOpaque(@"\\root", @"\\root\so1", @"\\root\so2"); XAssert.AreEqual(fingerprint1, fingerprint2); fingerprint1 = CreateFingerprintForCompositeSharedOpaque(@"\\root", @"\\root\so1", @"\\root\so2"); fingerprint2 = CreateFingerprintForCompositeSharedOpaque(@"\\root", @"\\root\so1", @"\\root\so3"); XAssert.AreNotEqual(fingerprint1, fingerprint2); }
public void TestVolumeFileSystemName() { var file = GetFullPath(nameof(TestVolumeFileSystemName)); File.WriteAllText(file, nameof(TestVolumeFileSystemName)); using (var stream = FileUtilities.CreateFileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { FileSystemType fsType = FileUtilities.GetVolumeFileSystemByHandle(stream.SafeFileHandle); XAssert.AreNotEqual(FileSystemType.Unknown, fsType); } }
public void Test() { string root = Path.Combine(TemporaryDirectory, "testDeployment"); Directory.CreateDirectory(root); File.WriteAllText( Path.Combine(root, TestServerManifestName), @"included1.dll included1.pdb excluded1.txt subdir" + Path.DirectorySeparatorChar + "included2.exe" + Environment.NewLine + AppDeployment.BuildXLBrandingManifestFileName); File.WriteAllText(Path.Combine(root, "included1.dll"), "test"); // Include pdbs to aid with call stacks when debugging File.WriteAllText(Path.Combine(root, "included1.pdb"), "test"); File.WriteAllText(Path.Combine(root, "excluded1.txt"), "test"); File.WriteAllText(Path.Combine(root, "excluded2.dll"), "test"); File.WriteAllText(Path.Combine(root, AppDeployment.BuildXLBrandingManifestFileName), "test"); Directory.CreateDirectory(Path.Combine(root, "subdir")); File.WriteAllText(Path.Combine(root, "subdir", "included2.exe"), "test"); // Create an initial app deployment and verify it is correct AppDeployment deployment = AppDeployment.ReadDeploymentManifest(root, TestServerManifestName); // Verify the file count. PDB files should only be included for the server deployment. XAssert.AreEqual(4, deployment.GetRelevantRelativePaths(forServerDeployment: true).Count()); XAssert.AreEqual(3, deployment.GetRelevantRelativePaths(forServerDeployment: false).Count()); Fingerprint originalHash = deployment.TimestampBasedHash; // Now mess with files that should not impact the state and make sure they are excluded // This file is excluded because of the extension. It is in the manifest UpdateFile(Path.Combine(root, "excluded1.txt")); // This file is excluded because it isn't in the deployment manifest UpdateFile(Path.Combine(root, "excluded2.dll")); AppDeployment deployment2 = AppDeployment.ReadDeploymentManifest(root, TestServerManifestName); XAssert.AreEqual( deployment.TimestampBasedHash.ToHex(), deployment2.TimestampBasedHash.ToHex()); // Mess with a file that is in the deployment and check that the hash does change UpdateFile(Path.Combine(root, "subdir", "included2.exe")); AppDeployment deployment3 = AppDeployment.ReadDeploymentManifest(root, TestServerManifestName); XAssert.AreNotEqual( deployment.TimestampBasedHash.ToHex(), deployment3.TimestampBasedHash.ToHex()); }
private static async Task Read(AsyncFileStream stream, byte[] buffer, int offset, int count) { int remaining = count; while (remaining > 0) { int read = await stream.ReadAsync(buffer, offset, remaining); XAssert.AreNotEqual(0, read, "Unexpected EOF"); remaining -= read; offset += read; } }
public void TestHistoricDataEquals() { XAssert.AreNotEqual(default(HistoricDataPoint), null); XAssert.AreEqual(default(HistoricDataPoint), default(HistoricDataPoint)); XAssert.AreEqual(default(HistoricDataPoint), new HistoricDataPoint(default(TableStats), default(TableStats), default(TableStats))); XAssert.AreNotEqual(default(HistoricDataPoint), new HistoricDataPoint(default(TableStats), default(TableStats), new TableStats(1, 1))); XAssert.AreNotEqual( new HistoricDataPoint(default(TableStats), new TableStats(1, 1), default(TableStats)), new HistoricDataPoint(default(TableStats), default(TableStats), new TableStats(1, 1))); XAssert.AreEqual( new HistoricDataPoint(default(TableStats), new TableStats(1, 2), new TableStats(3, 4)), new HistoricDataPoint(default(TableStats), new TableStats(1, 2), new TableStats(3, 4))); }