private async Task VerifyWriteBytesIfContentMismatchedAsync(
            FileContentTable fileContentTable,
            string targetRelPath,
            string contents,
            bool expectWrite,
            VersionedFileIdentityAndContentInfo?originalDestinationInfo = null)
        {
            byte[]                  encoded      = Encoding.UTF8.GetBytes(contents);
            ContentHash             contentsHash = ContentHashingUtilities.HashBytes(encoded);
            ConditionalUpdateResult result       =
                await fileContentTable.WriteBytesIfContentMismatchedAsync(GetFullPath(targetRelPath), encoded, contentsHash);

            XAssert.AreEqual(expectWrite, !result.Elided, "Decision to write was incorrect.");

            FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin targetInfo =
                await fileContentTable.GetAndRecordContentHashAsync(GetFullPath(targetRelPath));

            XAssert.AreEqual(FileContentTableExtensions.ContentHashOrigin.Cached, targetInfo.Origin, "Write didn't record the target hash.");
            XAssert.AreEqual(
                contentsHash,
                targetInfo.VersionedFileIdentityAndContentInfo.FileContentInfo.Hash,
                "Hashes should match after the write.");
            XAssert.AreEqual(contents, File.ReadAllText(GetFullPath(targetRelPath)), "Hashes match but content does not");

            if (originalDestinationInfo.HasValue)
            {
                VerifyDestinationVersion(result, originalDestinationInfo.Value);
            }
        }
 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");
     }
 }
        private async Task VerifyCopyIfContentMismatchedAsync(
            FileContentTable fileContentTable,
            string sourceRelPath,
            string destRelPath,
            FileContentInfo sourceVersionedHash,
            bool expectedCopy,
            VersionedFileIdentityAndContentInfo?originalDestinationInfo = null)
        {
            ConditionalUpdateResult result =
                await fileContentTable.CopyIfContentMismatchedAsync(GetFullPath(sourceRelPath), GetFullPath(destRelPath), sourceVersionedHash);

            XAssert.AreEqual(expectedCopy, !result.Elided, "Decision to copy or elide was incorrect.");

            FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin targetInfo =
                await fileContentTable.GetAndRecordContentHashAsync(GetFullPath(destRelPath));

            XAssert.AreEqual(FileContentTableExtensions.ContentHashOrigin.Cached, targetInfo.Origin, "Copy didn't record the target hash.");
            XAssert.AreEqual(
                sourceVersionedHash.Hash,
                targetInfo.VersionedFileIdentityAndContentInfo.FileContentInfo.Hash,
                "Hashes should match after the copy.");
            XAssert.AreEqual(
                File.ReadAllText(GetFullPath(sourceRelPath)),
                File.ReadAllText(GetFullPath(destRelPath)),
                "Hashes match but content does not");

            if (originalDestinationInfo.HasValue)
            {
                VerifyDestinationVersion(result, originalDestinationInfo.Value);
            }
        }