-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TestCentric/issue-15
Add tests
- Loading branch information
Showing
5 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace TestCentric.Metadata | ||
{ | ||
public class AssemblyTests | ||
{ | ||
static string THIS_ASSEMBLY = Assembly.GetExecutingAssembly().Location; | ||
|
||
AssemblyDefinition _assemblyDef; | ||
|
||
|
||
[OneTimeSetUp] | ||
public void CreateAssemblyDefinition() | ||
{ | ||
_assemblyDef = AssemblyDefinition.ReadAssembly(THIS_ASSEMBLY); | ||
} | ||
|
||
[Test] | ||
public void CheckAttribute() | ||
{ | ||
var titleAttr = GetCustomAttribute("System.Reflection.AssemblyTitleAttribute"); | ||
|
||
Assert.NotNull(titleAttr, "Title Attribute not found"); | ||
|
||
var args = titleAttr.ConstructorArguments; | ||
Assert.That(args.Count, Is.EqualTo(1)); | ||
Assert.That(args[0].Value, Is.EqualTo("TestCentric.Metadata Tests")); | ||
} | ||
|
||
[TestCase("nunit.framework")] | ||
[TestCase("testcentric.engine.metadata")] | ||
public void HasAssemblyReference(string name) | ||
{ | ||
Assert.That(HasReferenceTo(name)); | ||
} | ||
|
||
[Test] | ||
public void GetFrameworkName() | ||
{ | ||
#if NET35 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(null)); | ||
#elif NET40 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETFramework,Version=v4.0")); | ||
#elif NET45 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETFramework,Version=v4.5")); | ||
#elif NETCOREAPP2_1 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETCoreApp,Version=v2.1")); | ||
#elif NETCOREAPP3_1 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETCoreApp,Version=v3.1")); | ||
#elif NET5_0 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETCoreApp,Version=v5.0")); | ||
#elif NET6_0 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETCoreApp,Version=v6.0")); | ||
#elif NET7_0 | ||
Assert.That(_assemblyDef.GetFrameworkName(), Is.EqualTo(".NETCoreApp,Version=v7.0")); | ||
#else | ||
Assert.Fail($"Untested target runtime: {_assemblyDef.GetFrameworkName()}"); | ||
#endif | ||
} | ||
|
||
[Test] | ||
public void GetRuntimeVersion() | ||
{ | ||
#if NET35 | ||
Assert.That(_assemblyDef.GetRuntimeVersion(), Is.EqualTo(new Version(2, 0, 50727))); | ||
#else | ||
Assert.That(_assemblyDef.GetRuntimeVersion(), Is.EqualTo(new Version(4, 0, 30319))); | ||
#endif | ||
} | ||
|
||
private CustomAttribute GetCustomAttribute(string fullName) | ||
{ | ||
foreach (var attr in _assemblyDef.CustomAttributes) | ||
if (attr.AttributeType.FullName == fullName) | ||
return attr; | ||
|
||
return null; | ||
} | ||
|
||
private bool HasReferenceTo(string name) | ||
{ | ||
foreach (var reference in _assemblyDef.MainModule.AssemblyReferences) | ||
if (reference.Name == name) | ||
return true; | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
using NUnitLite; | ||
|
||
namespace TestCentric.Metadata | ||
{ | ||
class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
#if NETFRAMEWORK | ||
return new AutoRun().Execute(args); | ||
#else | ||
return new TextRunner(typeof(Program).GetTypeInfo().Assembly).Execute(args); | ||
#endif | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/testcentric.engine.metadata.tests/testcentric.engine.metadata.tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net35;net40;net45;netcoreapp2.1;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks> | ||
<CheckEolTargetFramework>false</CheckEolTargetFramework> | ||
<RootNamespace>TestCentric.Metadata</RootNamespace> | ||
<OutputType>Exe</OutputType> | ||
<OutputPath>..\..\bin\$(Configuration)\tests\</OutputPath> | ||
<AssemblyTitle>TestCentric.Metadata Tests</AssemblyTitle> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnitLite" Version="3.13.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\testcentric.engine.metadata\testcentric.engine.metadata.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |