Skip to content

Commit f5bc313

Browse files
authored
Add logic to invoke clean client side libraries command during test cleanup phase
1 parent 556a920 commit f5bc313

File tree

5 files changed

+103
-119
lines changed

5 files changed

+103
-119
lines changed

test/LibraryManager.IntegrationTest/AddClientSideLibrariesFromUITests.cs

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
2-
using System.IO;
3-
using Microsoft.Test.Apex.Services;
4-
using Microsoft.Test.Apex.VisualStudio.Shell;
1+
using System.IO;
52
using Microsoft.Test.Apex.VisualStudio.Shell.ToolWindows;
6-
using Microsoft.Test.Apex.VisualStudio.Solution;
73
using Microsoft.VisualStudio.TestTools.UnitTesting;
84
using Microsoft.Web.LibraryManager.IntegrationTest.Services;
95

@@ -12,66 +8,20 @@ namespace Microsoft.Web.LibraryManager.IntegrationTest
128
[TestClass]
139
public class AddClientSideLibrariesFromUITests : VisualStudioLibmanHostTest
1410
{
15-
private string _initialLibmanFileContent;
16-
private string _pathToLibmanFile;
17-
private ProjectTestExtension _webProject;
18-
private const string _libman = "libman.json";
19-
private const string _projectName = @"TestProjectCore20";
20-
2111
protected override void DoHostTestInitialize()
2212
{
2313
base.DoHostTestInitialize();
2414

25-
_webProject = Solution[_projectName];
26-
ProjectItemTestExtension libmanConfig = _webProject[_libman];
27-
_pathToLibmanFile = Path.Combine(SolutionRootPath, _projectName, _libman);
28-
_initialLibmanFileContent = File.ReadAllText(_pathToLibmanFile);
29-
30-
string libmanConfigFullPath = libmanConfig.FullPath;
15+
string libmanConfigFullPath = _libmanConfig.FullPath;
3116

3217
if (File.Exists(libmanConfigFullPath))
3318
{
3419
string projectPath = Path.Combine(SolutionRootPath, _projectName);
35-
libmanConfig.Delete();
20+
_libmanConfig.Delete();
3621
Helpers.FileIO.WaitForDeletedFile(projectPath, libmanConfigFullPath, caseInsensitive: false);
3722
}
3823
}
3924

40-
protected override void DoHostTestCleanup()
41-
{
42-
ProjectItemTestExtension libmanConfig = _webProject[_libman];
43-
44-
if (libmanConfig != null)
45-
{
46-
CleanClientSideLibraries();
47-
48-
libmanConfig.Open();
49-
Editor.Selection.SelectAll();
50-
Editor.KeyboardCommands.Delete();
51-
Editor.Edit.InsertTextInBuffer(_initialLibmanFileContent);
52-
53-
libmanConfig.Save();
54-
}
55-
56-
base.DoHostTestCleanup();
57-
}
58-
59-
private void CleanClientSideLibraries()
60-
{
61-
Guid guid = Guid.Parse("44ee7bda-abda-486e-a5fe-4dd3f4cefac1");
62-
uint commandId = 0x0200;
63-
SolutionExplorerItemTestExtension configFileNode = SolutionExplorer.FindItemRecursive(_libman);
64-
configFileNode.Select();
65-
66-
WaitFor.IsTrue(() =>
67-
{
68-
CommandQueryResult queryResult = VisualStudio.ObjectModel.Commanding.QueryStatusCommand(guid, commandId);
69-
return queryResult.IsEnabled;
70-
},TimeSpan.FromMilliseconds(40000), TimeSpan.FromMilliseconds(500));
71-
72-
VisualStudio.ObjectModel.Commanding.ExecuteCommand(guid, commandId, null);
73-
}
74-
7525
[TestMethod]
7626
public void InstallClientSideLibraries_FromProjectRoot_SmokeTest()
7727
{
Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
using System.IO;
2-
using Microsoft.Test.Apex.VisualStudio.Solution;
32
using Microsoft.VisualStudio.TestTools.UnitTesting;
43

54
namespace Microsoft.Web.LibraryManager.IntegrationTest
65
{
76
[TestClass]
87
public class FileSaveRestoreTests : VisualStudioLibmanHostTest
98
{
10-
ProjectTestExtension _webProject;
11-
ProjectItemTestExtension _libManConfig;
12-
const string _projectName = @"TestProjectCore20";
13-
const string _libman = "libman.json";
14-
private string _libmanFileContent;
15-
16-
[TestInitialize]
17-
public void initialize()
18-
{
19-
_webProject = Solution[_projectName];
20-
_libManConfig = _webProject[_libman];
21-
string pathToLibmanFile = Path.Combine(SolutionRootPath, _projectName, _libman);
22-
_libmanFileContent = File.ReadAllText(pathToLibmanFile);
23-
}
24-
259
[TestMethod]
2610
public void FileSaveRestore_AddDeleteLibrary()
2711
{
2812
string projectPath = Path.Combine(SolutionRootPath, _projectName);
2913

30-
_libManConfig.Delete();
14+
_libmanConfig.Delete();
3115
Helpers.FileIO.WaitForDeletedFile(projectPath, Path.Combine(projectPath, _libman), caseInsensitive: false, timeout: 1000);
3216

3317
VisualStudio.ObjectModel.Commanding.ExecuteCommand("Project.ManageClientSideLibraries");
3418
Helpers.FileIO.WaitForRestoredFile(projectPath, Path.Combine(projectPath, _libman), caseInsensitive: false, timeout: 1000);
3519

36-
_libManConfig = _webProject[_libman];
37-
_libManConfig.Open();
20+
_libmanConfig = _webProject[_libman];
21+
_libmanConfig.Open();
3822

3923
string pathToLibrary = Path.Combine(SolutionRootPath, _projectName, "wwwroot", "lib", "jquery-validate");
4024
string[] expectedFiles = new[]
@@ -52,6 +36,7 @@ public void FileSaveRestore_AddDeleteLibrary()
5236
}
5337
]
5438
}";
39+
5540
string deletingLibraryContent = @"{
5641
""version"": ""1.0"",
5742
""defaultProvider"": ""cdnjs"",
@@ -63,17 +48,15 @@ public void FileSaveRestore_AddDeleteLibrary()
6348

6449
ReplaceFileContent(deletingLibraryContent);
6550
Helpers.FileIO.WaitForDeletedFiles(pathToLibrary, expectedFiles, caseInsensitive: true);
66-
67-
ReplaceFileContent(_libmanFileContent);
6851
}
6952

7053
private void ReplaceFileContent(string content)
7154
{
7255
Editor.Selection.SelectAll();
73-
Editor.KeyboardCommands.Backspace();
56+
Editor.KeyboardCommands.Delete();
7457
Editor.Edit.InsertTextInBuffer(content);
7558

76-
_libManConfig.Save();
59+
_libmanConfig.Save();
7760
}
7861
}
7962
}

