Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.NET] Remove all CR and BOM characters created by 'dotnet new'
- Loading branch information
Showing
7 changed files
with
320 additions
and
320 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
|
||
<ProjectReference Include="../Cantera/Cantera.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
|
||
<ProjectReference Include="../Cantera/Cantera.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
332 changes: 166 additions & 166 deletions
332
interfaces/dotnet/Cantera.Tests/src/ApplicationTest.cs
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 |
---|---|---|
@@ -1,166 +1,166 @@ | ||
// This file is part of Cantera. See License.txt in the top-level directory or | ||
// at https://cantera.org/license.txt for license and copyright information. | ||
|
||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using Cantera.Interop; | ||
using Xunit; | ||
|
||
namespace Cantera.Tests; | ||
|
||
[Collection("Application")] | ||
public class ApplicationTest | ||
{ | ||
class FooException : Exception { } | ||
|
||
readonly static LogMessageEventArgs s_mockLog = | ||
new(LogLevel.Warning, "Testing", "This is a test message."); | ||
|
||
[Fact] | ||
public void CanteraInfo_VersionRetrieved() | ||
{ | ||
// version string should start with a number | ||
Assert.Matches("^[1-9]", Application.Version); | ||
} | ||
|
||
[Fact] | ||
public void CanteraInfo_GitCommitRetrieved() | ||
{ | ||
Assert.NotEmpty(Application.GitCommit); | ||
} | ||
|
||
[Fact] | ||
public void CanteraInfo_DataDirectoryAdded() | ||
{ | ||
var dirs = Application.DataDirectories; | ||
var originalCount = dirs.Count; | ||
var longestDir = dirs.MaxBy(d => d.FullName.Length); | ||
|
||
Assert.NotNull(longestDir); | ||
|
||
dirs.Add(Path.Join(longestDir!.FullName, "garbazh")); | ||
|
||
Assert.Equal(originalCount + 1, dirs.Count); | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_MessageLogged() | ||
{ | ||
LogLevel? logLevel = null; | ||
string? report = null; | ||
|
||
void LogMessage(object? sender, LogMessageEventArgs e) | ||
{ | ||
logLevel = e.LogLevel; | ||
report = e.Message; | ||
} | ||
|
||
try | ||
{ | ||
Application.MessageLogged += LogMessage; | ||
|
||
ProduceRealLogOutput(); | ||
|
||
Assert.NotNull(logLevel); | ||
Assert.NotNull(report); | ||
|
||
Assert.Equal(LogLevel.Info, logLevel); | ||
Assert.NotEmpty(report); | ||
} | ||
finally | ||
{ | ||
Application.MessageLogged -= LogMessage; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_ConsoleLogged() | ||
{ | ||
var stdOut = Console.Out; | ||
var consoleOut = new StringWriter(); | ||
|
||
try | ||
{ | ||
Console.SetOut(consoleOut); | ||
Application.AddConsoleLogging(); | ||
ProduceMockLogOutput(); | ||
|
||
var output = consoleOut.ToString(); | ||
|
||
var logLevel = s_mockLog.LogLevel.ToString().ToUpperInvariant(); | ||
|
||
var prefix = $"{logLevel} ({s_mockLog.Category}) "; | ||
const string iso8601FormatString = "yyyy-MM-ddThh:mm:ss.fffzzz"; | ||
const int lengthOfIso8601FormattedString = 29; | ||
|
||
Assert.Matches('^' + Regex.Escape(prefix), output); | ||
|
||
var nowString = output.Substring( | ||
prefix.Length, lengthOfIso8601FormattedString); | ||
|
||
Assert.True(DateTimeOffset.TryParseExact( | ||
nowString, iso8601FormatString, null, default, out _)); | ||
} | ||
finally | ||
{ | ||
Application.RemoveConsoleLogging(); | ||
Console.SetOut(stdOut); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_ExceptionRegistered() | ||
{ | ||
static void LogMessage(object? sender, LogMessageEventArgs e) => | ||
throw new FooException(); | ||
|
||
try | ||
{ | ||
Application.MessageLogged += LogMessage; | ||
|
||
var thrown = | ||
Assert.Throws<CallbackException>(() => ProduceMockLogOutput()); | ||
|
||
Assert.NotNull(thrown.InnerException); | ||
Assert.IsType<FooException>(thrown.InnerException); | ||
} | ||
finally | ||
{ | ||
Application.MessageLogged -= LogMessage; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Produces log output by calling into the native Cantera library to invoke | ||
/// the logging callback. | ||
/// </summary> | ||
static void ProduceRealLogOutput() | ||
{ | ||
using var thermo = Application.CreateThermoPhase("gri30.yaml"); | ||
|
||
var handle = (ThermoPhaseHandle) typeof(ThermoPhase) | ||
.GetField("_handle", BindingFlags.NonPublic | BindingFlags.Instance)! | ||
.GetValue(thermo)!; | ||
|
||
InteropUtil.CheckReturn(LibCantera.thermo_print(handle, InteropConsts.True, 0)); | ||
} | ||
|
||
/// <summary> | ||
/// Produces log output without calling into the native Cantera library. | ||
/// </summary> | ||
static void ProduceMockLogOutput() | ||
{ | ||
var eventField = typeof(Application).GetField("s_invokeMessageLoggedDelegate", | ||
BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(eventField); | ||
|
||
var del = (LibCantera.LogCallback) eventField!.GetValue(null)!; | ||
|
||
Assert.NotNull(del); | ||
|
||
del(s_mockLog.LogLevel, s_mockLog.Category, s_mockLog.Message); | ||
|
||
CallbackException.ThrowIfAny(); | ||
} | ||
} | ||
// This file is part of Cantera. See License.txt in the top-level directory or | ||
// at https://cantera.org/license.txt for license and copyright information. | ||
|
||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using Cantera.Interop; | ||
using Xunit; | ||
|
||
namespace Cantera.Tests; | ||
|
||
[Collection("Application")] | ||
public class ApplicationTest | ||
{ | ||
class FooException : Exception { } | ||
|
||
readonly static LogMessageEventArgs s_mockLog = | ||
new(LogLevel.Warning, "Testing", "This is a test message."); | ||
|
||
[Fact] | ||
public void CanteraInfo_VersionRetrieved() | ||
{ | ||
// version string should start with a number | ||
Assert.Matches("^[1-9]", Application.Version); | ||
} | ||
|
||
[Fact] | ||
public void CanteraInfo_GitCommitRetrieved() | ||
{ | ||
Assert.NotEmpty(Application.GitCommit); | ||
} | ||
|
||
[Fact] | ||
public void CanteraInfo_DataDirectoryAdded() | ||
{ | ||
var dirs = Application.DataDirectories; | ||
var originalCount = dirs.Count; | ||
var longestDir = dirs.MaxBy(d => d.FullName.Length); | ||
|
||
Assert.NotNull(longestDir); | ||
|
||
dirs.Add(Path.Join(longestDir!.FullName, "garbazh")); | ||
|
||
Assert.Equal(originalCount + 1, dirs.Count); | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_MessageLogged() | ||
{ | ||
LogLevel? logLevel = null; | ||
string? report = null; | ||
|
||
void LogMessage(object? sender, LogMessageEventArgs e) | ||
{ | ||
logLevel = e.LogLevel; | ||
report = e.Message; | ||
} | ||
|
||
try | ||
{ | ||
Application.MessageLogged += LogMessage; | ||
|
||
ProduceRealLogOutput(); | ||
|
||
Assert.NotNull(logLevel); | ||
Assert.NotNull(report); | ||
|
||
Assert.Equal(LogLevel.Info, logLevel); | ||
Assert.NotEmpty(report); | ||
} | ||
finally | ||
{ | ||
Application.MessageLogged -= LogMessage; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_ConsoleLogged() | ||
{ | ||
var stdOut = Console.Out; | ||
var consoleOut = new StringWriter(); | ||
|
||
try | ||
{ | ||
Console.SetOut(consoleOut); | ||
Application.AddConsoleLogging(); | ||
ProduceMockLogOutput(); | ||
|
||
var output = consoleOut.ToString(); | ||
|
||
var logLevel = s_mockLog.LogLevel.ToString().ToUpperInvariant(); | ||
|
||
var prefix = $"{logLevel} ({s_mockLog.Category}) "; | ||
const string iso8601FormatString = "yyyy-MM-ddThh:mm:ss.fffzzz"; | ||
const int lengthOfIso8601FormattedString = 29; | ||
|
||
Assert.Matches('^' + Regex.Escape(prefix), output); | ||
|
||
var nowString = output.Substring( | ||
prefix.Length, lengthOfIso8601FormattedString); | ||
|
||
Assert.True(DateTimeOffset.TryParseExact( | ||
nowString, iso8601FormatString, null, default, out _)); | ||
} | ||
finally | ||
{ | ||
Application.RemoveConsoleLogging(); | ||
Console.SetOut(stdOut); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogWriter_ExceptionRegistered() | ||
{ | ||
static void LogMessage(object? sender, LogMessageEventArgs e) => | ||
throw new FooException(); | ||
|
||
try | ||
{ | ||
Application.MessageLogged += LogMessage; | ||
|
||
var thrown = | ||
Assert.Throws<CallbackException>(() => ProduceMockLogOutput()); | ||
|
||
Assert.NotNull(thrown.InnerException); | ||
Assert.IsType<FooException>(thrown.InnerException); | ||
} | ||
finally | ||
{ | ||
Application.MessageLogged -= LogMessage; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Produces log output by calling into the native Cantera library to invoke | ||
/// the logging callback. | ||
/// </summary> | ||
static void ProduceRealLogOutput() | ||
{ | ||
using var thermo = Application.CreateThermoPhase("gri30.yaml"); | ||
|
||
var handle = (ThermoPhaseHandle) typeof(ThermoPhase) | ||
.GetField("_handle", BindingFlags.NonPublic | BindingFlags.Instance)! | ||
.GetValue(thermo)!; | ||
|
||
InteropUtil.CheckReturn(LibCantera.thermo_print(handle, InteropConsts.True, 0)); | ||
} | ||
|
||
/// <summary> | ||
/// Produces log output without calling into the native Cantera library. | ||
/// </summary> | ||
static void ProduceMockLogOutput() | ||
{ | ||
var eventField = typeof(Application).GetField("s_invokeMessageLoggedDelegate", | ||
BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(eventField); | ||
|
||
var del = (LibCantera.LogCallback) eventField!.GetValue(null)!; | ||
|
||
Assert.NotNull(del); | ||
|
||
del(s_mockLog.LogLevel, s_mockLog.Category, s_mockLog.Message); | ||
|
||
CallbackException.ThrowIfAny(); | ||
} | ||
} |
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
Oops, something went wrong.