Exemple #1
0
        public void LibraryAddVersion()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                Library libV1 = null;
                Library libV2 = null;

                var libSpecV1 = TestRandom.RandomPakcageSpec();

                using (var testPackage = TestRandom.RandomPackage(libSpecV1))
                {
                    using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
                        .AddArgument(testPackage.FileName);
                        Invoke(cmdlet);
                    }
                }

                var libSpecV2 = new PackageSpec
                {
                    Id           = libSpecV1.Id,
                    Title        = libSpecV1.Title,
                    Authors      = libSpecV1.Authors,
                    Description  = libSpecV1.Description,
                    ReleaseNotes = TestRandom.RandomText(15, 25),
                    Version      = new Version(libSpecV1.Version.Major + 1, 0, 1)
                };


                using (var testPackage = TestRandom.RandomPackage(libSpecV2))
                {
                    using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
                        .AddArgument(testPackage.FileName);
                        Invoke(cmdlet);
                    }
                }

                // Get all versions
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathLibraryVersion)
                    .AddParameter(UiPathStrings.Id, libSpecV1.Id);

                    var libraries = Invoke <Library>(cmdlet);

                    Validators.ValidateLibraryResponse(libraries, libSpecV2, libSpecV1);

                    libV1 = libraries[0];

                    Assert.IsTrue(libV1.IsLatestVersion.HasValue);
                    Assert.IsTrue(libV1.IsLatestVersion.Value);

                    libV2 = libraries[1];

                    Assert.IsTrue(libV2.IsLatestVersion.HasValue);
                    Assert.IsFalse(libV2.IsLatestVersion.Value);
                }


                // Only Host admin can delete Libraries
                //
                using (var hostRunspace = PowershellFactory.CreateHostAuthenticatedSession(TestContext))
                {
                    // Remove by Id, will remove all versions
                    using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
                        .AddParameter(UiPathStrings.Id, libV1.Id);
                        Invoke(cmdlet);
                    }
                }
            }
        }