Пример #1
0
        public async Task FailsOnNewerVersionOfPackage()
        {
            await CreateAndClosePackage((writer, package) => Task.CompletedTask, new Version(2, 0));

            var file = new DynamicPackageData(new Version(1, 0), this);

            Assert.AreEqual(PackageOpenResultType.IncompatibleVersion, (await file.Open(PackageFilename)).Result);
        }
Пример #2
0
        public async Task ReadOnly_OpensNonExclusiveLock()
        {
            await CreateAndClosePackage((writer, package) => writer.Write(ContentFileName, SampleText));

            await using (File.OpenRead(PackageFilename))
                using (var file = new DynamicPackageData(new Version(1, 0), this))
                {
                    var result = await file.Open(PackageFilename, true);

                    Assert.IsTrue(result.IsSuccessful);
                }

            await using (new FileStream(PackageFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var file = new DynamicPackageData(new Version(1, 0), this))
                {
                    var result = await file.Open(PackageFilename, true);

                    Assert.IsTrue(result.IsSuccessful);
                }

            await using (new FileStream(PackageFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (var file = new DynamicPackageData(new Version(1, 0), this))
                {
                    var result = await file.Open(PackageFilename, true);

                    Assert.IsTrue(result.IsSuccessful);
                }

            await using (new FileStream(PackageFilename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                using (var file = new DynamicPackageData(new Version(1, 0), this))
                {
                    var result = await file.Open(PackageFilename, true);

                    Assert.IsTrue(result.IsSuccessful);
                }

            await using (new FileStream(PackageFilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                using (var file = new DynamicPackageData(new Version(1, 0), this))
                {
                    var result = await file.Open(PackageFilename, true);

                    Assert.IsTrue(result.IsSuccessful);
                }
        }