public async Task GivenAFileWriteThenDeleteMultipleTimesVerifyDoesNotExist() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); a.Delete(log, CancellationToken.None); await a.Write(new JObject(), log, CancellationToken.None); a.Delete(log, CancellationToken.None); await a.Write(new JObject(), log, CancellationToken.None); await a.Write(new JObject(), log, CancellationToken.None); await a.Write(new JObject(), log, CancellationToken.None); a.Delete(log, CancellationToken.None); a.HasChanges.Should().BeTrue(); cache.Root.GetFiles().Should().BeEmpty(); await fileSystem.Commit(log, CancellationToken.None); var path = Path.Combine(target, "a.txt"); File.Exists(path).Should().BeFalse(); } }
public async Task GivenThatICreateAndDeleteAFileInTheSameSessionVerifyItIsRemoved() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); a.Delete(log, CancellationToken.None); await fileSystem.Commit(log, CancellationToken.None); File.Exists(a.RootPath.LocalPath).Should().BeFalse("the file was deleted"); } }
public async Task GivenAFileChangeVerifyCommitSetsHasChangesFalse() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); a.HasChanges.Should().BeTrue(); cache.Root.GetFiles().Length.Should().Be(1); await fileSystem.Commit(log, CancellationToken.None); a.HasChanges.Should().BeFalse(); cache.Root.GetFiles().Length.Should().Be(1); } }
public async Task GivenThatICallGetFilesReturnAKnownFile() { using (var target = new TestFolder()) using (var cache = new LocalCache()) using (var cache2 = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root)); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); await fileSystem.Commit(log, CancellationToken.None); File.Exists(a.RootPath.LocalPath).Should().BeTrue("the file was not deleted yet"); var results = await fileSystem2.GetFiles(log, CancellationToken.None); results.Select(e => Path.GetFileName(e.EntityUri.LocalPath)).ShouldBeEquivalentTo(new[] { "a.txt" }); } }
public async Task GivenAFileExistsVerifyWriteOverWrites() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var path = Path.Combine(target, "a.txt"); File.WriteAllText(path, "."); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); a.HasChanges.Should().BeTrue(); cache.Root.GetFiles().Length.Should().Be(1); await fileSystem.Commit(log, CancellationToken.None); File.ReadAllText(path).Should().StartWith("{"); } }
public async Task GivenThatIDestroyAFeedItIsNowEmpty() { using (var target = new TestFolder()) using (var cache = new LocalCache()) using (var cache2 = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root)); var a = fileSystem.Get("a.txt"); await a.Write(new JObject(), log, CancellationToken.None); await fileSystem.Commit(log, CancellationToken.None); File.Exists(a.RootPath.LocalPath).Should().BeTrue("the file was not deleted yet"); await fileSystem2.Destroy(log, CancellationToken.None); await fileSystem2.Commit(log, CancellationToken.None); Directory.Exists(target).Should().BeFalse("all files were deleted"); } }
public async Task CatalogTest_AddPackageAsync_SupportsWritingMultiplePages() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { // Arrange var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, CatalogPageSize = 1, } }; var catalog = new Catalog(context); var catalogIndex = TemplateUtility.LoadTemplate( "CatalogIndex", DateTimeOffset.UtcNow, fileSystem.BaseURI); await fileSystem.Get("catalog/index.json").Write( JObject.Parse(catalogIndex), log, context.Token); var testPackageA = new TestNupkg("packageA", "1.0.0"); var testPackageB = new TestNupkg("packageB", "1.0.0"); var zipFileA = testPackageA.Save(packagesFolder.Root); var zipFileB = testPackageB.Save(packagesFolder.Root); using (var zipA = new ZipArchive(File.OpenRead(zipFileA.FullName), ZipArchiveMode.Read, false)) using (var zipB = new ZipArchive(File.OpenRead(zipFileB.FullName), ZipArchiveMode.Read, false)) { var inputA = new PackageInput(zipFileA.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false) { NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg"), Zip = zipA, Package = new PackageArchiveReader(zipA) }; var inputB = new PackageInput(zipFileB.FullName, new PackageIdentity("packageB", NuGetVersion.Parse("1.0.0")), false) { NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageB/1.0.0/packageB.1.0.0.nupkg"), Zip = zipB, Package = new PackageArchiveReader(zipB) }; // Act await catalog.AddPackageAsync(inputA); await catalog.AddPackageAsync(inputB); await fileSystem.Commit(context.Log, context.Token); // Assert Assert.True( await fileSystem.Get("catalog/page.0.json").Exists(context.Log, context.Token), "The first catalog page should exist."); Assert.True( await fileSystem.Get("catalog/page.1.json").Exists(context.Log, context.Token), "The second catalog page should exist."); } } }