Skip to content

Commit 7cf7f45

Browse files
committed
Add more complicated unit test
This one prunes out 3/7 references
1 parent 4df737f commit 7cf7f45

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,80 @@ public void ItHandlesReferenceAndPackageReferenceNameCollisions()
220220
.Contain(c => c.Name == "System.Collections.NonGeneric.Reference.Reference" && c.Type == "referenceassembly");
221221
}
222222

223+
[Fact]
224+
public void ItHandlesReferencesThatCannotBeRemovedProperly()
225+
{
226+
string mainProjectName = "simple.dependencies";
227+
LockFile lockFile = TestLockFiles.GetLockFile(mainProjectName);
228+
229+
SingleProjectInfo mainProject = SingleProjectInfo.Create(
230+
"/usr/Path",
231+
mainProjectName,
232+
".dll",
233+
"1.0.0",
234+
[]);
235+
236+
ITaskItem[] referencePaths = new ITaskItem[]
237+
{
238+
new MockTaskItem(
239+
"/usr/Path/System.NotConflicting.dll",
240+
new Dictionary<string, string>
241+
{
242+
{ "CopyLocal", "false" },
243+
{ "FusionName", "System.NotConflicting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" },
244+
{ "Version", "" },
245+
}),
246+
new MockTaskItem(
247+
"/usr/Path/System.Collections.NonGeneric.dll",
248+
new Dictionary<string, string>
249+
{
250+
{ "CopyLocal", "false" },
251+
{ "FusionName", "System.Collections.NonGeneric, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" },
252+
{ "Version", "" },
253+
}),
254+
new MockTaskItem(
255+
"/usr/Path/System.Collections.NonGeneric.Reference.dll",
256+
new Dictionary<string, string>
257+
{
258+
{ "CopyLocal", "false" },
259+
{ "FusionName", "System.Collections.NonGeneric.Reference, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" },
260+
{ "Version", "" },
261+
}),
262+
};
263+
264+
ProjectContext projectContext = lockFile.CreateProjectContext(
265+
FrameworkConstants.CommonFrameworks.NetCoreApp10.GetShortFolderName(),
266+
runtime: null,
267+
platformLibraryName: Constants.DefaultPlatformLibrary,
268+
runtimeFrameworks: null,
269+
isSelfContained: false);
270+
271+
CompilationOptions compilationOptions = CreateCompilationOptions();
272+
273+
IEnumerable<ReferenceInfo> directReferences =
274+
ReferenceInfo.CreateDirectReferenceInfos(
275+
referencePaths,
276+
[],
277+
lockFileLookup: new LockFileLookup(lockFile),
278+
i => true,
279+
true);
280+
281+
DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph: null, projectContext: projectContext, libraryLookup: new LockFileLookup(lockFile))
282+
.WithReferenceAssemblies(ReferenceInfo.CreateReferenceInfos(referencePaths))
283+
.WithCompilationOptions(compilationOptions)
284+
.WithDirectReferences(directReferences)
285+
.Build();
286+
287+
// ensure the DependencyContext can be written out successfully - it has no duplicate dependency names
288+
Save(dependencyContext);
289+
290+
dependencyContext.RuntimeLibraries.Count.Should().Be(4);
291+
dependencyContext.RuntimeLibraries.Should().Contain(x => x.Name.Equals("simple.dependencies"));
292+
dependencyContext.RuntimeLibraries.Should().Contain(x => x.Name.Equals("System.NotConflicting"));
293+
dependencyContext.RuntimeLibraries.Should().Contain(x => x.Name.Equals("System.Collections.NonGeneric.Reference"));
294+
dependencyContext.RuntimeLibraries.Should().Contain(x => x.Name.Equals("System.Collections.NonGeneric.Reference.Reference"));
295+
}
296+
223297
private DependencyContext BuildDependencyContextWithReferenceAssemblies(bool useCompilationOptions)
224298
{
225299
string mainProjectName = "simple.dependencies";

0 commit comments

Comments
 (0)