This class provides the helper methods to create different types of packages
Inheritance: NuGetGallery.FunctionalTests.HelperBase
        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 override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();

            //Do initial login
            WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();

            yield return(logonGet);

            logonGet = null;

            WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);

            yield return(logonPost);

            logonPost = null;

            WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);

            yield return(uploadRequest);

            if (this.LastResponse.ResponseUri.ToString().Contains("verify-upload"))
            {
                WebTestRequest cancelGet = AssertAndValidationHelper.GetCancelGetRequest();
                yield return(cancelGet);

                cancelGet     = null;
                uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
                yield return(uploadRequest);
            }
            uploadRequest = null;

            // The API key is part of the nuget.config file that is present under the solution dir.
            string packageId       = DateTime.Now.Ticks.ToString();
            string packageFullPath = PackageCreationHelper.CreatePackage(packageId);

            WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);

            yield return(uploadPostRequest);

            uploadPostRequest = null;

            WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);

            verifyUploadRequest.ExtractValues += new EventHandler <ExtractionEventArgs>(defaultExtractionRule.Extract);
            yield return(verifyUploadRequest);

            verifyUploadRequest = null;

            WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0");

            yield return(verifyUploadPostRequest);

            verifyUploadPostRequest = null;
        }
        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);
            }
        }
Example #6
0
        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)
        {
            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);

            await UploadExistingPackage(packageFullPath);

            // Delete package from local disk once it gets uploaded
            CleanCreatedPackage(packageFullPath);
        }
        /// <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>
        /// <param name="packageId"></param>
        /// <param name="version"></param>
        public static void UploadNewPackageAndVerify(string packageId, string version = "1.0.0")
        {
            if (string.IsNullOrEmpty(packageId))
            {
                packageId = DateTime.Now.Ticks.ToString();
            }
            string packageFullPath = PackageCreationHelper.CreatePackage(packageId, version);
            string standardOutput  = string.Empty;
            string standardError   = string.Empty;
            int    exitCode        = CmdLineHelper.UploadPackage(packageFullPath, UrlHelper.V2FeedPushSourceUrl, out standardOutput, out standardError);

            Assert.IsTrue((exitCode == 0), "The package upload via Nuget.exe didnt suceed properly. Check the logs to see the process error and output stream.  Exit Code: " + exitCode + ". Error message: \"" + standardError + "\"");
            Console.WriteLine(standardOutput);
            Console.WriteLine(standardError);
            Assert.IsTrue(ClientSDKHelper.CheckIfPackageVersionExistsInSource(packageId, version, UrlHelper.V2FeedRootUrl), "Package {0} is not found in the site {1} after uploading.", packageId, UrlHelper.V2FeedRootUrl);

            //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);
            }
        }
Example #8
0
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();

            //Upload a new package.
            string packageId = this.Name + DateTime.Now.Ticks.ToString();
            string version   = "1.0.0";

            AssertAndValidationHelper.UploadNewPackageAndVerify(packageId, version);

            //Do initial login to be able to perform edit.
            WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();

            yield return(logonGet);

            logonGet = null;
            WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);

            yield return(logonPost);

            logonPost = null;

            WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);

            yield return(uploadRequest);

            if (this.LastResponse.ResponseUri.ToString().Contains("verify-upload"))
            {
                WebTestRequest cancelGet = AssertAndValidationHelper.GetCancelGetRequest();
                yield return(cancelGet);

                cancelGet     = null;
                uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
                yield return(uploadRequest);
            }
            uploadRequest = null;

            // The API key is part of the nuget.config file that is present under the solution dir.
            string packageFullPath = PackageCreationHelper.CreatePackage(packageId);

            WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);

            yield return(uploadPostRequest);

            uploadPostRequest = null;

            WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);

            yield return(verifyUploadRequest);

            verifyUploadRequest = null;

            WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0");

            yield return(verifyUploadPostRequest);

            verifyUploadPostRequest = null;

            WebTestRequest verifyEditRequest = AssertAndValidationHelper.GetEditGetRequestForPackage(packageId, "1.0.0");

            verifyEditRequest.ExtractValues += new EventHandler <ExtractionEventArgs>(defaultExtractionRule.Extract);
            yield return(verifyEditRequest);

            verifyEditRequest = null;

            WebTestRequest         verifyEditPostRequest        = AssertAndValidationHelper.GetEditPackagePostRequest(this, packageId, "1.0.0", description: "This is a new description.", authors: "clayco", copyright: "Copyright 2014", tags: "Tag1 Tag2", summary: "This is a summary.");
            ValidationRuleFindText newDescriptionValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(@"This is a new description.");
            ValidationRuleFindText pendingEditValidationRule    = AssertAndValidationHelper.GetValidationRuleForFindText(@"An edit is pending for this package version.");

            verifyEditPostRequest.ValidateResponse += new EventHandler <ValidationEventArgs>(newDescriptionValidationRule.Validate);
            verifyEditPostRequest.ValidateResponse += new EventHandler <ValidationEventArgs>(pendingEditValidationRule.Validate);
            yield return(verifyEditPostRequest);

            verifyEditPostRequest = null;

            // wait a minute.
            System.Threading.Thread.Sleep(60000);
            WebTestRequest         verifyProcessedRequest      = new WebTestRequest(UrlHelper.GetPackagePageUrl(packageId, "1.0.0"));
            ValidationRuleFindText noPendingEditValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(@"An edit is pending for this package version.", false);

            verifyProcessedRequest.ValidateResponse += new EventHandler <ValidationEventArgs>(newDescriptionValidationRule.Validate);
            verifyProcessedRequest.ValidateResponse += new EventHandler <ValidationEventArgs>(noPendingEditValidationRule.Validate);
            yield return(verifyProcessedRequest);

            verifyProcessedRequest = null;
        }
        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);
            }
        }
