Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock.As appears to be broken in Moq 4.1.1308.2321 #54

Closed
TrevorPilley opened this issue Sep 3, 2013 · 2 comments
Closed

Mock.As appears to be broken in Moq 4.1.1308.2321 #54

TrevorPilley opened this issue Sep 3, 2013 · 2 comments

Comments

@TrevorPilley
Copy link

The following works as expected in 4.0.10827 but in 4.1.1308.2321 the foo as IDisposable cast doesn't succeed.

public interface IFoo
{
    void Bar();
}

[TestFixture]
public class Tests
{
    [Test]
    public void Test()
    {
        var mock = new Mock<IFoo>();
        mock.Setup(x => x.Bar());
        mock.As<IDisposable>().Setup(x => x.Dispose());

        Action<IFoo> testMock = (IFoo foo) =>
        {
            foo.Bar();

            var disposable = foo as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        };

        testMock(mock.Object);

        mock.VerifyAll();
    }
@kzu
Copy link
Contributor

kzu commented Sep 9, 2013

This was an unintended break from pull request #4.

I'm working on a fix. For the time being, if you move the .As to be the first line right after creating the mock, this test passes.

Will keep you posted.

@kzu
Copy link
Contributor

kzu commented Sep 9, 2013

Fixed and published on latest nuget: https://www.nuget.org/packages/moq

@kzu kzu closed this as completed Sep 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants