Skip to content

Commit

Permalink
Merge pull request #59 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
ricaun authored Oct 7, 2024
2 parents 8fb6abe + 6a1db5f commit 4fd5697
Show file tree
Hide file tree
Showing 34 changed files with 583 additions and 124 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ 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.6.0] / 2024-09-25 - 2024-10-06
### Features
- Support `TestAdapter` custom executer.
- Support environment variables to overwrite settings in the `TestAdapter`. (Fix: #57)
- Support `Cancel` tests and `Kill` processes in the `TestAdapter`.
### App
- Force to kill test when `ClientDisconnected`.
### Command
- Update to use `JsonService` implementation to use `Newtonsoft.Json` in the domain.
- Update `ProcessStart` with `GetProcesses` to enable kill process.
### Console
- Add `RevitTestUtils.Exceptions` to show exceptions in the console.
- Add `ricaun.RevitAPI.Fake.References.RevitAPIUI` to fix `RevitAPIUI` reference exception in the discovery test. (Fix: #58)
- Disable/Remove discovery test to use `RevitAPIUI` version `2021` to `2023`.
- Add Environment variable for process arguments `RICAUN_REVITTEST_CONSOLE_PROCESS_ARGUMENTS`.
### Shared
- Update to use `ricaun.NamedPipeWrapper.Json` version `1.8.0`.
- Add `ClientDisconnected` in `PipeProcessServer`.
### TestAdapter
- Use `LocalExtensionData` to store `TestModel` result.
- Add `EnvironmentSettings` to overwrite settings in the `TestAdapter`.
- Update `JsonService` implementation to use `Newtonsoft.Json` in the domain.
- Support `Cancel` to abort and `Kill` processes.
- Add `ProcessExtension` to `KillTree` for net framework.
### Tests
- Add `TestsRevitUI` to validate fake `RevitAPIUI` reference.

## [1.5.0] / 2024-09-11 - 2024-09-19
### Features
- Support tests with `TestCaseSource`. (Fix: #55)
Expand Down Expand Up @@ -486,6 +513,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [x] TestsFail

[vNext]: ../../compare/1.0.0...HEAD
[1.6.0]: ../../compare/1.5.0...1.6.0
[1.5.0]: ../../compare/1.4.1...1.5.0
[1.4.1]: ../../compare/1.4.0...1.4.1
[1.4.0]: ../../compare/1.3.6...1.4.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.5.0</Version>
<Version>1.6.0</Version>
</PropertyGroup>
</Project>
14 changes: 13 additions & 1 deletion README.old.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ For more information see [Wiki](https://github.com/ricaun-io/ricaun.RevitTest/wi
* [ricaun.RevitTest.Application.bundle.zip](ricaun.RevitTest.Application)
#### Shared
* [ricaun.NUnit](https://github.com/ricaun-io/ricaun.NUnit)
* [NamedPipeWrapper.Json](https://github.com/ricaun-io/named-pipe-wrapper-json)
* [ricaun.NamedPipeWrapper.Json](https://github.com/ricaun-io/named-pipe-wrapper-json)
#### TestAdapter
* [ricaun.RevitTest.Console.exe](ricaun.RevitTest.Console)
* [ricaun.RevitTest.Command](ricaun.RevitTest.Command)
Expand Down Expand Up @@ -131,6 +131,18 @@ dotnet test ricaun.RevitTest.Tests.dll --settings:.runsettings -- NUnit.Version=
dotnet test ricaun.RevitTest.Tests.dll -v:detailed -- NUnit.Application=""
```

### Environment Variables
```
RICAUN_REVITTEST_TESTADAPTER_NUNIT_VERSION
RICAUN_REVITTEST_TESTADAPTER_NUNIT_LANGUAGE
RICAUN_REVITTEST_TESTADAPTER_NUNIT_OPEN
RICAUN_REVITTEST_TESTADAPTER_NUNIT_CLOSE
RICAUN_REVITTEST_TESTADAPTER_NUNIT_TIMEOUT
RICAUN_REVITTEST_TESTADAPTER_NUNIT_VERBOSITY
RICAUN_REVITTEST_TESTADAPTER_NUNIT_APPLICATION
RICAUN_REVITTEST_TESTADAPTER_NUNIT_METADATA
```

### `.runsettings`
.csproj
```xml
Expand Down
16 changes: 16 additions & 0 deletions ricaun.RevitTest.Application/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ private static void PipeTestServer_Initialize()
response.Tests = null;
});

PipeTestServer.ClientDisconnected = () =>
{
try
{
if (IsTestRunning)
{
Log.WriteLine("PipeTestServer: ClientDisconnected - TestEngine.KillTests");
ricaun.NUnit.TestEngine.Result = new TestModelResult((test) =>
{
throw new Exception("Client disconnect, TestEngine.Kill to ignore test result.");
});
}
}
catch { }
};

var initializeServer = PipeTestServer.Initialize();

if (initializeServer)
Expand Down
23 changes: 23 additions & 0 deletions ricaun.RevitTest.Command/Extensions/Json/IJsonService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ricaun.RevitTest.Command.Extensions.Json
{
/// <summary>
/// Represents a service for JSON serialization and deserialization.
/// </summary>
public interface IJsonService
{
/// <summary>
/// Deserializes the specified JSON string into an object of type T.
/// </summary>
/// <typeparam name="T">The type of the object to deserialize.</typeparam>
/// <param name="value">The JSON string to deserialize.</param>
/// <returns>The deserialized object of type T.</returns>
T Deserialize<T>(string value);

/// <summary>
/// Serializes the specified object into a JSON string.
/// </summary>
/// <param name="value">The object to serialize.</param>
/// <returns>The JSON string representation of the serialized object.</returns>
string Serialize(object value);
}
}
43 changes: 43 additions & 0 deletions ricaun.RevitTest.Command/Extensions/Json/JsonService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace ricaun.RevitTest.Command.Extensions.Json
{
#if NETFRAMEWORK
using System.Web.Script.Serialization;
internal class JsonService : IJsonService
{
public JsonService()
{
JavaScriptSerializer = new JavaScriptSerializer();
}
public JavaScriptSerializer JavaScriptSerializer { get; set; }
public T Deserialize<T>(string value)
{
return JavaScriptSerializer.Deserialize<T>(value);
}

public string Serialize(object value)
{
return JavaScriptSerializer.Serialize(value);
}
}
#endif
#if NET
using System.Text.Json;
internal class JsonService : IJsonService
{
public T Deserialize<T>(string value)
{
return JsonSerializer.Deserialize<T>(value);
}

public string Serialize(object value)
{
return JsonSerializer.Serialize(value);
}
}
#endif
#if NETSTANDARD
internal class JsonService : NewtonsoftJsonService
{
}
#endif
}
20 changes: 20 additions & 0 deletions ricaun.RevitTest.Command/Extensions/Json/NewtonsoftJsonService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ricaun.RevitTest.Command.Extensions.Json
{
internal class NewtonsoftJsonService : IJsonService
{
public NewtonsoftJsonService()
{
Settings = new Newtonsoft.Json.JsonSerializerSettings();
}
public Newtonsoft.Json.JsonSerializerSettings Settings { get; }
public T Deserialize<T>(string value)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value, Settings);
}

public string Serialize(object value)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(value, Settings);
}
}
}
102 changes: 18 additions & 84 deletions ricaun.RevitTest.Command/Extensions/JsonExtension.cs
Original file line number Diff line number Diff line change
@@ -1,98 +1,33 @@
namespace ricaun.RevitTest.Command.Extensions
using ricaun.RevitTest.Command.Extensions.Json;

namespace ricaun.RevitTest.Command.Extensions
{
#if NETFRAMEWORK
using System.Web.Script.Serialization;
/// <summary>
/// JsonExtension
/// <code>Reference Include="System.Web.Extensions"</code>
/// </summary>
public static class JsonExtension
{
private static JavaScriptSerializer JavaScriptSerializer { get; set; } = new JavaScriptSerializer();

/// <summary>
/// Deserialize
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T Deserialize<T>(this string value)
{
return JavaScriptSerializer.Deserialize<T>(value);
}

/// <summary>
/// Serialize
/// IJsonService
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string Serialize(object value)
{
return JavaScriptSerializer.Serialize(value);
}
public static IJsonService JsonService { get; set; } = CreateJsonService();

/// <summary>
/// ToJson
/// Create JsonService
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ToJson(this object value)
/// <remarks>
/// If NewtonsoftJsonService is available, use it.
/// </remarks>
private static IJsonService CreateJsonService()
{
return Serialize(value);
try
{
return new NewtonsoftJsonService();
}
catch { };
return new JsonService();
}
}
#endif

#if NETSTANDARD
using Newtonsoft.Json;
public static class JsonExtension
{
/// <summary>
/// Settings
/// </summary>
public static JsonSerializerSettings Settings { get; set; } = new JsonSerializerSettings();

/// <summary>
/// Deserialize
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T Deserialize<T>(this string value)
{
return JsonConvert.DeserializeObject<T>(value, Settings);
}

/// <summary>
/// Serialize
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string Serialize(object value)
{
return JsonConvert.SerializeObject(value, Settings);
}

/// <summary>
/// ToJson
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ToJson(this object value)
{
return Serialize(value);
}
}
#endif

#if NET
using System.Text.Json;
public static class JsonExtension
{
/// <summary>
/// Settings
/// </summary>
public static JsonSerializerOptions Settings { get; set; } = new JsonSerializerOptions();

/// <summary>
/// Deserialize
Expand All @@ -102,7 +37,7 @@ public static class JsonExtension
/// <returns></returns>
public static T Deserialize<T>(this string value)
{
return JsonSerializer.Deserialize<T>(value, Settings);
return JsonService.Deserialize<T>(value);
}

/// <summary>
Expand All @@ -112,7 +47,7 @@ public static T Deserialize<T>(this string value)
/// <returns></returns>
public static string Serialize(object value)
{
return JsonSerializer.Serialize(value, Settings);
return JsonService.Serialize(value);
}

/// <summary>
Expand All @@ -125,5 +60,4 @@ public static string ToJson(this object value)
return Serialize(value);
}
}
#endif
}
7 changes: 7 additions & 0 deletions ricaun.RevitTest.Command/Process/ProcessStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace ricaun.RevitTest.Command.Process
{
public class ProcessStart
{
private static List<System.Diagnostics.Process> Processes = new List<System.Diagnostics.Process>();
public static System.Diagnostics.Process[] GetProcesses()
{
return Processes.OfType<System.Diagnostics.Process>().Where(e => !e.HasExited).ToArray();
}

protected virtual void WriteLine(string message)
{
Debug.WriteLine(message);
Expand Down Expand Up @@ -99,6 +105,7 @@ private async Task Run(string arguments,
if (string.IsNullOrEmpty(processPath)) return;
var psi = NewProcessStartInfo(arguments);
var process = System.Diagnostics.Process.Start(psi);
Processes.Add(process);
process.OutputDataReceived += (sender, e) =>
{
consoleAction?.Invoke(e.Data);
Expand Down
6 changes: 6 additions & 0 deletions ricaun.RevitTest.Command/ricaun.RevitTest.Command.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<Reference Include="System.Web.Extensions" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
<PackageReference Include="Newtonsoft.Json" Version="9.*" IncludeAssets="build; compile" PrivateAssets="All">
<NoWarn>NU1903</NoWarn>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Newtonsoft.Json" Version="*" />
</ItemGroup>
Expand Down
Binary file not shown.
Loading

0 comments on commit 4fd5697

Please sign in to comment.