Example #1
0
        public async Task GivenAS3AccountVerifyBucketOperations()
        {
            using (var testContext = new AmazonS3TestContext())
            {
                testContext.CreateBucketOnInit = false;
                await testContext.InitAsync();

                // Verify at the start
                (await testContext.FileSystem.HasBucket(testContext.Logger, CancellationToken.None)).Should().BeFalse("HasBucket should return false since it does not exist yet");
                (await testContext.FileSystem.Validate(testContext.Logger, CancellationToken.None)).Should().BeFalse("Validate should be false since the bucket does not exist yet");

                // Create
                await testContext.FileSystem.CreateBucket(testContext.Logger, CancellationToken.None);

                var hasBucket = (await testContext.FileSystem.HasBucket(testContext.Logger, CancellationToken.None));
                hasBucket.Should().BeTrue("HasBucket should return true after");
                var valid = (await testContext.FileSystem.Validate(testContext.Logger, CancellationToken.None));
                valid.Should().BeTrue("Validate should be true after");

                // Delete
                await testContext.FileSystem.DeleteBucket(testContext.Logger, CancellationToken.None);

                (await testContext.FileSystem.HasBucket(testContext.Logger, CancellationToken.None)).Should().BeFalse();
                (await testContext.FileSystem.Validate(testContext.Logger, CancellationToken.None)).Should().BeFalse();

                await testContext.CleanupAsync();
            }
        }
Example #2
0
        public async Task GivenAStorageAccountVerifyPushSucceeds()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                {
                    await testContext.InitAsync();

                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);

                    var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                            testContext.FileSystem,
                                                            enableCatalog : true,
                                                            enableSymbols : true,
                                                            log : testContext.Logger,
                                                            token : CancellationToken.None);

                    result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                         testContext.FileSystem,
                                                         new List <string>() { zipFile.FullName },
                                                         force : false,
                                                         skipExisting : false,
                                                         log : testContext.Logger);

                    result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             testContext.Logger);

                    result.Should().BeTrue();

                    await testContext.CleanupAsync();
                }
        }
Example #3
0
        public async Task GivenAStorageAccountWithNoContainerVerifyPushSucceeds()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                {
                    // Skip creation and allow it to be done during push.
                    testContext.CreateBucketOnInit = false;

                    await testContext.InitAsync();

                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);

                    var result = await PushCommand.RunAsync(testContext.LocalSettings,
                                                            testContext.FileSystem,
                                                            new List <string>() { zipFile.FullName },
                                                            force : false,
                                                            skipExisting : false,
                                                            log : testContext.Logger);

                    result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             testContext.Logger);

                    result.Should().BeTrue();

                    await testContext.CleanupAsync();
                }
        }
Example #4
0
        public async Task GivenPushCreatesAnS3BucketVerifyNuGetCanRead()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                    using (var sourceContext = new SourceCacheContext())
                    {
                        // Skip creation and allow it to be done during push.
                        testContext.CreateBucketOnInit = false;
                        await testContext.InitAsync();

                        var testPackage = new TestNupkg("packageA", "1.0.0");
                        var zipFile     = testPackage.Save(packagesFolder.Root);

                        var result = await PushCommand.RunAsync(testContext.LocalSettings,
                                                                testContext.FileSystem,
                                                                new List <string>() { zipFile.FullName },
                                                                force : false,
                                                                skipExisting : false,
                                                                log : testContext.Logger);

                        // Read the feed with NuGet.Protocol
                        var feedIndex = $"{testContext.FileSystem.Root.AbsoluteUri}index.json";
                        var repo      = Repository.Factory.GetCoreV3(feedIndex);
                        var resource  = await repo.GetResourceAsync <FindPackageByIdResource>(CancellationToken.None);

                        var packageResults = (await resource.GetAllVersionsAsync("packageA", sourceContext, NullLogger.Instance, CancellationToken.None)).ToList();
                        packageResults.Count.Should().Be(1);
                        packageResults[0].ToIdentityString().Should().Be("1.0.0");

                        await testContext.CleanupAsync();
                    }
        }
Example #5
0
        public async Task SubFeed_InitMultipleFeedsVerifyDestroyDoesNotModifyOthers()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                    using (var testContext2 = new AmazonS3TestContext())
                    {
                        // Use a subfeed for the filesystem
                        var subFeedName  = "testSubFeedA";
                        var subFeedName2 = "testSubFeedB";
                        var root         = UriUtility.GetPath(testContext.Uri, subFeedName);
                        var root2        = UriUtility.GetPath(testContext.Uri, subFeedName2);
                        testContext.FileSystem  = new AmazonS3FileSystem(testContext.LocalCache, root, root, testContext.Client, testContext.BucketName, feedSubPath: subFeedName);
                        testContext2.FileSystem = new AmazonS3FileSystem(testContext.LocalCache, root2, root2, testContext.Client, testContext.BucketName, feedSubPath: subFeedName2);

                        await testContext.InitAsync();

                        await testContext2.InitAsync();

                        var testPackage = new TestNupkg("packageA", "1.0.0");
                        var zipFile     = testPackage.Save(packagesFolder.Root);

                        var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                                testContext.FileSystem,
                                                                enableCatalog : true,
                                                                enableSymbols : true,
                                                                log : testContext.Logger,
                                                                token : CancellationToken.None);

                        result &= await InitCommand.RunAsync(testContext.LocalSettings,
                                                             testContext2.FileSystem,
                                                             enableCatalog : true,
                                                             enableSymbols : true,
                                                             log : testContext2.Logger,
                                                             token : CancellationToken.None);

                        // Destroy feed2
                        result &= await DestroyCommand.RunAsync(testContext.LocalSettings,
                                                                testContext2.FileSystem,
                                                                testContext2.Logger);

                        // Validate feed1
                        result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                                 testContext.FileSystem,
                                                                 testContext.Logger);


                        result.Should().BeTrue();

                        await testContext.CleanupAsync();

                        await testContext2.CleanupAsync();
                    }
        }
