Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd320bc

Browse files
authored
Merge pull request UiPath#24 from UiPath/develop
Merge develop into master
2 parents ac0d154 + 22f489c commit cd320bc

27 files changed

+16873
-10
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Management.Automation.Runspaces;
4+
using UiPath.PowerShell.Models;
5+
using UiPath.PowerShell.Tests.Util;
6+
using Cmdlet = System.Management.Automation.PowerShell;
7+
8+
namespace UiPath.PowerShell.Tests.Cmdlets
9+
{
10+
[TestClass]
11+
public class LibraryTests : TestClassBase
12+
{
13+
[TestMethod]
14+
public void LibraryAddRemovePositional()
15+
{
16+
using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
17+
{
18+
Library library = null;
19+
20+
var libSpec = TestRandom.RandomPakcageSpec();
21+
22+
using (var testPackage = TestRandom.RandomPackage(libSpec))
23+
{
24+
25+
// Positional add
26+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
27+
{
28+
cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
29+
.AddArgument(testPackage.FileName);
30+
Invoke(cmdlet);
31+
}
32+
}
33+
34+
// Get by Id
35+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
36+
{
37+
cmdlet.AddCommand(UiPathStrings.GetUiPathLibrary)
38+
.AddParameter(UiPathStrings.Id, libSpec.Id);
39+
40+
var libraries = Invoke<Library>(cmdlet);
41+
42+
Validators.ValidateLibraryResponse(libraries, libSpec);
43+
44+
library = libraries[0];
45+
46+
Assert.IsTrue(library.IsLatestVersion.HasValue);
47+
Assert.IsTrue(library.IsLatestVersion.Value);
48+
}
49+
50+
// Only Host admin can delete Libraries
51+
//
52+
using (var hostRunspace = PowershellFactory.CreateHostAuthenticatedSession(TestContext))
53+
{
54+
55+
// positional remove by object
56+
using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
57+
{
58+
cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
59+
.AddArgument(library);
60+
Invoke(cmdlet);
61+
}
62+
}
63+
}
64+
}
65+
66+
67+
[TestMethod]
68+
public void LibraryAddVersion()
69+
{
70+
using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
71+
{
72+
Library libV1 = null;
73+
Library libV2 = null;
74+
75+
var libSpecV1 = TestRandom.RandomPakcageSpec();
76+
77+
using (var testPackage = TestRandom.RandomPackage(libSpecV1))
78+
{
79+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
80+
{
81+
cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
82+
.AddArgument(testPackage.FileName);
83+
Invoke(cmdlet);
84+
}
85+
}
86+
87+
var libSpecV2 = new PackageSpec
88+
{
89+
Id = libSpecV1.Id,
90+
Title = libSpecV1.Title,
91+
Authors = libSpecV1.Authors,
92+
Description = libSpecV1.Description,
93+
ReleaseNotes = TestRandom.RandomText(15, 25),
94+
Version = new Version(libSpecV1.Version.Major + 1, 0, 1)
95+
};
96+
97+
98+
using (var testPackage = TestRandom.RandomPackage(libSpecV2))
99+
{
100+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
101+
{
102+
cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
103+
.AddArgument(testPackage.FileName);
104+
Invoke(cmdlet);
105+
}
106+
}
107+
108+
// Get all versions
109+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
110+
{
111+
cmdlet.AddCommand(UiPathStrings.GetUiPathLibraryVersion)
112+
.AddParameter(UiPathStrings.Id, libSpecV1.Id);
113+
114+
var libraries = Invoke<Library>(cmdlet);
115+
116+
Validators.ValidateLibraryResponse(libraries, libSpecV2, libSpecV1);
117+
118+
libV1 = libraries[0];
119+
120+
Assert.IsTrue(libV1.IsLatestVersion.HasValue);
121+
Assert.IsTrue(libV1.IsLatestVersion.Value);
122+
123+
libV2 = libraries[1];
124+
125+
Assert.IsTrue(libV2.IsLatestVersion.HasValue);
126+
Assert.IsFalse(libV2.IsLatestVersion.Value);
127+
128+
}
129+
130+
131+
// Only Host admin can delete Libraries
132+
//
133+
using (var hostRunspace = PowershellFactory.CreateHostAuthenticatedSession(TestContext))
134+
{
135+
136+
// Remove by Id, will remove all versions
137+
using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
138+
{
139+
cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
140+
.AddParameter(UiPathStrings.Id, libV1.Id);
141+
Invoke(cmdlet);
142+
}
143+
}
144+
}
145+
}
146+
147+
private void TestFilter(Runspace session, Action<Cmdlet> action, PackageSpec expected)
148+
{
149+
using (var cmdlet = PowershellFactory.CreateCmdlet(session))
150+
{
151+
cmdlet.AddCommand(UiPathStrings.GetUiPathLibrary);
152+
action(cmdlet);
153+
154+
var libraries = Invoke<Library>(cmdlet);
155+
156+
Validators.ValidateLibraryResponse(libraries, expected);
157+
}
158+
}
159+
160+
161+
[TestMethod]
162+
public void LibraryFind()
163+
{
164+
using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
165+
{
166+
var libSpec1 = TestRandom.RandomPakcageSpec();
167+
168+
using (var testPackage = TestRandom.RandomPackage(libSpec1))
169+
{
170+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
171+
{
172+
cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
173+
.AddArgument(testPackage.FileName);
174+
Invoke(cmdlet);
175+
}
176+
}
177+
178+
var libSpec2 = TestRandom.RandomPakcageSpec();
179+
180+
181+
using (var testPackage = TestRandom.RandomPackage(libSpec2))
182+
{
183+
using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
184+
{
185+
cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
186+
.AddArgument(testPackage.FileName);
187+
Invoke(cmdlet);
188+
}
189+
}
190+
191+
TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Id, libSpec1.Id), libSpec1);
192+
TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Id, libSpec2.Id), libSpec2);
193+
TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Title, libSpec1.Title), libSpec1);
194+
TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Authors, libSpec1.Authors), libSpec1);
195+
TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Version, libSpec2.Version), libSpec2);
196+
197+
// Only Host admin can delete Libraries
198+
//
199+
using (var hostRunspace = PowershellFactory.CreateHostAuthenticatedSession(TestContext))
200+
{
201+
202+
// Remove
203+
using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
204+
{
205+
cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
206+
.AddParameter(UiPathStrings.Id, libSpec1.Id);
207+
Invoke(cmdlet);
208+
}
209+
210+
using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
211+
{
212+
cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
213+
.AddParameter(UiPathStrings.Id, libSpec2.Id);
214+
Invoke(cmdlet);
215+
}
216+
}
217+
}
218+
}
219+
}
220+
}
221+

