Debian Codegraph @

external/nuget-buildtasks/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs

raw symbols SCIP
1 // Copyright (c) .NET Foundation. All rights reserved.
2 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
4 using System;
5 using System.IO;
6 using System.Linq;
7 using System.Text;
8 using Microsoft.NuGet.Build.Tasks.Tests.Helpers;
9 using Xunit;
10
11 namespace Microsoft.NuGet.Build.Tasks.Tests
12 {
13 public partial class ReferenceResolutionTests
14 {
15 [Fact]
16 public static void TestReferenceResolutionWithRuntimeIDWin10X86()
17 {
18 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
19 Json.Json.Win10,
20 targetMoniker: ".NETCore,Version=v5.0",
21 runtimeIdentifier: "win10-x86");
22
23 AssertHelpers.AssertCountOf(101, result.References);
24 AssertHelpers.AssertCountOf(119, result.CopyLocalItems);
25 AssertHelpers.AssertNoTargetPaths(result.CopyLocalItems);
26 }
27
28 [Fact]
29 public static void TestReferenceResolutionWithRuntimeIDWin10X64()
30 {
31 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
32 Json.Json.Win10,
33 targetMoniker: ".NETCore,Version=v5.0",
34 runtimeIdentifier: "win10-x64");
35
36 AssertHelpers.AssertCountOf(101, result.References);
37 AssertHelpers.AssertCountOf(119, result.CopyLocalItems);
38 AssertHelpers.AssertNoTargetPaths(result.CopyLocalItems);
39 }
40
41 [Fact]
42 public static void TestReferenceResolutionWithRuntimeIDWin10X86Aot()
43 {
44 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
45 Json.Json.Win10,
46 targetMoniker: ".NETCore,Version=v5.0",
47 runtimeIdentifier: "win10-x86-aot");
48
49 AssertHelpers.AssertCountOf(101, result.References);
50 AssertHelpers.AssertCountOf(141, result.CopyLocalItems);
51 AssertHelpers.AssertNoTargetPaths(result.CopyLocalItems);
52 }
53
54 [Fact]
55 public static void TestReferenceResolutionWithRuntimeIDWin10X64Aot()
56 {
57 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
58 Json.Json.Win10,
59 targetMoniker: ".NETCore,Version=v5.0",
60 runtimeIdentifier: "win10-x64-aot");
61
62 AssertHelpers.AssertCountOf(101, result.References);
63 AssertHelpers.AssertCountOf(141, result.CopyLocalItems);
64 AssertHelpers.AssertNoTargetPaths(result.CopyLocalItems);
65 }
66
67 [Fact]
68 public static void TestReferenceResolutionWithMissingRuntimeIDAndFallback()
69 {
70 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
71 Json.Json.Win10,
72 targetMoniker: ".NETCore,Version=v5.0",
73 runtimeIdentifier: "missing-runtime-identifier",
74 allowFallbackOnTargetSelection: true);
75
76 // We should still have references. We'll assert that CopyLocalItems contains something, but it's purely best
77 // effort and so there's no promise that it'll ever contain any specific items
78 AssertHelpers.AssertCountOf(101, result.References);
79 Assert.NotEmpty(result.CopyLocalItems);
80 }
81
82 [Fact]
83 public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallback()
84 {
85 var exception = Assert.Throws<ExceptionFromResource>(() =>
86 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
87 Json.Json.Win10,
88 targetMoniker: ".NETCore,Version=v5.0",
89 runtimeIdentifier: "missing-runtime-identifier",
90 allowFallbackOnTargetSelection: false));
91
92 Assert.Equal(nameof(Strings.MissingRuntimeInProjectJson), exception.ResourceName);
93 Assert.Equal(new[] { "missing-runtime-identifier", "\"missing-runtime-identifier\": { }" }, exception.MessageArgs);
94 }
95
96 [Fact]
97 public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackAndNoRuntimesSection()
98 {
99 var exception = Assert.Throws<ExceptionFromResource>(() =>
100 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
101 Json.Json.Win10,
102 targetMoniker: ".NETCore,Version=v5.0",
103 runtimeIdentifier: "missing-runtime-identifier",
104 allowFallbackOnTargetSelection: false,
105 projectJsonFileContents: "{ }"));
106
107 Assert.Equal(nameof(Strings.MissingRuntimesSectionInProjectJson), exception.ResourceName);
108 Assert.Equal(new[] { "\"runtimes\": { \"missing-runtime-identifier\": { } }" }, exception.MessageArgs);
109 }
110
111 [Fact]
112 public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackInProjectCsproj()
113 {
114 using (var tempRoot = new TempRoot())
115 using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
116 {
117 var exception = Assert.Throws<ExceptionFromResource>(() =>
118 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
119 Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length),
120 targetMoniker: ".NETFramework,Version=v4.5",
121 runtimeIdentifier: "missing-runtime-identifier",
122 allowFallbackOnTargetSelection: false,
123 isLockFileProjectJsonBased: false));
124
125 Assert.Equal(nameof(Strings.MissingRuntimeIdentifierInProjectFile), exception.ResourceName);
126 Assert.Equal(new[] { "missing-runtime-identifier", "missing-runtime-identifier" }, exception.MessageArgs);
127 }
128 }
129
130 [Fact]
131 public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackAndNoRuntimesSectionInProjectCsproj()
132 {
133 var exception = Assert.Throws<ExceptionFromResource>(() =>
134 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
135 Json.Json.Win10,
136 targetMoniker: ".NETCore,Version=v5.0",
137 runtimeIdentifier: "missing-runtime-identifier",
138 allowFallbackOnTargetSelection: false,
139 projectJsonFileContents: "{ }"));
140
141 Assert.Equal(nameof(Strings.MissingRuntimesSectionInProjectJson), exception.ResourceName);
142 Assert.Equal(new[] { "\"runtimes\": { \"missing-runtime-identifier\": { } }" }, exception.MessageArgs);
143 }
144
145 [Fact]
146 public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallback()
147 {
148 var exception = Assert.Throws<ExceptionFromResource>(() =>
149 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
150 Json.Json.Win10,
151 targetMoniker: "Missing,Version=1.0",
152 runtimeIdentifier: "missing-runtime-identifier",
153 allowFallbackOnTargetSelection: false));
154
155 Assert.Equal(nameof(Strings.MissingFrameworkInProjectJson), exception.ResourceName);
156 Assert.Equal(new[] { "Missing,Version=1.0" }, exception.MessageArgs);
157 }
158
159 [Fact]
160 public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallbackInProjectCsproj()
161 {
162 using (var tempRoot = new TempRoot())
163 using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
164 {
165 var exception = Assert.Throws<ExceptionFromResource>(() =>
166 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
167 Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length),
168 targetMoniker: "Missing,Version=1.0",
169 runtimeIdentifier: "missing-runtime-identifier",
170 allowFallbackOnTargetSelection: false,
171 isLockFileProjectJsonBased: false));
172
173 Assert.Equal(nameof(Strings.MissingFrameworkInProjectFile), exception.ResourceName);
174 Assert.Equal(new[] { "Missing,Version=1.0" }, exception.MessageArgs);
175 }
176 }
177
178 [Fact]
179 public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallback()
180 {
181 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
182 Json.Json.Win10,
183 targetMoniker: "MissingFrameworkMoniker,Version=v42.0",
184 runtimeIdentifier: "",
185 allowFallbackOnTargetSelection: true);
186
187 // We should still have references. Since we have no runtime ID, we should have no copy local items
188 AssertHelpers.AssertCountOf(101, result.References);
189 AssertHelpers.AssertCountOf(0, result.CopyLocalItems);
190 }
191
192 [Fact]
193 public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallbackInProjectCsproj()
194 {
195 using (var tempRoot = new TempRoot())
196 using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
197 {
198 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
199 Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length),
200 targetMoniker: "MissingFrameworkMoniker,Version=v42.0",
201 runtimeIdentifier: "",
202 allowFallbackOnTargetSelection: true,
203 isLockFileProjectJsonBased: false);
204
205 // We should still have references. Since we have no runtime ID, we should have no copy local items
206 AssertHelpers.AssertCountOf(1, result.References);
207 AssertHelpers.AssertCountOf(0, result.CopyLocalItems);
208 }
209 }
210
211 [Theory]
212 [InlineData(true, nameof(Strings.NoTargetsInLockFileForProjectJson))]
213 [InlineData(false, nameof(Strings.NoTargetsInLockFileForProjectFile))]
214 public static void TestReferenceResolutionWithMissingTargets(bool isProjectJsonBased, string errorResourceName)
215 {
216 using (var tempRoot = new TempRoot())
217 using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
218 {
219 var exception = Assert.Throws<ExceptionFromResource>(() =>
220 NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
221 Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length),
222 targetMoniker: "MissingFrameworkMoniker,Version=v42.0",
223 runtimeIdentifier: "",
224 allowFallbackOnTargetSelection: true,
225 isLockFileProjectJsonBased: isProjectJsonBased));
226
227 Assert.Equal(errorResourceName, exception.ResourceName);
228 }
229 }
230
231 [Fact]
232 public static void TestReferenceResolutionWithNoRuntimeID()
233 {
234 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
235 Json.Json.Win10,
236 targetMoniker: ".NETCore,Version=v5.0",
237 runtimeIdentifier: "");
238
239 // We should still have references, but no copy local
240 AssertHelpers.AssertCountOf(101, result.References);
241 AssertHelpers.AssertCountOf(0, result.CopyLocalItems);
242 }
243
244 [Fact]
245 public static void PackagesHaveMetadataWithPackageIdAndVersion()
246 {
247 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
248 Json.Json.Win10,
249 targetMoniker: ".NETCore,Version=v5.0",
250 runtimeIdentifier: "win10-x86");
251
252 var immutableCopyLocalitem = result.CopyLocalItems.Single(i => i.ItemSpec.EndsWith("System.Collections.Immutable.dll"));
253
254 Assert.Equal("System.Collections.Immutable", immutableCopyLocalitem.GetMetadata(ResolveNuGetPackageAssets.NuGetPackageIdMetadata));
255 Assert.Equal("1.1.36", immutableCopyLocalitem.GetMetadata(ResolveNuGetPackageAssets.NuGetPackageVersionMetadata));
256 }
257
258
259 [Fact]
260 public static void ReferencedPackagesCorrectlyParsed()
261 {
262 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
263 Json.Json.Win10,
264 targetMoniker: ".NETCore,Version=v5.0",
265 runtimeIdentifier: "");
266
267 // We should still have references, but no copy local
268 AssertHelpers.AssertCountOf(5, result.ReferencedPackages);
269
270 var packageNames = result.ReferencedPackages.Select(t => t.ItemSpec);
271
272 Assert.Contains("Microsoft.NETCore.UniversalWindowsPlatform", packageNames);
273 }
274
275 [Fact]
276 public static void ExcludingFrameworkReferencesActuallyExcludesFrameworkReferences()
277 {
278 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
279 Json.Json.FluentAssertions,
280 targetMoniker: ".NETFramework,Version=v4.5.2",
281 runtimeIdentifier: "",
282 includeFrameworkReferences: false);
283
284 // We should only have references from the core package
285 AssertHelpers.AssertCountOf(2, result.References);
286 Assert.True(result.References.All(r => r.ItemSpec.Contains("FluentAssertions")));
287
288 // This should still count as the reference to a package
289 var packageNames = result.ReferencedPackages.Select(t => t.ItemSpec);
290 Assert.Contains("FluentAssertions", packageNames);
291 }
292
293 [Fact]
294 public static void IncludingFrameworkReferencesActuallyIncludesFrameworkReferences()
295 {
296 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
297 Json.Json.FluentAssertions,
298 targetMoniker: ".NETFramework,Version=v4.5.2",
299 runtimeIdentifier: "",
300 includeFrameworkReferences: true);
301
302 // We should have references to the package itself plus framework packages
303 AssertHelpers.AssertCountOf(4, result.References);
304 Assert.True(result.References.All(r => r.ItemSpec.Contains("FluentAssertions") ||
305 r.ItemSpec == "System.Xml" ||
306 r.ItemSpec == "System.Xml.Linq"));
307
308 // This should still count as the reference to a package
309 var packageNames = result.ReferencedPackages.Select(t => t.ItemSpec);
310 Assert.Contains("FluentAssertions", packageNames);
311 }
312
313 [Fact]
314 public static void AllPackageReferencesAreMarkedAsSuch()
315 {
316 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
317 Json.Json.FluentAssertions,
318 targetMoniker: ".NETFramework,Version=v4.5.2",
319 runtimeIdentifier: "",
320 includeFrameworkReferences: true);
321
322 // We should have references to the package itself plus framework packages
323 AssertHelpers.AssertCountOf(4, result.References);
324 Assert.All(result.References, r => Assert.Equal(ResolveNuGetPackageAssets.NuGetSourceType_Package, r.GetMetadata(ResolveNuGetPackageAssets.NuGetSourceType)));
325 }
326
327 [Fact]
328 public static void CopyLocalContentsIncludePdbsIfAvailable()
329 {
330 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
331 Json.Json.FluentAssertionsAndWin10,
332 targetMoniker: "UAP,Version=v10.0",
333 runtimeIdentifier: "win10-x86",
334 includeFrameworkReferences: true);
335
336 Assert.Single(result.CopyLocalItems, r => r.ItemSpec.EndsWithPath("FluentAssertions.dll"));
337 Assert.Single(result.CopyLocalItems, r => r.ItemSpec.EndsWithPath("FluentAssertions.pdb"));
338 Assert.Single(result.CopyLocalItems, r => r.ItemSpec.EndsWithPath("FluentAssertions.Core.dll"));
339 Assert.Single(result.CopyLocalItems, r => r.ItemSpec.EndsWithPath("FluentAssertions.Core.pdb"));
340 }
341
342 [Fact]
343 public static void FrameworkReferencesAreNotProvidedIfAlreadyProvidedByAnotherPackage()
344 {
345 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
346 Json.Json.FluentAssertionsAndWin10,
347 targetMoniker: "UAP,Version=v10.0",
348 runtimeIdentifier: "",
349 includeFrameworkReferences: true);
350
351 // There should be exactly one reference to System.Xml.dll, and no other references
352 Assert.Single(result.References.Where(r => r.ItemSpec.EndsWith("System.Xml.dll")));
353 Assert.Empty(result.References.Where(r => r.ItemSpec == "System.Xml"));
354 }
355
356 [Fact]
357 public static void AllNuGetReferencesHaveValidIsFrameworkReferenceProperty()
358 {
359 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
360 Json.Json.FluentAssertions,
361 targetMoniker: ".NETFramework,Version=v4.5.2",
362 runtimeIdentifier: "");
363
364 var key = ResolveNuGetPackageAssets.NuGetIsFrameworkReference;
365 var values = result.References.Select(r => r.GetMetadata(key));
366
367 Assert.All(result.References, r => Assert.Contains(key, r.MetadataNames.Cast<string>()));
368 Assert.All(values, v => Assert.Contains(v, new[] { "true", "false" }));
369 }
370
371 [Fact]
372 public static void AllReferencesHaveCorrectIsFrameworkReferenceProperty()
373 {
374 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
375 Json.Json.FluentAssertions,
376 targetMoniker: ".NETFramework,Version=v4.5.2",
377 runtimeIdentifier: "");
378
379 var references = result.References.ToDictionary(
380 r => r.ItemSpec,
381 r => r.GetMetadata(ResolveNuGetPackageAssets.NuGetIsFrameworkReference)
382 );
383
384 AssertHelpers.AssertCountOf(4, result.References);
385
386 var corePath = Path.Combine(result.ReferenceTemporaryPath, @"FluentAssertions\3.4.1\lib\net45\FluentAssertions.Core.dll");
387 Assert.True(references.ContainsKey(corePath));
388 Assert.Equal("false", references[corePath]);
389
390 var mainPath = Path.Combine(result.ReferenceTemporaryPath, @"FluentAssertions\3.4.1\lib\net45\FluentAssertions.dll");
391 Assert.True(references.ContainsKey(mainPath));
392 Assert.Equal("false", references[mainPath]);
393
394 Assert.Equal("true", references["System.Xml"]);
395 Assert.Equal("true", references["System.Xml.Linq"]);
396 }
397
398 [Fact]
399 public static void NativeWinMDSetsMetadata()
400 {
401 string imageRuntimeVersion = "WindowsRuntime 1.3";
402 TryGetRuntimeVersion tryGetRuntimeVersion = p => imageRuntimeVersion;
403 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
404 Json.Json.nativeWinMD,
405 targetMoniker: ".NETCore,Version=v5.0",
406 runtimeIdentifier: "win10-x86",
407 tryGetRuntimeVersion: tryGetRuntimeVersion);
408
409 var winmd = result.CopyLocalItems.FirstOrDefault(c =>
410 Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
411
412 Assert.NotNull(winmd);
413 Assert.Equal(imageRuntimeVersion, winmd.GetMetadata("ImageRuntime"));
414 Assert.Equal("true", winmd.GetMetadata("WinMDFile"));
415 Assert.Equal("Native", winmd.GetMetadata("WinMDFileType"));
416 Assert.False(string.IsNullOrEmpty(winmd.GetMetadata("Implementation")), "implementation should be set for native winmd");
417 Assert.Equal(Path.GetFileNameWithoutExtension(winmd.ItemSpec) + ".dll", winmd.GetMetadata("Implementation"), StringComparer.OrdinalIgnoreCase);
418 }
419
420 [Fact]
421 public static void ManagedWinMDDoesNotSetsMetadata()
422 {
423 string imageRuntimeVersion = "WindowsRuntime 1.4;CLR v4.0.30319";
424 TryGetRuntimeVersion tryGetRuntimeVersion = p => imageRuntimeVersion;
425 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
426 Json.Json.nativeWinMD,
427 targetMoniker: ".NETCore,Version=v5.0",
428 runtimeIdentifier: "win10-x86",
429 tryGetRuntimeVersion: tryGetRuntimeVersion);
430
431 var winmd = result.CopyLocalItems.FirstOrDefault(c =>
432 Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
433
434 Assert.NotNull(winmd);
435 Assert.Equal(imageRuntimeVersion, winmd.GetMetadata("ImageRuntime"));
436 Assert.Equal("true", winmd.GetMetadata("WinMDFile"));
437 Assert.Equal("Managed", winmd.GetMetadata("WinMDFileType"));
438 Assert.True(string.IsNullOrEmpty(winmd.GetMetadata("Implementation")), "implementation should not be set for managed winmd");
439 }
440
441 [Fact]
442 public static void BogusWinMDDoesNotSetImplementation()
443 {
444 string imageRuntimeVersion = "BogusRuntime 1.4;C1R v4.0.30319";
445 TryGetRuntimeVersion tryGetRuntimeVersion = p => imageRuntimeVersion;
446 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
447 Json.Json.nativeWinMD,
448 targetMoniker: ".NETCore,Version=v5.0",
449 runtimeIdentifier: "win10-x86",
450 tryGetRuntimeVersion: tryGetRuntimeVersion);
451
452 var winmd = result.CopyLocalItems.FirstOrDefault(c =>
453 Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
454
455 Assert.NotNull(winmd);
456 Assert.Equal(imageRuntimeVersion, winmd.GetMetadata("ImageRuntime"));
457 Assert.True(string.IsNullOrEmpty(winmd.GetMetadata("WinMDFile")));
458 Assert.True(string.IsNullOrEmpty(winmd.GetMetadata("WinMDFileType")));
459 Assert.True(string.IsNullOrEmpty(winmd.GetMetadata("Implementation")), "implementation should not be set for bogus winmd");
460 }
461
462 [Fact]
463 public static void TestTargetPathCollisionsFound()
464 {
465 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
466 Json.Json.Win10_Edm,
467 targetMoniker: ".NETCore,Version=v5.0",
468 runtimeIdentifier: "win10-x86");
469
470 AssertHelpers.AssertConsistentTargetPaths(result.CopyLocalItems);
471 }
472
473 [Fact]
474 public static void TestTargetPathCollisionsFound2()
475 {
476 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
477 Json.Json.Win10_xunit,
478 targetMoniker: ".NETCore,Version=v5.0",
479 runtimeIdentifier: "win10-x86");
480
481 AssertHelpers.AssertConsistentTargetPaths(result.CopyLocalItems);
482 }
483
484 [Fact]
485 public static void MultipleProjectFileDependencyGroups()
486 {
487 var resultFor45 = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
488 Json.Json.MultipleProjectFileDependencyGroups,
489 targetMoniker: ".NETFramework,Version=v4.5",
490 runtimeIdentifier: "win",
491 allowFallbackOnTargetSelection: true);
492
493 var packageNames = resultFor45.ReferencedPackages.Select(t => t.ItemSpec);
494
495 Assert.Equal("Newtonsoft.Json", packageNames.Single());
496
497 var resultFor46 = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
498 Json.Json.MultipleProjectFileDependencyGroups,
499 targetMoniker: ".NETFramework,Version=v4.6",
500 runtimeIdentifier: "win",
501 allowFallbackOnTargetSelection: true);
502
503 AssertHelpers.AssertCountOf(1, resultFor46.ReferencedPackages);
504
505 packageNames = resultFor46.ReferencedPackages.Select(t => t.ItemSpec);
506
507 Assert.Contains("FluentAssertions", packageNames);
508 }
509
510 // Regression test for https://devdiv.visualstudio.com/DevDiv/_workitems?id=500532&_a=edit
511 [Fact]
512 public static void MultipleProjectFileDependencyGroups_MismatchedCases()
513 {
514 var resultFor45 = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
515 Json.Json.MultipleProjectFileDependencyGroups_CaseMismatch,
516 targetMoniker: ".NETFramework,Version=v4.5",
517 runtimeIdentifier: "win",
518 allowFallbackOnTargetSelection: true);
519
520 var packageNames = resultFor45.ReferencedPackages.Select(t => t.ItemSpec);
521
522 Assert.Equal("Newtonsoft.Json", packageNames.Single(), ignoreCase: true);
523
524 var resultFor46 = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
525 Json.Json.MultipleProjectFileDependencyGroups,
526 targetMoniker: ".NETFramework,Version=v4.6",
527 runtimeIdentifier: "win",
528 allowFallbackOnTargetSelection: true);
529
530 AssertHelpers.AssertCountOf(1, resultFor46.ReferencedPackages);
531
532 packageNames = resultFor46.ReferencedPackages.Select(t => t.ItemSpec);
533
534 Assert.Equal("FluentAssertions", packageNames.Single(), ignoreCase: true);
535 }
536
537 [Fact]
538 public static void ProjectsNotIncludedInReferences()
539 {
540 var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
541 Json.Json.ProjectDependency,
542 targetMoniker: ".NETFramework,Version=v4.5.2",
543 runtimeIdentifier: "win");
544
545 Assert.DoesNotContain("ClassLibrary1", result.ReferencedPackages.Select(t => t.ItemSpec));
546 }
547 }
548 }