Using temp1 As New TempFile()
    Using temp2 As New TempFile()
        Dim options As var = New TransactedCompoundFile.Options(temp1.TempPath) With { _
            Key .BlockSize = 512 _
        }
        Const  count As Integer = 4
        Dim sample1 As Byte() = New Byte(options.MaxWriteSize / 3) {}
        Dim sample2 As Byte() = DirectCast(sample1.Clone(), Byte())
        New Random().NextBytes(sample1)
        New Random().NextBytes(sample2)
        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                Assert.AreEqual(h, file.Create())
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
            Dim h As UInteger = 1UI
            While h < count
                file.Write(h, sample1, 0, sample1.Length)
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
            file.Commit()
            'persist.
            Dim h As UInteger = 1UI
            While h < count
                file.Write(h, sample2, 0, sample2.Length)
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
            file.Commit(Function(x) temp1.CopyTo(temp2.TempPath, True), 0)
        End Using
        options = New TransactedCompoundFile.Options(temp2.TempPath) With { _
            Key .BlockSize = 512, _
            Key .CommitOnDispose = False _
        }
        'Verify primary has sample2 data
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary
        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                CompareBytes(sample2, 0, sample2.Length, IOStream.ReadAllBytes(file.Read(h)))
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
        End Using
        'Verify secondary has sample1 data
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary
        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                CompareBytes(sample1, 0, sample1.Length, IOStream.ReadAllBytes(file.Read(h)))
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
        End Using
    End Using
End Using |