Skip to content

Commit

Permalink
Merge pull request #39 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 1.3.1
  • Loading branch information
ricaun authored Apr 5, 2024
2 parents 0533dcb + 4e293e6 commit 1d42b85
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>.</NukeRootDirectory>
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ 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.3.1] / 2024-04-02
### Features
- Support Revit 2025 to 2017.
### Fixed
- Fix `Installation` Application issue.
- Fix `Timeout` issue with `testsFinishedForceToEnd`.
### Command
- Update `ricaun.Revit.Installation` to `1.1.2`
- Update `debugger` with debug logs.
- Update `Command` with `SemanticVersion`.
### Application
- Fix `AssemblyResolve` in `.NET Core` updated `AppDomainExtension`.
### Shared
- Update `NamedPipeWrapper.Json` to `1.7.0`
### TestAdapter
- Update `TestAdapter` with debug logs.
- Update `TestAdapter` with `PackageTags`
- Update `TestAdapter` with `PackageLicenseFile`
- Add `IsLogDebug` with `Verbosity`.


## [1.3.0] / 2024-03-28
### Features
- Readme information to wiki.
Expand Down Expand Up @@ -380,6 +401,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [x] TestsFail

[vNext]: ../../compare/1.0.0...HEAD
[1.3.1]: ../../compare/1.3.0...1.3.1
[1.3.0]: ../../compare/1.2.1...1.3.0
[1.2.1]: ../../compare/1.2.0...1.2.1
[1.2.0]: ../../compare/1.1.3...1.2.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.3.0</Version>
<Version>1.3.1</Version>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions ricaun.RevitTest.Application/Extensions/AppDomainUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ internal static class AppDomainUtils
/// <returns></returns>
public static AppDomainExtension.DelegatesDisposable AssemblyResolveDisposable()
{
#if DEBUG
var resolveEventHandler = AppDomain.CurrentDomain.GetResolveEventHandler();
Console.WriteLine($"Debug Domain >> {AppDomain.CurrentDomain.FriendlyName}");
Console.WriteLine($"Debug Assembly >> {typeof(AppDomainUtils).Assembly.FullName}");
Console.WriteLine($"Debug Location >> {typeof(AppDomainUtils).Assembly.Location}");
Console.WriteLine($"Debug GetResolveEventHandler >> {resolveEventHandler}");
if (resolveEventHandler is not null)
{
Console.WriteLine($"Debug GetInvocationList >> {resolveEventHandler.GetInvocationList().Length}");
}
#endif
return AppDomain.CurrentDomain.GetAssemblyResolveDisposable().NotRemoveDelegatesAfterDispose();
}
}
Expand All @@ -25,12 +36,21 @@ internal static class AppDomainExtension
/// <returns></returns>
public static ResolveEventHandler GetResolveEventHandler(this AppDomain appDomain)
{
#if NETFRAMEWORK
var fieldName = "_AssemblyResolve";

var fieldInfo = appDomain.GetType()
.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);

return fieldInfo?.GetValue(appDomain) as ResolveEventHandler;
#elif NET
var fieldName = "AssemblyResolve";

var fieldInfo = typeof(System.Runtime.Loader.AssemblyLoadContext)
.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic);

return fieldInfo?.GetValue(null) as ResolveEventHandler;
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<PackageReference Include="Newtonsoft.Json" Version="9.*" IncludeAssets="build; compile" PrivateAssets="All">
<NoWarn>NU1903</NoWarn>
</PackageReference>
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*-*" IncludeAssets="build; compile" PrivateAssets="All" />
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 23 additions & 2 deletions ricaun.RevitTest.Command/Utils/AppUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ricaun.RevitTest.Command.Utils
using System.Reflection;

namespace ricaun.RevitTest.Command.Utils
{
public static class AppUtils
{
Expand All @@ -9,10 +11,29 @@ public static class AppUtils
public static string GetInfo()
{
var assemblyName = typeof(AppUtils).Assembly.GetName();
var info = $"{assemblyName.Name} {assemblyName.Version.ToString(3)} [{GetTargetFrameworkName()}]";
var info = $"{assemblyName.Name} {GetSemanticVersion()} [{GetTargetFrameworkName()}]";
return info;
}

/// <summary>
/// Get Semantic Version
/// </summary>
/// <returns></returns>
public static string GetSemanticVersion() {

var assembly = typeof(AppUtils).Assembly;
var version = assembly.GetName().Version.ToString(3);

try
{
var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
version = informationalVersion.Split('+')[0];
}
catch { }

return version;
}

/// <summary>
/// Get Target Framework Name (Net Framework or Net Core)
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Command/ricaun.RevitTest.Command.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PropertyGroup>
<Company>ricaun</Company>
<Authors>Luiz Henrique Cassettari</Authors>
<Description>Package $(PackageId).</Description>
<Description>Contract to create a Console application for package ricaun.RevitTest.TestAdapter.</Description>
<CopyrightYears>$([System.DateTime]::Now.ToString('yyyy'))</CopyrightYears>
</PropertyGroup>

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,47 @@ namespace ricaun.RevitTest.Console.Revit.Services
public class ApplicationPluginsDisposable : IDisposable
{
private readonly string applicationPluginsPath;
private readonly bool applicationPluginsPathDelete;
private Action<Exception> downloadException;
private Action<string> logConsole;

public bool Initialized { get; private set; }
public ApplicationPluginsDisposable(string applicationPluginsPath)
{
this.applicationPluginsPath = applicationPluginsPath;
Initialize();
}
public ApplicationPluginsDisposable(byte[] data, string fileName)
{
this.applicationPluginsPath = data.CopyToFile(fileName);
Initialize();
File.Delete(this.applicationPluginsPath);
this.applicationPluginsPathDelete = true;
}
private void Initialize()

public ApplicationPluginsDisposable SetException(Action<Exception> downloadException)
{
if (string.IsNullOrEmpty(applicationPluginsPath)) return;
this.downloadException = downloadException;
return this;
}

public ApplicationPluginsDisposable SetLog(Action<string> logConsole)
{
this.logConsole = logConsole;
return this;
}

public ApplicationPluginsDisposable Initialize()
{
if (string.IsNullOrEmpty(applicationPluginsPath)) return this;
var applicationPluginsFolder = RevitUtils.GetCurrentUserApplicationPluginsFolder();
ApplicationPluginsUtils.DownloadBundle(applicationPluginsFolder, applicationPluginsPath);
Initialized = ApplicationPluginsUtils.DownloadBundle(applicationPluginsFolder, applicationPluginsPath, downloadException, logConsole);

if (applicationPluginsPathDelete)
{
File.Delete(this.applicationPluginsPath);
}

return this;
}

public void Dispose()
{
if (string.IsNullOrEmpty(applicationPluginsPath)) return;
Expand Down
70 changes: 62 additions & 8 deletions ricaun.RevitTest.Console/Revit/Utils/RevitTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void CreateRevitServer(
bool forceToCloseRevit = false,
params string[] testFilters)
{
int timeoutCountMax = forceToWaitRevit ? 0 : 1;
int timeoutCountMax = forceToWaitRevit ? 0 : 10;

if (revitVersionNumber == 0)
{
Expand All @@ -119,6 +119,7 @@ public static void CreateRevitServer(

int timeoutCount = 0;
bool sendFileWhenCreatedOrUpdated = true;
bool testsFinishedForceToEnd = false;

Action<string, bool> resetSendFile = (file, exists) =>
{
Expand All @@ -127,8 +128,19 @@ public static void CreateRevitServer(

using (new FileWatcher().Initialize(fileToTest, resetSendFile))
{
using (CreateAppPlugin())
using (var appPlugin = CreateApplicationPlugin())
{
Debug.WriteLine($"Application Install: {appPlugin.Initialized}");

if (appPlugin.Initialized == false)
{
var exceptionAppPlugin = new Exception("Application not initialized.");
var failTests = TestEngine.Fail(fileToTest, exceptionAppPlugin, testFilters);
actionOutput.Invoke(failTests.ToJson());
Thread.Sleep(SleepMillisecondsBeforeFinish);
return;
}

if (RevitInstallationUtils.InstalledRevit.TryGetRevitInstallationGreater(revitVersionNumber, out RevitInstallation revitInstallation))
{
Log.WriteLine(revitInstallation);
Expand All @@ -146,8 +158,8 @@ public static void CreateRevitServer(
client.ServerMessage.PropertyChanged += (s, e) =>
{
var message = s as TestResponse;
Debug.WriteLine($"{revitInstallation}: PropertyChanged[ {e.PropertyName} ]");
Debug.WriteLine($"{revitInstallation}: {message}");
LogDebug.WriteLine($"{revitInstallation}: PropertyChanged[ {e.PropertyName} ]");
LogDebug.WriteLine($"{revitInstallation}: {message}");
switch (e.PropertyName)
{
case nameof(TestResponse.Test):
Expand All @@ -156,6 +168,7 @@ public static void CreateRevitServer(
{
Log.WriteLine($"{revitInstallation}: {test.Time} \t {test}");
actionOutput?.Invoke(test.ToJson());
testsFinishedForceToEnd = false;
}
break;
case nameof(TestResponse.Tests):
Expand All @@ -165,6 +178,7 @@ public static void CreateRevitServer(
Log.WriteLine($"{revitInstallation}: {tests.Time} \t {tests}");
actionOutput?.Invoke(null); // Force to clear file
actionOutput?.Invoke(tests.ToJson());
testsFinishedForceToEnd = true;
}
break;
case nameof(TestResponse.Info):
Expand Down Expand Up @@ -197,11 +211,20 @@ public static void CreateRevitServer(
timeoutCount++;

if (timeoutCountMax > 0 && timeoutCount > timeoutCountMax)
{
Log.WriteLine($"{revitInstallation}: Timeout");
break;
}

if (client.ServerMessage.IsBusy)
continue;

if (testsFinishedForceToEnd)
{
Log.WriteLine($"{revitInstallation}: Tests Finished");
break;
}

//if (System.Console.KeyAvailable)
//{
// var cki = System.Console.ReadKey(true);
Expand Down Expand Up @@ -256,12 +279,43 @@ public static void CreateRevitServer(
}

#region private
private static ApplicationPluginsDisposable CreateAppPlugin()
private static ApplicationPluginsDisposable CreateApplicationPlugin()
{
return new ApplicationPluginsDisposable(
Properties.Resources.ricaun_RevitTest_Application_bundle,
"ricaun.RevitTest.Application.bundle.zip");
var application = new ApplicationPluginsDisposable(
Properties.Resources.ricaun_RevitTest_Application_bundle,
"ricaun.RevitTest.Application.bundle.zip");

application.SetException(ApplicationException);
application.SetLog(ApplicationLog);

return application.Initialize();
}

private static void ApplicationException(Exception exception)
{
LogDebug.WriteLine($"Application Error: {exception.Message}");
}

private static void ApplicationLog(string log)
{
LogDebug.WriteLine($"Application: {log}");
}
#endregion
}

public static class LogDebug
{
/// <summary>
/// WriteLine
/// </summary>
/// <param name="value"></param>
public static void WriteLine(string value)
{
Debug.WriteLine(value);
if (DebuggerUtils.IsDebuggerAttached)
{
Log.WriteLine($"Debug: {value}");
}
}
}
}
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Shared/ricaun.RevitTest.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NamedPipeWrapper.Json" Version="*-*" />
<PackageReference Include="NamedPipeWrapper.Json" Version="*" />
<PackageReference Include="ricaun.NUnit" Version="*" />
</ItemGroup>

Expand Down
Binary file not shown.
Binary file not shown.
17 changes: 14 additions & 3 deletions ricaun.RevitTest.TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void Cancel()
{
}

private static bool IsLogDebug => System.Diagnostics.Debugger.IsAttached || AdapterSettings.Settings.NUnit.Verbosity > 2;

/// <summary>
/// Run Tests using RevitTest.Console -t
/// </summary>
Expand Down Expand Up @@ -111,7 +113,9 @@ private async Task RunTests(IFrameworkHandle frameworkHandle, string source, Lis

if (item.StartsWith("{\"FileName"))
{
AdapterLogger.Logger.Debug($"OutputConsole: {item.Trim()}");
if (IsLogDebug)
AdapterLogger.Logger.Debug($"OutputConsole: DEBUG: {item.Trim()}");

var testAssembly = item.Deserialize<TestAssemblyModel>();

if (testAssemblyEnabled == false) return;
Expand All @@ -124,17 +128,24 @@ private async Task RunTests(IFrameworkHandle frameworkHandle, string source, Lis
}
else if (item.StartsWith("{\"Name"))
{
AdapterLogger.Logger.Debug($"OutputConsole: {item.Trim()}");
if (IsLogDebug)
AdapterLogger.Logger.Debug($"OutputConsole: DEBUG: {item.Trim()}");

if (item.Deserialize<TestModel>() is TestModel testModel)
{
RecordResultTestModel(frameworkHandle, source, tests, testModel);
testAssemblyEnabled = false;
}
}
else
else if (item.StartsWith(" "))
{
AdapterLogger.Logger.Debug($"OutputConsole: {item}");
}
else
{
if (IsLogDebug)
AdapterLogger.Logger.Debug($"OutputConsole: DEBUG: {item}");
}
};

AdapterLogger.Logger.Info($"RunRevitTest: {source} [Version: {AdapterSettings.Settings.NUnit.Version}] [TestFilter: {filters.Length}]");
Expand Down
Loading

0 comments on commit 1d42b85

Please sign in to comment.