Skip to content

Commit

Permalink
Add unit tests for explicit interface implementation in FromExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Mar 10, 2018
1 parent 69c97ea commit b9023f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Hangfire.Core/Common/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private static void Validate(
{
if (!method.IsPublic)
{
throw new NotSupportedException("Only public methods can be invoked in the background.");
throw new NotSupportedException("Only public methods can be invoked in the background. Ensure your method has the `public` access modifier, and you aren' using explicit interface implementation.");
}

if (method.ContainsGenericParameters)
Expand Down
19 changes: 19 additions & 0 deletions tests/Hangfire.Core.Tests/Common/JobFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ public void FromScopedExpression_HandlesMethodsDeclaredInBaseClasse()
Assert.Equal(typeof(Instance), job.Method.DeclaringType);
}

[Fact]
public void FromScopedExpression_ThrowsWhenExplicitInterfaceImplementationIsPassed()
{
IService service = new ServiceImpl();
Assert.Throws<NotSupportedException>(() => Job.FromExpression(() => service.Method()));
}

public interface IService
{
void Method();
}

public class ServiceImpl : IService
{
void IService.Method()
{
}
}

[Fact]
public void Ctor_ThrowsAnException_WhenMethodContainsReferenceParameter()
{
Expand Down

0 comments on commit b9023f3

Please sign in to comment.