Skip to content

Commit

Permalink
Update RevitTestConsole with SetCurrentDirectory using the source…
Browse files Browse the repository at this point in the history
… test file.
  • Loading branch information
ricaun committed Aug 28, 2024
1 parent ba11f21 commit af6faa5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add `TestsFilePathTooLong` to similate long path inside test.
- Update to use `ricaun.Revit.UI.Tasks` library to run async tests.
- Update `ApplicationUtils` check local file exists.
- Update `RevitTestConsole` with `SetCurrentDirectory` using the source test file.

## [1.3.4] / 2024-05-27
### Console
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.5-rc.2</Version>
<Version>1.3.5-rc.3</Version>
</PropertyGroup>
</Project>
9 changes: 6 additions & 3 deletions ricaun.RevitTest.TestAdapter/Services/ApplicationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,18 @@ public static async Task<bool> DownloadAsync(string applicationFolder, string ad
private static bool LocalFileExists(string filePath, out string localFilePath)
{
localFilePath = filePath;

if (File.Exists(localFilePath)) return true;

try
{
var assemblyDirectory = Path.GetDirectoryName(typeof(ApplicationUtils).Assembly.Location);
localFilePath = Path.Combine(assemblyDirectory, filePath);
var currentDirectory = Directory.GetCurrentDirectory();
localFilePath = Path.Combine(currentDirectory, filePath);
localFilePath = new FileInfo(localFilePath).FullName;
AdapterLogger.Logger.Debug($"Application LocalFileCheck: {localFilePath}");
if (File.Exists(localFilePath))
{
AdapterLogger.Logger.DebugOnlyLocal($"Download File AssemblyDirectory: {assemblyDirectory}");
AdapterLogger.Logger.DebugOnlyLocal($"Download LocalFileCheck: {localFilePath}");
return true;
}
}
Expand Down
9 changes: 8 additions & 1 deletion ricaun.RevitTest.TestAdapter/Services/RevitTestConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ private string ValidadeApplication(string applicationPath, bool showApplicationN
return null;
}

public RevitTestConsole(string application = null)
public RevitTestConsole(string application = null, string sourceFile = null)
{
if (!string.IsNullOrEmpty(sourceFile))
{
var directory = Path.GetDirectoryName(sourceFile);
if (Directory.Exists(directory))
Directory.SetCurrentDirectory(directory);
}

applicationPath = ValidadeApplication(application, true);
if (applicationPath is null)
{
Expand Down
4 changes: 3 additions & 1 deletion ricaun.RevitTest.TestAdapter/TestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ricaun.RevitTest.TestAdapter.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -45,7 +46,8 @@ internal static List<TestCase> GetTests(
{
Metadatas.MetadataSettings.Create(source);
AdapterLogger.Logger.Info($"DiscoverTests: {source}");
using (var revit = new RevitTestConsole(AdapterSettings.Settings.NUnit.Application))

using (var revit = new RevitTestConsole(AdapterSettings.Settings.NUnit.Application, source))
{
if (revit.IsTrusted(out string message) == false)
{
Expand Down
2 changes: 1 addition & 1 deletion ricaun.RevitTest.TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private async Task RunTests(IFrameworkHandle frameworkHandle, string source, Lis
AdapterLogger.Logger.Info($"RevitTestConsole: {AdapterSettings.Settings.NUnit.Application}");
AdapterLogger.Logger.Info("---------");

using (var revit = new RevitTestConsole(AdapterSettings.Settings.NUnit.Application))
using (var revit = new RevitTestConsole(AdapterSettings.Settings.NUnit.Application, source))
{
if (revit.IsTrusted(out string message) == false)
{
Expand Down

0 comments on commit af6faa5

Please sign in to comment.