Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit db95b21

Browse files
committed
Remove fixture from DTH tests
1 parent 1e78aeb commit db95b21

File tree

16 files changed

+64
-146
lines changed

16 files changed

+64
-146
lines changed

misc/DthTestProjects/global.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"projects": ["src"]
3+
}

test/Microsoft.Dnx.DesignTimeHost.FunctionalTests/DthStartupTests.cs

+61-57
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515

1616
namespace Microsoft.Dnx.DesignTimeHost.FunctionalTests
1717
{
18-
[Collection(nameof(DthFunctionalTestCollection))]
1918
public class DthStartupTests : DnxSdkFunctionalTestBase
2019
{
21-
private readonly DthFunctionalTestFixture _fixture;
22-
23-
public DthStartupTests(DthFunctionalTestFixture fixture)
24-
{
25-
_fixture = fixture;
26-
}
27-
2820
public static IEnumerable<object[]> RuntimeComponentsWithBothVersions
2921
{
3022
get
@@ -90,19 +82,21 @@ public static IEnumerable<object[]> UnresolvedDependencyTestData
9082
[MemberData(nameof(DnxSdks))]
9183
public void DthStartup_GetProjectInformation(DnxSdk sdk)
9284
{
93-
var projectName = "EmptyConsoleApp";
94-
var testProject = _fixture.GetTestProjectPath(projectName);
95-
9685
using (var server = DthTestServer.Create(sdk))
9786
using (var client = new DthTestClient(server))
9887
{
99-
client.Initialize(testProject);
88+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
89+
var project = solution.GetProject("EmptyConsoleApp");
90+
91+
sdk.Dnu.Restore(project).EnsureSuccess();
92+
93+
client.Initialize(project.ProjectDirectory);
10094

10195
var projectInformation = client.DrainAllMessages()
10296
.RetrieveSingleMessage("ProjectInformation")
10397
.EnsureSource(server, client)
10498
.RetrievePayloadAs<JObject>()
105-
.AssertProperty("Name", projectName);
99+
.AssertProperty("Name", project.Name);
106100

107101
projectInformation.RetrievePropertyAs<JArray>("Configurations")
108102
.AssertJArrayCount(2)
@@ -122,9 +116,6 @@ public void DthStartup_GetProjectInformation(DnxSdk sdk)
122116
[MemberData(nameof(ProtocolNegotiationTestData))]
123117
public void DthStartup_ProtocolNegotiation(DnxSdk sdk, int requestVersion, int expectVersion)
124118
{
125-
var projectName = "EmptyConsoleApp";
126-
var testProject = _fixture.GetTestProjectPath(projectName);
127-
128119
using (var server = DthTestServer.Create(sdk))
129120
using (var client = server.CreateClient())
130121
{
@@ -141,9 +132,6 @@ public void DthStartup_ProtocolNegotiation(DnxSdk sdk, int requestVersion, int e
141132
[MemberData(nameof(DnxSdks))]
142133
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed(DnxSdk sdk)
143134
{
144-
var projectName = "EmptyConsoleApp";
145-
var testProject = _fixture.GetTestProjectPath(projectName);
146-
147135
using (var server = DthTestServer.Create(sdk))
148136
using (var client = server.CreateClient())
149137
{
@@ -160,15 +148,17 @@ public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed(DnxSdk sdk)
160148
[MemberData(nameof(RuntimeComponentsWithBothVersions))]
161149
public void DthCompilation_GetDiagnostics_OnEmptyConsoleApp(DnxSdk sdk, int protocolVersion)
162150
{
163-
var projectName = "EmptyConsoleApp";
164-
var testProject = _fixture.GetTestProjectPath(projectName);
165-
166151
using (var server = DthTestServer.Create(sdk))
167152
using (var client = server.CreateClient())
168153
{
154+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
155+
var project = solution.GetProject("EmptyConsoleApp");
156+
157+
sdk.Dnu.Restore(project).EnsureSuccess();
158+
169159
// Drain the inital messages
170-
client.Initialize(testProject, protocolVersion);
171-
client.SendPayLoad(testProject, "GetDiagnostics");
160+
client.Initialize(project.ProjectDirectory, protocolVersion);
161+
client.SendPayLoad(project, "GetDiagnostics");
172162

173163
var diagnosticsGroup = client.DrainTillFirst("AllDiagnostics")
174164
.EnsureSource(server, client)
@@ -188,27 +178,28 @@ public void DthCompilation_GetDiagnostics_OnEmptyConsoleApp(DnxSdk sdk, int prot
188178
[MemberData(nameof(RuntimeComponentsWithBothVersions))]
189179
public void DthCompilation_RestoreComplete_OnEmptyLibrary(DnxSdk sdk, int protocolVersion)
190180
{
191-
var projectName = "EmptyLibrary";
192-
193-
string testProject;
194-
using (_fixture.CreateDisposableTestProject(projectName, sdk, out testProject))
195181
using (var server = DthTestServer.Create(sdk))
196182
using (var client = server.CreateClient())
197183
{
184+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
185+
var project = solution.GetProject("EmptyLibrary");
186+
187+
sdk.Dnu.Restore(project).EnsureSuccess();
188+
198189
// Drain the inital messages
199-
client.Initialize(testProject, protocolVersion);
190+
client.Initialize(project.ProjectDirectory, protocolVersion);
200191

201192
client.DrainTillFirst("Dependencies")
202193
.EnsureSource(server, client)
203194
.EnsureNotContainDependency("System.Console");
204195

205-
File.Copy(Path.Combine(testProject, "project-update.json"),
206-
Path.Combine(testProject, "project.json"),
196+
File.Copy(Path.Combine(project.ProjectDirectory, "project-update.json"),
197+
Path.Combine(project.ProjectDirectory, "project.json"),
207198
overwrite: true);
208199

209-
sdk.Dnu.Restore(testProject).EnsureSuccess();
200+
sdk.Dnu.Restore(project).EnsureSuccess();
210201

211-
client.SendPayLoad(testProject, "RestoreComplete");
202+
client.SendPayLoad(project, "RestoreComplete");
212203

213204
client.DrainTillFirst("Dependencies")
214205
.EnsureSource(server, client)
@@ -221,28 +212,32 @@ public void DthCompilation_RestoreComplete_OnEmptyLibrary(DnxSdk sdk, int protoc
221212
public void DthCompilation_Initialize_UnresolvedDependency(DnxSdk sdk, int protocolVersion, string referenceType, string testProjectName,
222213
string expectedUnresolvedDependency, string expectedUnresolvedType)
223214
{
224-
var testProject = _fixture.GetTestProjectPath(testProjectName);
225-
226215
using (var server = DthTestServer.Create(sdk))
227216
using (var client = server.CreateClient())
228217
{
229-
client.Initialize(testProject, protocolVersion);
218+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
219+
var project = solution.GetProject(testProjectName);
220+
221+
sdk.Dnu.Restore(project);
222+
223+
client.Initialize(project.ProjectDirectory, protocolVersion);
230224

231225
var messages = client.DrainAllMessages();
232226

233227
var unresolveDependency = messages.RetrieveSingleMessage("Dependencies")
234228
.EnsureSource(server, client)
235229
.RetrieveDependency(expectedUnresolvedDependency);
230+
236231
unresolveDependency.AssertProperty("Name", expectedUnresolvedDependency)
237232
.AssertProperty("DisplayName", expectedUnresolvedDependency)
238233
.AssertProperty("Resolved", false)
239234
.AssertProperty("Type", expectedUnresolvedType);
240235

241236
if (expectedUnresolvedType == "Project")
242237
{
243-
unresolveDependency.AssertProperty(
244-
"Path",
245-
Path.Combine(Path.GetDirectoryName(testProject), expectedUnresolvedDependency, Project.ProjectFileName));
238+
unresolveDependency.AssertProperty("Path", Path.Combine(Path.GetDirectoryName(project.ProjectDirectory),
239+
expectedUnresolvedDependency,
240+
Project.ProjectFileName));
246241
}
247242
else
248243
{
@@ -254,7 +249,9 @@ public void DthCompilation_Initialize_UnresolvedDependency(DnxSdk sdk, int proto
254249

255250
if (referenceType == "Project")
256251
{
257-
var expectedUnresolvedProjectPath = Path.Combine(Path.GetDirectoryName(testProject), expectedUnresolvedDependency, Project.ProjectFileName);
252+
var expectedUnresolvedProjectPath = Path.Combine(Path.GetDirectoryName(project.ProjectDirectory),
253+
expectedUnresolvedDependency,
254+
Project.ProjectFileName);
258255

259256
referencesMessage.RetrievePayloadAs<JObject>()
260257
.RetrievePropertyAs<JArray>("ProjectReferences")
@@ -277,25 +274,30 @@ public void DthCompilation_Initialize_UnresolvedDependency(DnxSdk sdk, int proto
277274
[MemberData(nameof(DnxSdks))]
278275
public void DthNegative_BrokenProjectPathInLockFile_V1(DnxSdk sdk)
279276
{
280-
var testProject = _fixture.GetTestProjectPath("BrokenProjectPathSample");
277+
var projectName = "BrokenProjectPathSample";
278+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
279+
var project = solution.GetProject(projectName);
280+
281+
sdk.Dnu.Restore(project).EnsureSuccess();
281282

282283
using (var disposableDir = new DisposableDir())
283284
using (var server = DthTestServer.Create(sdk))
284285
using (var client = server.CreateClient())
285286
{
286-
// copy the project to difference location so that the project path in its lock file is invalid
287-
var targetPath = Path.Combine(disposableDir, "BrokenProjectPathSample");
288-
Testing.TestUtils.CopyFolder(testProject, targetPath);
287+
// After restore the project is copied to another place so that
288+
// the relative path in project lock file is invalid.
289+
var movedProjectPath = Path.Combine(disposableDir, projectName);
290+
TestUtils.CopyFolder(project.ProjectDirectory, movedProjectPath);
289291

290-
client.Initialize(targetPath, protocolVersion: 1);
292+
client.Initialize(movedProjectPath, protocolVersion: 1);
291293
var messages = client.DrainAllMessages()
292294
.AssertDoesNotContain("Error");
293295

294296
var error = messages.RetrieveSingleMessage("DependencyDiagnostics")
295297
.RetrieveDependencyDiagnosticsCollection()
296298
.RetrieveDependencyDiagnosticsErrorAt<JValue>(0);
297299

298-
Assert.Contains("error NU1001: The dependency EmptyLibrary could not be resolved.", error.Value<string>());
300+
Assert.Contains("error NU1002", error.Value<string>());
299301

300302
messages.RetrieveSingleMessage("Dependencies")
301303
.RetrieveDependency("EmptyLibrary")
@@ -308,24 +310,29 @@ public void DthNegative_BrokenProjectPathInLockFile_V1(DnxSdk sdk)
308310
[MemberData(nameof(DnxSdks))]
309311
public void DthNegative_BrokenProjectPathInLockFile_V2(DnxSdk sdk)
310312
{
311-
var testProject = _fixture.GetTestProjectPath("BrokenProjectPathSample");
313+
var projectName = "BrokenProjectPathSample";
314+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthTestProjects");
315+
var project = solution.GetProject(projectName);
316+
317+
sdk.Dnu.Restore(project).EnsureSuccess();
312318

313319
using (var disposableDir = new DisposableDir())
314320
using (var server = DthTestServer.Create(sdk))
315321
using (var client = server.CreateClient())
316322
{
317-
// copy the project to difference location so that the project path in its lock file is invalid
318-
var targetPath = Path.Combine(disposableDir, "BrokenProjectPathSample");
319-
Testing.TestUtils.CopyFolder(testProject, targetPath);
323+
// After restore the project is copied to another place so that
324+
// the relative path in project lock file is invalid.
325+
var movedProjectPath = Path.Combine(disposableDir, projectName);
326+
TestUtils.CopyFolder(project.ProjectDirectory, movedProjectPath);
320327

321-
client.Initialize(targetPath, protocolVersion: 2);
328+
client.Initialize(movedProjectPath, protocolVersion: 2);
322329
var messages = client.DrainAllMessages()
323330
.AssertDoesNotContain("Error");
324331

325332
messages.RetrieveSingleMessage("DependencyDiagnostics")
326333
.RetrieveDependencyDiagnosticsCollection()
327334
.RetrieveDependencyDiagnosticsErrorAt(0)
328-
.AssertProperty<string>("FormattedMessage", message => message.Contains("error NU1001: The dependency EmptyLibrary could not be resolved."))
335+
.AssertProperty<string>("FormattedMessage", message => message.Contains("error NU1002"))
329336
.RetrievePropertyAs<JObject>("Source")
330337
.AssertProperty("Name", "EmptyLibrary");
331338

@@ -342,15 +349,12 @@ public void DthNegative_BrokenProjectPathInLockFile_V2(DnxSdk sdk)
342349
[MemberData(nameof(DnxSdks))]
343350
public void DthDependencies_UpdateGlobalJson_RefreshDependencies(DnxSdk sdk)
344351
{
345-
using (var disposableDir = new DisposableDir())
346352
using (var server = DthTestServer.Create(sdk))
347353
using (var client = server.CreateClient())
348354
{
349-
Testing.TestUtils.CopyFolder(
350-
_fixture.GetTestProjectPath("UpdateSearchPathSample"),
351-
Path.Combine(disposableDir, "UpdateSearchPathSample"));
355+
var solution = TestUtils.GetSolution<DthStartupTests>(sdk, "DthUpdateSearchPathSample");
352356

353-
var root = Path.Combine(disposableDir, "UpdateSearchPathSample", "home");
357+
var root = Path.Combine(solution.RootPath, "home");
354358
sdk.Dnu.Restore(root).EnsureSuccess();
355359

356360
var testProject = Path.Combine(root, "src", "MainProject");

test/Microsoft.Dnx.DesignTimeHost.FunctionalTests/Infrastructure/DthFunctionalTestCollection.cs

-12
This file was deleted.

test/Microsoft.Dnx.DesignTimeHost.FunctionalTests/Infrastructure/DthFunctionalTestFixture.cs

-77
This file was deleted.

0 commit comments

Comments
 (0)