UploadPackageAsync() public method

Uploads the given package to the specified source and returns the exit code.
public UploadPackageAsync ( string packageFullPath, string sourceName ) : Task
packageFullPath string
sourceName string
return Task
        public async Task UploadNewPackage(string packageId, string version = "1.0.0", string minClientVersion = null,
                                           string title        = null, string tags   = null, string description = null, string licenseUrl = null,
                                           string dependencies = null, string apiKey = null, bool success       = true)
        {
            WriteLine("Uploading new package '{0}', version '{1}'", packageId, version);

            var packageCreationHelper = new PackageCreationHelper(TestOutputHelper);
            var packageFullPath       = await packageCreationHelper.CreatePackage(packageId, version, minClientVersion, title, tags, description, licenseUrl, dependencies);

            try
            {
                var commandlineHelper = new CommandlineHelper(TestOutputHelper);
                var processResult     = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl, apiKey);

                if (success)
                {
                    Assert.True(processResult.ExitCode == 0,
                                "The package upload via Nuget.exe did not succeed properly. Check the logs to see the process error and output stream.  Exit Code: " +
                                processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");
                }
                else
                {
                    Assert.False(processResult.ExitCode == 0,
                                 "The package upload via Nuget.exe succeeded but was expected to fail. Check the logs to see the process error and output stream.  Exit Code: " +
                                 processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");
                }
            }
            finally
            {
                // Delete package from local disk once it gets uploaded
                CleanCreatedPackage(packageFullPath);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a package with the specified Id and Version and uploads it and checks if the upload has suceeded.
        /// This will be used by test classes which tests scenarios on top of upload.
        /// </summary>
        public async Task UploadNewPackageAndVerify(string packageId, string version = "1.0.0", string minClientVersion = null, string title = null, string tags = null, string description = null, string licenseUrl = null, string dependencies = null)
        {
            if (string.IsNullOrEmpty(packageId))
            {
                packageId = DateTime.Now.Ticks.ToString();
            }

            WriteLine("Uploading new package '{0}', version '{1}'", packageId, version);

            var packageCreationHelper = new PackageCreationHelper(TestOutputHelper);
            var packageFullPath       = await packageCreationHelper.CreatePackage(packageId, version, minClientVersion, title, tags, description, licenseUrl, dependencies);

            var commandlineHelper = new CommandlineHelper(TestOutputHelper);
            var processResult     = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 0, "The package upload via Nuget.exe did not succeed properly. Check the logs to see the process error and output stream.  Exit Code: " + processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            var packageExistsInSource = CheckIfPackageVersionExistsInSource(packageId, version, UrlHelper.V2FeedRootUrl);
            var userMessage           = string.Format("Package {0} with version {1} is not found in the site {2} after uploading.", packageId, version, UrlHelper.V2FeedRootUrl);

            Assert.True(packageExistsInSource, userMessage);

            // Delete package from local disk so once it gets uploaded
            if (File.Exists(packageFullPath))
            {
                File.Delete(packageFullPath);
                Directory.Delete(Path.GetFullPath(Path.GetDirectoryName(packageFullPath)), true);
            }
        }
        public async Task CheckIfBaseTestPackageExistsAsync()
        {
            // Check if the BaseTestPackage exists in current source and if not upload it.
            // This will be used by the download related tests.
            try
            {
                var clientSdkHelper = new ClientSdkHelper(ConsoleTestOutputHelper.New);
                if (!clientSdkHelper.CheckIfPackageExistsInSource(Constants.TestPackageId, UrlHelper.V2FeedRootUrl))
                {
                    var testOutputHelper      = ConsoleTestOutputHelper.New;
                    var commandlineHelper     = new CommandlineHelper(testOutputHelper);
                    var packageCreationHelper = new PackageCreationHelper(testOutputHelper);
                    var packageFullPath       = await packageCreationHelper.CreatePackage(Constants.TestPackageId, "1.0.0");

                    var processResult = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

                    Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage);
                }
            }
            catch (Exception exception)
            {
                var message = string.Format(
                    "The initialization method to pre-upload test package has failed. Hence failing all the tests. Make sure that a package by name {0} exists @ {1} before running tests. Check test run error for details",
                    Constants.TestPackageId, UrlHelper.BaseUrl);
                throw new InvalidOperationException(message, exception);
            }
        }
Example #4
0
        public async Task UploadExistingPackage(string packageFullPath, string apiKey = null)
        {
            var commandlineHelper = new CommandlineHelper(TestOutputHelper);
            var processResult     = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl, apiKey);

            Assert.True(processResult.ExitCode == 0,
                        "The package upload via Nuget.exe did not succeed properly. Check the logs to see the process error and output stream.  Exit Code: " +
                        processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");
        }
        private async Task UploadPackage(string packageId, string version, string apiKey = null, bool success = true)
        {
            if (string.IsNullOrEmpty(packageId))
            {
                throw new ArgumentException($"{nameof(packageId)} cannot be null or empty!");
            }

            if (string.IsNullOrEmpty(version))
            {
                throw new ArgumentException($"{nameof(version)} cannot be null or empty!");
            }

            await Task.Yield();

            WriteLine("Uploading new package '{0}', version '{1}'", packageId, version);

            var packageCreationHelper = new PackageCreationHelper(TestOutputHelper);
            var packageFullPath       = await packageCreationHelper.CreatePackage(packageId, version);

            try
            {
                var commandlineHelper = new CommandlineHelper(TestOutputHelper);
                var processResult     = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl, apiKey);

                if (success)
                {
                    Assert.True(processResult.ExitCode == 0,
                                "The package upload via Nuget.exe did not succeed properly. Check the logs to see the process error and output stream.  Exit Code: " +
                                processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

                    await VerifyPackageExistsInV2Async(packageId, version);
                }
                else
                {
                    Assert.False(processResult.ExitCode == 0,
                                 "The package upload via Nuget.exe succeeded but was expected to fail. Check the logs to see the process error and output stream.  Exit Code: " +
                                 processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");
                }
            }
            finally
            {
                // Delete package from local disk once it gets uploaded
                CleanCreatedPackage(packageFullPath);
            }
        }
        public async Task UploadNewPackage(string packageId, string version = "1.0.0", string minClientVersion = null,
            string title = null, string tags = null, string description = null, string licenseUrl = null,
            string dependencies = null)
        {
            if (string.IsNullOrEmpty(packageId))
            {
                packageId = DateTime.Now.Ticks.ToString();
            }

            WriteLine("Uploading new package '{0}', version '{1}'", packageId, version);

            var packageCreationHelper = new PackageCreationHelper(TestOutputHelper);
            var packageFullPath = await packageCreationHelper.CreatePackage(packageId, version, minClientVersion, title, tags, description, licenseUrl, dependencies);

            var commandlineHelper = new CommandlineHelper(TestOutputHelper);
            var processResult = await commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 0,
                "The package upload via Nuget.exe did not succeed properly. Check the logs to see the process error and output stream.  Exit Code: " +
                processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            // Delete package from local disk once it gets uploaded
            if (File.Exists(packageFullPath))
            {
                File.Delete(packageFullPath);
                Directory.Delete(Path.GetFullPath(Path.GetDirectoryName(packageFullPath)), true);
            }
        }