UiPath.PowerShell.Tests/UiPath.PowerShell.Tests.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,33 @@
4747
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
4848
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
4949
</Reference>
50+
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
52+
</Reference>
5053
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5154
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
5255
</Reference>
56+
<Reference Include="NuGet.Core, Version=2.14.0.832, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<HintPath>..\packages\NuGet.Core.2.14.0\lib\net40-Client\NuGet.Core.dll</HintPath>
58+
</Reference>
5359
<Reference Include="System" />
5460
<Reference Include="System.Core" />
61+
<Reference Include="System.IO.Compression" />
62+
<Reference Include="System.IO.Compression.FileSystem" />
5563
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5664
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
5765
<Private>True</Private>
5866
</Reference>
5967
<Reference Include="System.Net" />
6068
<Reference Include="System.Net.Http" />
6169
<Reference Include="System.Web" />
70+
<Reference Include="System.Xml" />
71+
<Reference Include="System.Xml.Linq" />
6272
</ItemGroup>
6373
<ItemGroup>
6474
<Compile Include="Cmdlets\AssetTests.cs" />
6575
<Compile Include="Cmdlets\EnvironmentTests.cs" />
76+
<Compile Include="Cmdlets\LibraryTests.cs" />
6677
<Compile Include="Cmdlets\MergeAddRemoveTests.cs" />
6778
<Compile Include="Cmdlets\QueueDefinitionsTests.cs" />
6879
<Compile Include="Cmdlets\RobotTests.cs" />
@@ -74,6 +85,8 @@
7485
<Link>Properties\GlobalAssemblyInfo.cs</Link>
7586
</Compile>
7687
<Compile Include="Util\ApiHelper.cs" />
88+
<Compile Include="Util\PackageSpec.cs" />
89+
<Compile Include="Util\TestFileFixture.cs" />
7790
<Compile Include="Util\PowershellFactory.cs" />
7891
<Compile Include="Util\TestClassBase.cs" />
7992
<Compile Include="Util\TestRandom.cs" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace UiPath.PowerShell.Tests.Util
8+
{
9+
public class PackageSpec
10+
{
11+
public string Id { get; set; }
12+
public Version Version { get; set; }
13+
public string Authors { get; set; }
14+
public string Title { get; set; }
15+
public string Description { get; set; }
16+
public string ReleaseNotes { get; set; }
17+
}
18+
}

UiPath.PowerShell.Tests/Util/PowershellFactory.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,24 @@ public static Runspace CreateAuthenticatedSession(TestContext testContext)
6565
return runspace;
6666
}
6767

68+
public static Runspace CreateHostAuthenticatedSession(TestContext testContext)
69+
{
70+
var testSettings = TestSettings.FromTestContext(testContext);
71+
var iss = CreateSessionState();
72+
var runspace = CreateRunspace(iss);
73+
74+
try
75+
{
76+
runspace.Open();
77+
AuthenticateSession(runspace, testSettings.URL, "Host", "admin", testSettings.HostPassword, testContext);
78+
}
79+
catch
80+
{
81+
runspace.Dispose();
82+
throw;
83+
}
84+
return runspace;
85+
}
86+
6887
}
6988
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace UiPath.PowerShell.Tests.Util
9+
{
10+
public class TestFileFixture: IDisposable
11+
{
12+
public string FileName { get; set; }
13+
14+
public void Dispose()
15+
{
16+
if (File.Exists(FileName))
17+
{
18+
File.Delete(FileName);
19+
}
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)