Example #6
0
        public async Task SubFeed_PushAndVerifyNoFilesInRoot()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                {
                    // Use a subfeed for the filesystem
                    var subFeedName = "testSubFeed";
                    var root        = UriUtility.GetPath(testContext.Uri, subFeedName);
                    testContext.FileSystem = new AmazonS3FileSystem(
                        testContext.LocalCache, root, root,
                        testContext.Client, testContext.BucketName,
                        ServerSideEncryptionMethod.None, feedSubPath: subFeedName
                        );

                    await testContext.InitAsync();

                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);

                    var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                            testContext.FileSystem,
                                                            enableCatalog : true,
                                                            enableSymbols : true,
                                                            log : testContext.Logger,
                                                            token : CancellationToken.None);

                    result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                         testContext.FileSystem,
                                                         new List <string>() { zipFile.FullName },
                                                         force : false,
                                                         skipExisting : false,
                                                         log : testContext.Logger);

                    result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             testContext.Logger);

                    result.Should().BeTrue();

                    var files = await AmazonS3FileSystemAbstraction.GetFilesAsync(testContext.Client, testContext.BucketName, CancellationToken.None);

                    files.Where(e => e.Key.IndexOf(subFeedName, StringComparison.OrdinalIgnoreCase) < 0).Should().BeEmpty();
                    files.Where(e => e.Key.IndexOf(subFeedName, StringComparison.OrdinalIgnoreCase) > -1).Should().NotBeEmpty();

                    await testContext.CleanupAsync();
                }
        }
Example #7
0
        public async Task GivenAStorageAccountVerifyPushAndSucceedWithBaseURI()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                {
                    var baseUri    = new Uri("http://tempuri.org/abc/");
                    var fileSystem = new AmazonS3FileSystem(
                        testContext.LocalCache, testContext.Uri, baseUri,
                        testContext.Client, testContext.BucketName, ServerSideEncryptionMethod.None
                        );

                    testContext.FileSystem = fileSystem;

                    await testContext.InitAsync();

                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);

                    var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                            testContext.FileSystem,
                                                            enableCatalog : true,
                                                            enableSymbols : true,
                                                            log : testContext.Logger,
                                                            token : CancellationToken.None);

                    result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                         testContext.FileSystem,
                                                         new List <string>() { zipFile.FullName },
                                                         force : false,
                                                         skipExisting : false,
                                                         log : testContext.Logger);

                    result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             testContext.Logger);

                    result.Should().BeTrue();

                    // Check baseURIs
                    await BaseURITestUtil.VerifyBaseUris(testContext.FileSystem.Files.Values, baseUri);

                    await testContext.CleanupAsync();
                }
        }
Example #8
0
        public async Task GivenAStorageAccountVerifyInitSucceeds()
        {
            using (var testContext = new AmazonS3TestContext())
            {
                await testContext.InitAsync();

                var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                        testContext.FileSystem,
                                                        enableCatalog : true,
                                                        enableSymbols : true,
                                                        log : testContext.Logger,
                                                        token : CancellationToken.None);

                result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                         testContext.FileSystem,
                                                         testContext.Logger);

                result.Should().BeTrue();

                await testContext.CleanupAsync();
            }
        }
Example #9
0
        public async Task SubFeed_PushAndVerifyWithNestedFeedsVerifySuccess()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AmazonS3TestContext())
                    using (var testContext2 = new AmazonS3TestContext())
                    {
                        // Use a subfeed for the filesystem
                        var subFeedName = "testSubFeed";
                        var root        = UriUtility.GetPath(testContext.Uri, subFeedName);
                        testContext.FileSystem = new AmazonS3FileSystem(testContext.LocalCache, root, root, testContext.Client, testContext.BucketName, feedSubPath: subFeedName);

                        await testContext.InitAsync();

                        await testContext2.InitAsync();

                        var testPackage = new TestNupkg("packageA", "1.0.0");
                        var zipFile     = testPackage.Save(packagesFolder.Root);

                        var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                                testContext.FileSystem,
                                                                enableCatalog : true,
                                                                enableSymbols : true,
                                                                log : testContext.Logger,
                                                                token : CancellationToken.None);

                        result &= await InitCommand.RunAsync(testContext.LocalSettings,
                                                             testContext2.FileSystem,
                                                             enableCatalog : true,
                                                             enableSymbols : true,
                                                             log : testContext2.Logger,
                                                             token : CancellationToken.None);

                        result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             new List <string>() { zipFile.FullName },
                                                             force : false,
                                                             skipExisting : false,
                                                             log : testContext.Logger);

                        result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                             testContext2.FileSystem,
                                                             new List <string>() { zipFile.FullName },
                                                             force : false,
                                                             skipExisting : false,
                                                             log : testContext2.Logger);

                        result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                                 testContext.FileSystem,
                                                                 testContext.Logger);

                        result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                                 testContext2.FileSystem,
                                                                 testContext2.Logger);

                        result.Should().BeTrue();

                        await testContext.CleanupAsync();

                        await testContext2.CleanupAsync();
                    }
        }