Skip to content

Commit

Permalink
Add unit tests for new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Sep 23, 2017
1 parent 0de9646 commit e3d6119
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions UnitTests/MockFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,5 +1084,42 @@ public interface INewFoo : IFoo
public interface INewBar : IBar
{
}

// Note that this test requires that there be no [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
// or similar defined in this test assembly. If some other test requires that internals be made
// visible to DynamicProxy, then this test must be disabled.
[Fact]
public void SetupOnInaccessibleMethodThrowsException()
{
var mock = new Mock<Accessibility.ClassWithAccessibleAndInaccessibleMethod>();
var error = Record.Exception(() =>
{
mock.Setup(m => m.Internal());
});
Assert.NotNull(error);
Assert.IsType<ArgumentException>(error);
Assert.Contains("accessible", error.Message);
Assert.Contains("proxy generator", error.Message);
}

[Fact]
public void SetupOnAccessibleMethodDoesNotThrowException()
{
var mock = new Mock<Accessibility.ClassWithAccessibleAndInaccessibleMethod>();
var error = Record.Exception(() =>
{
mock.Setup(m => m.Public());
});
Assert.Null(error);
}

public class Accessibility
{
public class ClassWithAccessibleAndInaccessibleMethod
{
public virtual void Public() => throw new InvalidOperationException("Public");
internal virtual void Internal() => throw new InvalidOperationException("Internal");
}
}
}
}

0 comments on commit e3d6119

Please sign in to comment.