Example #10
0
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            //run this test only if read-only mode is set. This is to avoid false failures while doing Run all tests locally.
            if (EnvironmentSettings.ReadOnlyMode.Equals("True", StringComparison.OrdinalIgnoreCase))
            {
                ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();

                //Do initial login
                WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();
                yield return(logonGet);

                logonGet = null;

                WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);
                yield return(logonPost);

                logonPost = null;

                WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
                yield return(uploadRequest);

                uploadRequest = null;
                if (this.LastResponse.ResponseUri.ToString().Contains("verify-upload"))
                {
                    // if there is a upload in progress, try to submit that upload instead of creating a new package (since we are just going to verify that upload doesn't go through).
                    //Extract the package Id of the pending upload.
                    string response       = this.LastResponse.BodyString;
                    int    referenceIndex = response.IndexOf("<h4>Package ID</h4>");
                    int    startIndex     = response.IndexOf("<p>");
                    int    endIndex       = response.IndexOf("</p>", startIndex);
                    string packageId      = response.Substring(startIndex + 3, endIndex - (startIndex + 3));
                    this.AddCommentToResult(packageId); //Adding the package ID to result for debugging.
                    WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0", UrlHelper.VerifyUploadPageUrl, Constants.ReadOnlyModeError, 503);
                    yield return(verifyUploadPostRequest);

                    verifyUploadPostRequest = null;
                }
                else
                {
                    // The API key is part of the nuget.config file that is present under the solution dir.
                    string packageId       = DateTime.Now.Ticks.ToString();
                    string packageFullPath = PackageCreationHelper.CreatePackage(packageId);

                    WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);
                    yield return(uploadPostRequest);

                    uploadPostRequest = null;

                    WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);
                    verifyUploadRequest.ExtractValues += new EventHandler <ExtractionEventArgs>(defaultExtractionRule.Extract);
                    yield return(verifyUploadRequest);

                    verifyUploadRequest = null;

                    WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0", UrlHelper.VerifyUploadPageUrl, Constants.ReadOnlyModeError, 503);
                    yield return(verifyUploadPostRequest);

                    verifyUploadPostRequest = null;
                }
            }
        }
Example #11
0
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            // Temporary workaround for the SSL issue, which keeps the upload test from working with cloudapp.net sites
            if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org"))
            {
                ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();

                //Do initial login
                WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();
                yield return(logonGet);

                logonGet = null;

                WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);
                yield return(logonPost);

                logonPost = null;

                WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
                yield return(uploadRequest);

                if (this.LastResponse.ResponseUri.ToString().Contains("verify-upload"))
                {
                    // if there is a upload in progress, try to submit that upload instead of creating a new package (since we are just going to verify that upload goes through UI).
                    //Extract the package Id of the pending upload.
                    string response       = this.LastResponse.BodyString;
                    int    referenceIndex = response.IndexOf("<h4>Package ID</h4>");
                    int    startIndex     = response.IndexOf("<p>");
                    int    endIndex       = response.IndexOf("</p>", startIndex);
                    string packageId      = response.Substring(startIndex + 3, endIndex - (startIndex + 3));
                    this.AddCommentToResult(packageId);   //Adding the package ID to result for debugging.
                    WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0", UrlHelper.VerifyUploadPageUrl, Constants.ReadOnlyModeError, 503);
                    yield return(verifyUploadPostRequest);

                    verifyUploadPostRequest = null;
                }
                else
                {
                    uploadRequest = null;

                    // The API key is part of the nuget.config file that is present under the solution dir.
                    string packageId       = DateTime.Now.Ticks.ToString();
                    string packageFullPath = PackageCreationHelper.CreatePackage(packageId);

                    WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);
                    yield return(uploadPostRequest);

                    uploadPostRequest = null;

                    WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);
                    verifyUploadRequest.ExtractValues += new EventHandler <ExtractionEventArgs>(defaultExtractionRule.Extract);
                    yield return(verifyUploadRequest);

                    verifyUploadRequest = null;

                    WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0", UrlHelper.GetPackagePageUrl(packageId, "1.0.0"), packageId);
                    yield return(verifyUploadPostRequest);

                    verifyUploadPostRequest = null;
                }
            }
        }