Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace Bunit
[Serializable]
public sealed class JSRuntimeUnhandledInvocationException : Exception
{
#if NET5_0_OR_GREATER
private const string DefaultImportIdentifier = "import";
#endif

/// <summary>
/// Gets the unplanned invocation.
Expand Down Expand Up @@ -123,10 +125,12 @@ private static string GetGenericInvocationArguments(JSRuntimeInvocation invocati
}
}

#pragma warning disable S1172 // Unused method parameters should be removed
private static bool IsImportModuleInvocation(JSRuntimeInvocation invocation)
#pragma warning restore S1172 // Unused method parameters should be removed
{
#if NET5_0_OR_GREATER
return string.Equals(invocation.Identifier, DefaultImportIdentifier, StringComparison.InvariantCulture)
return string.Equals(invocation.Identifier, DefaultImportIdentifier, StringComparison.Ordinal)
&& typeof(IJSObjectReference).IsAssignableFrom(invocation.ResultType);
#else
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Bunit.JSInterop
{
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:Parameter should not span multiple lines", Justification = "Makes error message easier to read.")]
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Dummy types are visible for testing purposes.")]
public class JSRuntimeUnhandledInvocationExceptionTest
public partial class JSRuntimeUnhandledInvocationExceptionTest
{
private const string CodeIdent = " ";

Expand Down Expand Up @@ -296,22 +296,6 @@ public void Test035(string identifier)
Assert.Equal(exectedErrorMessage, sut.Message);
}

[Theory(DisplayName = "Message prints correctly when trying to import an unconfigured module")]
[AutoData]
public void Test036(string moduleName)
{
var identifier = "import";
var returnType = typeof(IJSObjectReference);
var invocationMethodName = "InvokeAsync";
var exectedErrorMessage = CreateExpectedErrorMessage(
$"{CodeIdent}{invocationMethodName}<{returnType.Name}>(\"{identifier}\", \"{moduleName}\")",
$"{CodeIdent}SetupModule(\"{moduleName}\")");

var sut = new JSRuntimeUnhandledInvocationException(new JSRuntimeInvocation(identifier, new object?[] { moduleName }, returnType, invocationMethodName));

Assert.Equal(exectedErrorMessage, sut.Message);
}

public class Dummy1 { }
public class Dummy2 { }
public class Dummy3 { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if NET5_0_OR_GREATER
using System;
using System.Diagnostics.CodeAnalysis;
using AutoFixture.Xunit2;
using Microsoft.JSInterop;
using Xunit;

namespace Bunit.JSInterop
{
public partial class JSRuntimeUnhandledInvocationExceptionTest
{
[Theory(DisplayName = "Message prints correctly when trying to import an unconfigured module")]
[AutoData]
public void Test036(string moduleName)
{
var identifier = "import";
var returnType = typeof(IJSObjectReference);
var invocationMethodName = "InvokeAsync";
var exectedErrorMessage = CreateExpectedErrorMessage(
$"{CodeIdent}{invocationMethodName}<{returnType.Name}>(\"{identifier}\", \"{moduleName}\")",
$"{CodeIdent}SetupModule(\"{moduleName}\")");

var sut = new JSRuntimeUnhandledInvocationException(new JSRuntimeInvocation(identifier, new object?[] { moduleName }, returnType, invocationMethodName));

Assert.Equal(exectedErrorMessage, sut.Message);
}
}
}
#endif