test/LibraryManager.IntegrationTest/LibmanCompletionTests.cs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
using System.Collections.Generic;
22
using Microsoft.Test.Apex.Editor;
3-
using Microsoft.Test.Apex.VisualStudio.Solution;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54

65
namespace Microsoft.Web.LibraryManager.IntegrationTest
76
{
87
[TestClass]
98
public class LibmanCompletionTests : VisualStudioLibmanHostTest
109
{
11-
ProjectItemTestExtension _libManConfig;
12-
13-
[TestInitialize()]
14-
public void initialize()
15-
{
16-
string projectName = "TestProjectCore20";
17-
18-
ProjectTestExtension webProject = Solution.ProjectsRecursive[projectName];
19-
_libManConfig = webProject.Find(SolutionItemFind.FileName, "libman.json");
20-
}
21-
2210
[TestMethod]
2311
public void LibmanCompletion_Destination()
2412
{
25-
_libManConfig.Open();
13+
_libmanConfig.Open();
2614
string[] expectedCompletionEntries = new[] {
2715
"Properties/",
2816
"wwwroot/",
2917
};
3018

3119
Editor.Caret.MoveToExpression("\"libraries\"");
32-
Editor.Caret.MoveDown(2);
20+
Editor.Caret.MoveDown(1);
21+
Editor.KeyboardCommands.Type("{");
22+
Editor.KeyboardCommands.Enter();
3323
Editor.KeyboardCommands.Type("\"destination\":");
3424

3525
Helpers.Completion.WaitForCompletionEntries(Editor, expectedCompletionEntries, caseInsensitive: true);
@@ -38,7 +28,7 @@ public void LibmanCompletion_Destination()
3828
[TestMethod]
3929
public void LibmanCompletion_Provider()
4030
{
41-
_libManConfig.Open();
31+
_libmanConfig.Open();
4232

4333
string[] expectedCompletionEntries = new[] {
4434
"cdnjs",
@@ -47,7 +37,9 @@ public void LibmanCompletion_Provider()
4737
};
4838

4939
Editor.Caret.MoveToExpression("\"libraries\"");
50-
Editor.Caret.MoveDown(2);
40+
Editor.Caret.MoveDown(1);
41+
Editor.KeyboardCommands.Type("{");
42+
Editor.KeyboardCommands.Enter();
5143
Editor.KeyboardCommands.Type("\"provider\":");
5244

5345
Helpers.Completion.WaitForCompletionEntries(Editor, expectedCompletionEntries, caseInsensitive: true);
@@ -56,7 +48,7 @@ public void LibmanCompletion_Provider()
5648
[TestMethod]
5749
public void LibmanCompletion_DefaultProvider()
5850
{
59-
_libManConfig.Open();
51+
_libmanConfig.Open();
6052

6153
string[] expectedCompletionEntries = new[] {
6254
"cdnjs",
@@ -75,7 +67,7 @@ public void LibmanCompletion_DefaultProvider()
7567
[TestMethod]
7668
public void LibmanCompletion_DefaultDestination()
7769
{
78-
_libManConfig.Open();
70+
_libmanConfig.Open();
7971
string[] expectedCompletionEntries = new[] {
8072
"Properties/",
8173
"wwwroot/",
@@ -92,13 +84,15 @@ public void LibmanCompletion_DefaultDestination()
9284
[TestMethod]
9385
public void LibmanCompletion_LibraryForCdnjs()
9486
{
95-
_libManConfig.Open();
87+
_libmanConfig.Open();
9688
string[] expectedCompletionEntries = new[] {
9789
"jquery",
9890
};
9991

10092
Editor.Caret.MoveToExpression("\"libraries\"");
101-
Editor.Caret.MoveDown(2);
93+
Editor.Caret.MoveDown(1);
94+
Editor.KeyboardCommands.Type("{");
95+
Editor.KeyboardCommands.Enter();
10296
Editor.KeyboardCommands.Type("\"provider\": \"cdnjs\",");
10397
Editor.KeyboardCommands.Enter();
10498

@@ -109,10 +103,12 @@ public void LibmanCompletion_LibraryForCdnjs()
109103
[TestMethod]
110104
public void LibmanCompletion_LibraryVersionForCdnjs()
111105
{
112-
_libManConfig.Open();
106+
_libmanConfig.Open();
113107

114108
Editor.Caret.MoveToExpression("\"libraries\"");
115-
Editor.Caret.MoveDown(2);
109+
Editor.Caret.MoveDown(1);
110+
Editor.KeyboardCommands.Type("{");
111+
Editor.KeyboardCommands.Enter();
116112
Editor.KeyboardCommands.Type("\"provider\": \"cdnjs\",");
117113
Editor.KeyboardCommands.Enter();
118114

@@ -126,14 +122,16 @@ public void LibmanCompletion_LibraryVersionForCdnjs()
126122
[TestMethod]
127123
public void LibmanCompletion_LibraryForFilesystem()
128124
{
129-
_libManConfig.Open();
125+
_libmanConfig.Open();
130126
string[] expectedCompletionEntries = new[] {
131127
"Properties/",
132128
"wwwroot/",
133129
};
134130

135131
Editor.Caret.MoveToExpression("\"libraries\"");
136-
Editor.Caret.MoveDown(2);
132+
Editor.Caret.MoveDown(1);
133+
Editor.KeyboardCommands.Type("{");
134+
Editor.KeyboardCommands.Enter();
137135
Editor.KeyboardCommands.Type("\"provider\": \"filesystem\",");
138136
Editor.KeyboardCommands.Enter();
139137

@@ -144,28 +142,34 @@ public void LibmanCompletion_LibraryForFilesystem()
144142
[TestMethod]
145143
public void LibmanCompletion_LibraryForUnpkg()
146144
{
147-
_libManConfig.Open();
148-
string[] expectedCompletionEntries = new[] {
149-
"bootstrap",
150-
"jquery",
151-
};
145+
// This test needs to be updated once we fix https://github.com/aspnet/LibraryManager/issues/221
146+
_libmanConfig.Open();
152147

153148
Editor.Caret.MoveToExpression("\"libraries\"");
154-
Editor.Caret.MoveDown(2);
149+
Editor.Caret.MoveDown(1);
150+
Editor.KeyboardCommands.Type("{");
151+
Editor.KeyboardCommands.Enter();
155152
Editor.KeyboardCommands.Type("\"provider\": \"unpkg\",");
156153
Editor.KeyboardCommands.Enter();
157154

158155
Editor.KeyboardCommands.Type("\"library\":");
159-
Helpers.Completion.WaitForCompletionEntries(Editor, expectedCompletionEntries, caseInsensitive: true, timeout: 5000);
156+
Editor.KeyboardCommands.Type("bootstr");
157+
Helpers.Completion.WaitForCompletionEntries(Editor, new[] { "bootstrap" }, caseInsensitive: true, timeout: 5000);
158+
159+
Editor.KeyboardCommands.Backspace(7);
160+
Editor.KeyboardCommands.Type("jqu");
161+
Helpers.Completion.WaitForCompletionEntries(Editor, new[] { "jquery" }, caseInsensitive: true, timeout: 5000);
160162
}
161163

162164
[TestMethod]
163165
public void LibmanCompletion_CompletionForBackSpace()
164166
{
165-
_libManConfig.Open();
167+
_libmanConfig.Open();
166168

167169
Editor.Caret.MoveToExpression("\"libraries\"");
168-
Editor.Caret.MoveDown(2);
170+
Editor.Caret.MoveDown(1);
171+
Editor.KeyboardCommands.Type("{");
172+
Editor.KeyboardCommands.Enter();
169173
Editor.KeyboardCommands.Type("\"provider\": \"cdnjs\",");
170174
Editor.KeyboardCommands.Enter();
171175

@@ -179,10 +183,12 @@ public void LibmanCompletion_CompletionForBackSpace()
179183
[TestMethod]
180184
public void LibmanCompletion_VersionCompletionInDescendingOrder()
181185
{
182-
_libManConfig.Open();
186+
_libmanConfig.Open();
183187

184188
Editor.Caret.MoveToExpression("\"libraries\"");
185-
Editor.Caret.MoveDown(2);
189+
Editor.Caret.MoveDown(1);
190+
Editor.KeyboardCommands.Type("{");
191+
Editor.KeyboardCommands.Enter();
186192
Editor.KeyboardCommands.Type("\"provider\": \"unpkg\",");
187193
Editor.KeyboardCommands.Enter();
188194

@@ -200,7 +206,7 @@ public void LibmanCompletion_VersionCompletionInDescendingOrder()
200206
semanticVersions.Add(SemanticVersion.Parse(item.Text));
201207
}
202208

203-
for (int i= 1; i < semanticVersions.Count; ++i)
209+
for (int i = 1; i < semanticVersions.Count; ++i)
204210
{
205211
Assert.IsTrue(semanticVersions[i].CompareTo(semanticVersions[i - 1]) <= 0);
206212
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"version": "1.0",
33
"libraries": [
4-
{
5-
6-
}
4+
75
]
86
}

0 commit comments

Comments
 (0)