Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClusterToolsExample.Node",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.TestKit.Xunit2.Tests", "src\contrib\testkits\Akka.TestKit.Xunit2.Tests\Akka.TestKit.Xunit2.Tests.csproj", "{95017C99-E960-44E5-83AD-BF21461DF06F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.TestKit.Xunit.Tests", "src\contrib\testkits\Akka.TestKit.Xunit.Tests\Akka.TestKit.Xunit.Tests.csproj", "{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1304,6 +1306,18 @@ Global
{95017C99-E960-44E5-83AD-BF21461DF06F}.Release|x64.Build.0 = Release|Any CPU
{95017C99-E960-44E5-83AD-BF21461DF06F}.Release|x86.ActiveCfg = Release|Any CPU
{95017C99-E960-44E5-83AD-BF21461DF06F}.Release|x86.Build.0 = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|x64.ActiveCfg = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|x64.Build.0 = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|x86.ActiveCfg = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Debug|x86.Build.0 = Debug|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|Any CPU.Build.0 = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|x64.ActiveCfg = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|x64.Build.0 = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|x86.ActiveCfg = Release|Any CPU
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1426,6 +1440,7 @@ Global
{ED00E6F4-2B5C-4F16-ADE4-45E4A73C17B8} = {7735F35A-E7B7-44DE-B6FB-C770B53EB69C}
{337A85B5-4A7C-4883-8634-46E7E52A765F} = {7735F35A-E7B7-44DE-B6FB-C770B53EB69C}
{95017C99-E960-44E5-83AD-BF21461DF06F} = {7625FD95-4B2C-4A5B-BDD5-94B1493FAC8E}
{F80F41E6-E5C7-4C92-B1CF-42539ECFBE68} = {7625FD95-4B2C-4A5B-BDD5-94B1493FAC8E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03AD8E21-7507-4E68-A4E9-F4A7E7273164}
Expand Down
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
</PropertyGroup>
<PropertyGroup>
<XunitVersion>2.8.1</XunitVersion>
<Xunit3Version>2.0.1</Xunit3Version>
<Xunit3RunnerVersion>3.0.2</Xunit3RunnerVersion>
<XunitRunnerVersion>2.8.1</XunitRunnerVersion>
<TestSdkVersion>17.9.0</TestSdkVersion>
<HyperionVersion>0.12.2</HyperionVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../../xunitSettings.props" />

<PropertyGroup>
<TargetFrameworks>$(NetFrameworkTestVersion);net8.0</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's going to be a bit of a breaking change but you know, at some point we have to step into the future here.

<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit.v3" Version="$(Xunit3Version)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(Xunit3RunnerVersion)">
<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>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Akka.TestKit.Xunit\Akka.TestKit.Xunit.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//-----------------------------------------------------------------------
// <copyright file="AkkaEqualExceptionSpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using Akka.TestKit.Xunit.Internals;
using Xunit;

namespace Akka.TestKit.Xunit.Tests.Internals;

public static class AkkaEqualExceptionSpec
{
#if NETFRAMEWORK
[Fact]
public static void Constructor_deserializes_message()
{
var originalException = new AkkaEqualException("Test message");

AkkaEqualException deserializedException;
using (var memoryStream = new System.IO.MemoryStream())
{
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(memoryStream, originalException);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
deserializedException = (AkkaEqualException)formatter.Deserialize(memoryStream);
}

Assert.Equal(originalException.Message, deserializedException.Message);
}
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//-----------------------------------------------------------------------
// <copyright file="XunitAssertionsSpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using Akka.TestKit.Xunit;
using Xunit;
using Xunit.Sdk;

namespace Akka.TestKit.Xunit.Tests;

public class XunitAssertionsSpec
{
private readonly XunitAssertions _assertions = new();

[Fact]
public void Assert_does_not_format_message_when_no_arguments_are_specified()
{
const string testMessage = "{Value} with different format placeholders {0}";

var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage));
Assert.Contains(testMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage));
Assert.Contains(testMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage));
Assert.Contains(testMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage));
Assert.Contains(testMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage));
Assert.Contains(testMessage, exception.Message);
}

[Fact]
public void Assert_formats_message_when_arguments_are_specified()
{
const string testMessage = "Meaning: {0}";
const string expectedMessage = "Meaning: 42";

var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);
}

[Fact]
public void Assert_catches_format_exceptions()
{
const string testMessage = "Meaning: {0} {1}";
const string expectedMessage = "Could not string.Format";

var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);

exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage, 42));
Assert.Contains(expectedMessage, exception.Message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

<PropertyGroup>
<Description>TestKit for writing tests for Akka.NET using xUnit.</Description>
<TargetFrameworks>$(NetStandardLibVersion);$(NetLibVersion)</TargetFrameworks>
<TargetFrameworks>$(NetStandardLibVersion);net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<PackageTags>$(AkkaPackageTags);testkit;xunit</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka.TestKit\Akka.TestKit.csproj" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.v3.extensibility.core" Version="$(Xunit3Version)" />
<PackageReference Include="xunit.v3.assert" Version="$(Xunit3Version)" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//-----------------------------------------------------------------------
// <copyright file="LocalFactAttribute.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using System;
using Xunit;
using Xunit.v3;

namespace Akka.TestKit.Xunit.Attributes;

/// <summary>
/// <para>
/// This custom XUnit Fact attribute will skip unit tests if the environment variable
/// "XUNIT_SKIP_LOCAL_FACT" exists and is set to the string "true"
/// </para>
/// <para>
/// Note that the original <see cref="Skip"/> property takes precedence over this attribute,
/// any unit tests with <see cref="LocalFactAttribute"/> with its <see cref="Skip"/> property
/// set will always be skipped, regardless of the environment variable content.
/// </para>
/// </summary>
[XunitTestCaseDiscoverer(typeof(FactDiscoverer))]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class LocalFactAttribute: Attribute, IFactAttribute
{
private const string EnvironmentVariableName = "XUNIT_SKIP_LOCAL_FACT";

private string? _skip;

/// <inheritdoc />
public string? DisplayName { get; set; }

/// <inheritdoc/>
public bool Explicit { get; set; }

/// <inheritdoc/>
public Type[]? SkipExceptions { get; set; }

/// <inheritdoc/>
public Type? SkipType { get; set; }

/// <inheritdoc/>
public string? SkipUnless { get; set; }

/// <inheritdoc/>
public string? SkipWhen { get; set; }

/// <inheritdoc/>
public int Timeout { get; set; }

/// <inheritdoc/>
public string? Skip
{
get
{
var skipLocal = Environment.GetEnvironmentVariable(EnvironmentVariableName)?
.ToLowerInvariant();
return skipLocal is "true" ? SkipLocal ?? "Local facts are being skipped" : _skip;
}
set => _skip = value;
}

/// <summary>
/// The reason why this unit test is being skipped by the <see cref="LocalFactAttribute"/>.
/// Note that the original <see cref="FactAttribute.Skip"/> property takes precedence over this message.
/// </summary>
public string? SkipLocal { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------
// <copyright file="LocalTheoryAttribute.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using System;
using Xunit.v3;

namespace Akka.TestKit.Xunit.Attributes
{
/// <summary>
/// <para>
/// This custom XUnit Fact attribute will skip unit tests if the environment variable
/// "XUNIT_SKIP_LOCAL_THEORY" exists and is set to the string "true"
/// </para>
/// <para>
/// Note that the original <see cref="IFactAttribute.Skip"/> property takes precedence over this attribute,
/// any unit tests with <see cref="LocalTheoryAttribute"/> with its <see cref="IFactAttribute.Skip"/> property
/// set will always be skipped, regardless of the environment variable content.
/// </para>
/// </summary>
[XunitTestCaseDiscoverer(typeof(TheoryDiscoverer))]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class LocalTheoryAttribute : LocalFactAttribute, ITheoryAttribute
{
/// <inheritdoc />
public bool DisableDiscoveryEnumeration { get; set; }

/// <inheritdoc />
public bool SkipTestWithoutData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//-----------------------------------------------------------------------
// <copyright file="WindowsFactAttribute.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using System;
using Xunit.v3;

namespace Akka.TestKit.Xunit.Attributes
{
/// <summary>
/// <para>
/// This custom XUnit Fact attribute will skip unit tests if the run-time environment is not windows
/// </para>
/// <para>
/// Note that the original <see cref="Skip"/> property takes precedence over this attribute,
/// any unit tests with <see cref="WindowsFactAttribute"/> with its <see cref="Skip"/> property
/// set will always be skipped, regardless of the environment variable content.
/// </para>
/// </summary>
public class WindowsFactAttribute : Attribute, IFactAttribute
{
private string? _skip;


/// <inheritdoc />
public string? DisplayName { get; set; }

/// <inheritdoc/>
public bool Explicit { get; set; }

/// <inheritdoc/>
public Type[]? SkipExceptions { get; set; }

/// <inheritdoc/>
public Type? SkipType { get; set; }

/// <inheritdoc/>
public string? SkipUnless { get; set; }

/// <inheritdoc/>
public string? SkipWhen { get; set; }

/// <inheritdoc/>
public int Timeout { get; set; }

/// <inheritdoc/>
public string? Skip
{
get
{
if (_skip != null)
return _skip;

var platform = Environment.OSVersion.Platform;
var notWindows = platform is PlatformID.MacOSX or PlatformID.Unix or PlatformID.Xbox;
return notWindows ? SkipUnix ?? "Skipped under Unix platforms" : null;
}
set => _skip = value;
}

/// <summary>
/// The reason why this unit test is being skipped by the <see cref="WindowsFactAttribute"/>.
/// Note that the original <see cref="Skip"/> property takes precedence over this message.
/// </summary>
public string? SkipUnix { get; set; }
}
}

Loading