Skip to content

Commit

Permalink
Add TestEngine.GetAssemblyMetadataAttributes to get `AssemblyMetada…
Browse files Browse the repository at this point in the history
…taAttribute` from `assemblyFile`.
  • Loading branch information
ricaun committed Dec 7, 2024
1 parent 02876cf commit b21d75e
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 102 deletions.
199 changes: 100 additions & 99 deletions Build/.nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,69 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Build",
"Clean",
"Compile",
"GitPreRelease",
"GitRelease",
"Pack",
"PrePack",
"Release",
"Sign",
"Test"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"Folder": {
"type": "string"
},
"GitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
},
"Host": {
"type": "string",
"description": "Host for execution. Default is 'automatic'",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"MainName": {
"type": "string"
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"NugetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NugetApiUrl": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
Expand All @@ -65,15 +72,61 @@
"type": "boolean",
"description": "Shows the execution plan (HTML)"
},
"PreReleaseFilter": {
"Profile": {
"type": "array",
"description": "Defines the profiles to load",
"items": {
"type": "string"
}
},
"Profile": {
"Root": {
"type": "string",
"description": "Root directory during build execution"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"$ref": "#/definitions/ExecutableTarget"
}
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"description": "Logging verbosity during build execution. Default is 'Normal'",
"$ref": "#/definitions/Verbosity"
}
}
}
},
"allOf": [
{
"properties": {
"Folder": {
"type": "string"
},
"GitHubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"MainName": {
"type": "string"
},
"NugetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NugetApiUrl": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"PreReleaseFilter": {
"type": "array",
"description": "Defines the profiles to load",
"items": {
"type": "string"
}
Expand All @@ -84,10 +137,6 @@
"ReleaseNameVersion": {
"type": "boolean"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
},
"SignFile": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
Expand All @@ -96,48 +145,10 @@
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"Build",
"Clean",
"Compile",
"GitPreRelease",
"GitRelease",
"Pack",
"PrePack",
"Release",
"Sign",
"Test"
]
}
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"Build",
"Clean",
"Compile",
"GitPreRelease",
"GitRelease",
"Pack",
"PrePack",
"Release",
"Sign",
"Test"
]
}
},
"TestBuildStopWhenFailed": {
"type": "boolean"
},
Expand All @@ -146,21 +157,11 @@
},
"TestResults": {
"type": "boolean"
},
"UnlistNuget": {
"type": "boolean"
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
]
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
}
]
}
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.1] / 2024-12-07
### Updates
- Add `TestEngine.GetAssemblyMetadataAttributes` to get `AssemblyMetadataAttribute` from `assemblyFile`.

## [1.4.0] / 2024-09-11
### Features
- Support `TestCaseSourceAttribute` with `IEnumerable` and `object[]` parameters. (Fix: #27)
Expand Down Expand Up @@ -236,14 +240,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.0.0] / 2022-08-18
### Features
- Test Assembly with diferent NUnit Version with LoadFile
- Test Assembly with different NUnit Version with LoadFile
- Test Methods with Attribute Name
- Test if Assembly contain the same NUnit Version
- Test Method with custom parameters
- Test Instance with custom parameters
- Test with Console Output

[vNext]: ../../compare/1.0.0...HEAD
[1.4.1]: ../../compare/1.4.0...1.4.1
[1.4.0]: ../../compare/1.3.1...1.4.0
[1.3.1]: ../../compare/1.3.0...1.3.1
[1.3.0]: ../../compare/1.2.9...1.3.0
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.4.0</Version>
<Version>1.4.1-alpha</Version>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions ricaun.NUnit.Tests/ReferenceLoaderUtils_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Reflection;

[assembly: AssemblyMetadata("Tests", "Tests")]

namespace ricaun.NUnit.Tests
{
public class ReferenceLoaderUtils_Tests
Expand Down Expand Up @@ -44,5 +46,23 @@ public void ReferenceLoaderUtils_Tests_GetReferencesRepeat_Assemblies()
var endWith = AppDomain.CurrentDomain.GetAssemblies().Length;
Assert.Zero(endWith - startWith);
}

[Test]
public void ReferenceLoaderUtils_Tests_GetMetadataAttributes_Assemblies()
{
var assemblyFile = Assembly.GetExecutingAssembly().Location;
var startWith = AppDomain.CurrentDomain.GetAssemblies().Length;

var assemblyMetadataAttributes = ReferenceLoaderUtils.GetAssemblyMetadataAttributes(assemblyFile);
foreach (var assemblyMetadataAttribute in assemblyMetadataAttributes)
{
Console.WriteLine($"{assemblyMetadataAttribute.Key}: {assemblyMetadataAttribute.Value}");
}
Assert.IsNotNull(assemblyMetadataAttributes.FirstOrDefault(e => e.Key.Equals("Tests")));

var endWith = AppDomain.CurrentDomain.GetAssemblies().Length;
Assert.Zero(endWith - startWith);
}
}

}
16 changes: 16 additions & 0 deletions ricaun.NUnit/Extensions/ReferenceLoaderUtils.NET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
/// </summary>
internal static partial class ReferenceLoaderUtils
{
/// <summary>
/// GetAssemblyMetadataAttributes by Load Assembly with <see cref="ReferenceLoaderUtils.SimpleLoadContextUtil"/>
/// </summary>
/// <param name="assemblyPath"></param>
/// <returns></returns>
public static AssemblyMetadataAttribute[] GetAssemblyMetadataAttributes(string assemblyPath)
{
var result = new AssemblyMetadataAttribute[] { };
SimpleLoadContextUtil.LoadAndUnload(assemblyPath, (assembly) =>
{
result = assembly.GetCustomAttributes<AssemblyMetadataAttribute>().ToArray();
});

return result;
}

/// <summary>
/// GetReferencedAssemblies by Load Assembly with <see cref="ReferenceLoaderUtils.SimpleLoadContextUtil"/>
/// </summary>
Expand Down
Loading

0 comments on commit b21d75e

Please sign in to comment.