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

IsAssignableFrom breaks __ComObject support #269

Closed
bob-fisher opened this issue Jun 10, 2016 · 2 comments
Closed

IsAssignableFrom breaks __ComObject support #269

bob-fisher opened this issue Jun 10, 2016 · 2 comments

Comments

@bob-fisher
Copy link

trying to setup setter for a property of ISymbol type, which is COM interface:
ISymbol setSymbol = null;
elMock.SetupGet(e => e.Symbol).Returns(setSymbol);
elMock.SetupSet(e => e.Symbol = It.IsAny()).Callback(s => setSymbol = s);

set it during a test:
el.Symbol = (ISymbol)Com.CreateInstance();

this never works, setSymbol stays null, Symbol property also always returns null

@stakx
Copy link
Contributor

stakx commented Jun 5, 2017

Let's start with the getter:

Symbol property also always returns null

That's because you configured it to return null. At the moment when .Returns(setSymbol) executes, setSymbol is null, therefore that call is equivalent to .Returns(null). Did you perhaps mean:

elMock.SetupGet(e => e.Symbol).Returns(() => setSymbol);  // deferred evaluation using lambda

@stakx
Copy link
Contributor

stakx commented Jun 5, 2017

Regarding the setter, there seems to be a problem, indeed. It.IsAny<T> won't recognize an instance of T is that is a COM object.

You mentioned IsAssignableFrom in this issue's title. I'm assuming you're referring to the one inside It.IsAny<T>():

public static TValue IsAny<TValue>()
{
    return Match<TValue>.Create(
        value => value == null || typeof(TValue).IsAssignableFrom(value.GetType()),
        () => It.IsAny<TValue>());
}

typeof(TValue).IsAssignableFrom(value.GetType()) might indeed not work for a COM object. This could apparently be solved by changing the test to value is TValue.

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