Add more assembly version testing for SharedFx/Targeting pack (#25474)
* Add more assembly version tests packs * Add more tests * Fix test, feedback
This commit is contained in:
parent
6cd4d8bd68
commit
b434b8e3f3
|
|
@ -2,8 +2,12 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using System.Reflection.PortableExecutable;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
@ -81,7 +85,7 @@ namespace Microsoft.AspNetCore
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItContainsValidRuntimeConfigFile()
|
public void SharedFrameworkContainsValidRuntimeConfigFile()
|
||||||
{
|
{
|
||||||
var runtimeConfigFilePath = Path.Combine(_sharedFxRoot, "Microsoft.AspNetCore.App.runtimeconfig.json");
|
var runtimeConfigFilePath = Path.Combine(_sharedFxRoot, "Microsoft.AspNetCore.App.runtimeconfig.json");
|
||||||
|
|
||||||
|
|
@ -98,7 +102,7 @@ namespace Microsoft.AspNetCore
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItContainsValidDepsJson()
|
public void SharedFrameworkContainsValidDepsJson()
|
||||||
{
|
{
|
||||||
var depsFilePath = Path.Combine(_sharedFxRoot, "Microsoft.AspNetCore.App.deps.json");
|
var depsFilePath = Path.Combine(_sharedFxRoot, "Microsoft.AspNetCore.App.deps.json");
|
||||||
|
|
||||||
|
|
@ -155,6 +159,46 @@ namespace Microsoft.AspNetCore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SharedFrameworkAssembliesHaveExpectedAssemblyVersions()
|
||||||
|
{
|
||||||
|
// Only test managed assemblies
|
||||||
|
IEnumerable<string> dlls = Directory.GetFiles(_sharedFxRoot, "*.dll", SearchOption.AllDirectories).Where(i => !i.Contains("aspnetcorev2_inprocess"));
|
||||||
|
Assert.NotEmpty(dlls);
|
||||||
|
|
||||||
|
Assert.All(dlls, path =>
|
||||||
|
{
|
||||||
|
using var fileStream = File.OpenRead(path);
|
||||||
|
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
|
||||||
|
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
|
||||||
|
var assemblyDefinition = reader.GetAssemblyDefinition();
|
||||||
|
|
||||||
|
// Assembly versions should all match Major.Minor.0.0
|
||||||
|
Assert.Equal(0, assemblyDefinition.Version.Build);
|
||||||
|
Assert.Equal(0, assemblyDefinition.Version.Revision);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SharedFrameworkAssemblyReferencesHaveExpectedAssemblyVersions()
|
||||||
|
{
|
||||||
|
IEnumerable<string> dlls = Directory.GetFiles(_sharedFxRoot, "*.dll", SearchOption.AllDirectories).Where(i => !i.Contains("aspnetcorev2_inprocess") && !i.Contains("System.Security.Cryptography.Xml", StringComparison.OrdinalIgnoreCase));
|
||||||
|
Assert.NotEmpty(dlls);
|
||||||
|
|
||||||
|
Assert.All(dlls, path =>
|
||||||
|
{
|
||||||
|
using var fileStream = File.OpenRead(path);
|
||||||
|
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
|
||||||
|
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
|
||||||
|
|
||||||
|
Assert.All(reader.AssemblyReferences, handle =>
|
||||||
|
{
|
||||||
|
var reference = reader.GetAssemblyReference(handle);
|
||||||
|
Assert.Equal(0, reference.Version.Revision);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItContainsVersionFile()
|
public void ItContainsVersionFile()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,31 @@ namespace Microsoft.AspNetCore
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RefAssemblyReferencesHaveExpectedAssemblyVersions()
|
||||||
|
{
|
||||||
|
if (!_isTargetingPackBuilding)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<string> dlls = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll", SearchOption.AllDirectories);
|
||||||
|
Assert.NotEmpty(dlls);
|
||||||
|
|
||||||
|
Assert.All(dlls, path =>
|
||||||
|
{
|
||||||
|
using var fileStream = File.OpenRead(path);
|
||||||
|
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
|
||||||
|
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
|
||||||
|
|
||||||
|
Assert.All(reader.AssemblyReferences, handle =>
|
||||||
|
{
|
||||||
|
var reference = reader.GetAssemblyReference(handle);
|
||||||
|
Assert.Equal(0, reference.Version.Revision);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void PackageOverridesContainsCorrectEntries()
|
public void PackageOverridesContainsCorrectEntries()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue