Skip to content

Commit

Permalink
Update tests to always expect file versions in deps.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Apr 20, 2018
1 parent 5f34610 commit d29e8a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public void Versions_are_included_in_deps_json()
var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier);
publishDirectory.Should().HaveFile(testProject.Name + ".deps.json");

var depsFilePath = Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json");
CheckVersionsInDepsFile(depsFilePath);
}

void CheckVersionsInDepsFile(string depsFilePath)
{
DependencyContext dependencyContext;
using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json")))
using (var depsJsonFileStream = File.OpenRead(depsFilePath))
{
dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);
}
Expand All @@ -84,18 +90,18 @@ public void Versions_are_included_in_deps_json()
}

[Fact]
public void Versions_are_not_included_for_self_contained_apps()
public void Versions_are_included_for_self_contained_apps()
{
Versions_are_not_included(build: false);
Versions_are_included(build: false);
}

[Fact]
public void Versions_are_not_included_for_build()
public void Versions_are_included_for_build()
{
Versions_are_not_included(build: true);
Versions_are_included(build: true);
}

private void Versions_are_not_included(bool build, [CallerMemberName] string callingMethod = "")
private void Versions_are_included(bool build, [CallerMemberName] string callingMethod = "")
{
var testProject = GetTestProject();
testProject.RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(testProject.TargetFrameworks);
Expand All @@ -120,22 +126,8 @@ private void Versions_are_not_included(bool build, [CallerMemberName] string cal
var outputDirectory = command.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier);
outputDirectory.Should().HaveFile(testProject.Name + ".deps.json");

DependencyContext dependencyContext;
using (var depsJsonFileStream = File.OpenRead(Path.Combine(outputDirectory.FullName, $"{testProject.Name}.deps.json")))
{
dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);
}

var allRuntimeFiles = dependencyContext.RuntimeLibraries.SelectMany(rl => rl.NativeLibraryGroups.Concat(rl.RuntimeAssemblyGroups))
.SelectMany(rag => rag.RuntimeFiles);

allRuntimeFiles.Should().NotBeEmpty();

foreach (var runtimeFile in allRuntimeFiles)
{
runtimeFile.AssemblyVersion.Should().BeNull();
runtimeFile.FileVersion.Should().BeNull();
}
var depsFilePath = Path.Combine(outputDirectory.FullName, $"{testProject.Name}.deps.json");
CheckVersionsInDepsFile(depsFilePath);
}

[Fact(Skip = "Host deps.json doesn't have runtime file version info yet: https://github.com/dotnet/sdk/issues/2124")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<PackageReference Include="Microsoft.DotNet.Cli.Utils" Version="$(MicrosoftDotNetCliUtilsVersion)" />
<PackageReference Include="NuGet.Packaging.Core" Version="$(NuGetPackagingVersion)" />
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetPackagingVersion)" />

<!-- Referenced explicitly here because Microsoft.DotNet.Cli.Utils references a lower version at the moment, which causes
RAR conflicts (though ideally I would think NuGet would resolve this) -->
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit d29e8a5

Please sign in to comment.