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

Error with events and IEnumerable<T> #27

Closed
Portikus opened this issue Jun 21, 2017 · 8 comments
Closed

Error with events and IEnumerable<T> #27

Portikus opened this issue Jun 21, 2017 · 8 comments

Comments

@Portikus
Copy link
Contributor

Hi I have an Inteface with the following event:

 event EventHandler<IEnumerable<string>> SomeEvent;

When SimpleStubs is now generating the stubs it generates the following:

protected void On_SomeEvent(object sender, IEnumerable args)
{
     global::System.EventHandler<global::System.Collections.Generic.IEnumerable<string>> handler = SomeEvent;
     if (handler != null) { handler(sender, args); }
}
public void SomeEvent_Raise(object sender, IEnumerable args)
{
     On_SomeEvent(sender, args);
}

It generates methods for IEnumerable not for IEnumerable<string> which wont compile.

@nehmebilal
Copy link
Collaborator

Hi @Portikus,

Thanks for reporting this issue! Should be a quick fix.

@nehmebilal
Copy link
Collaborator

The issue has been resolved in master. I will publish the fix with the next NuGet.

@billyzkid
Copy link

Hi! When can we expect the updated nuget with this fix? This bug is a blocker for me. Thanks!

@nehmebilal
Copy link
Collaborator

Sorry for the delay. I will publish the NuGet this week.

@nehmebilal
Copy link
Collaborator

nehmebilal commented Jul 26, 2017

Just released 2.3.4 which fixes this issue. Please reopen if you have any problems.

@billyzkid
Copy link

billyzkid commented Jul 26, 2017

I am still seeing the same issue with the 2.3.4 release. Can someone please verify? Here is my test interface and the generated stub that fails to build:

public interface ISomeInterface
{
    event EventHandler<IEnumerable<string>> SomeEvent;
}

This fails with "Argument 2: cannot convert from 'System.Collections.IEnumerable' to 'System.Collections.Generic.IEnumerable'":

[CompilerGenerated]
public class StubISomeInterface : ISomeInterface
{
    private readonly StubContainer<StubISomeInterface> _stubs = new StubContainer<StubISomeInterface>();

    public event global::System.EventHandler<global::System.Collections.Generic.IEnumerable<string>> SomeEvent;

    protected void On_SomeEvent(object sender, IEnumerable args)
    {
        global::System.EventHandler<global::System.Collections.Generic.IEnumerable<string>> handler = SomeEvent;
        if (handler != null) { handler(sender, args); }
    }

    public void SomeEvent_Raise(object sender, IEnumerable args)
    {
        On_SomeEvent(sender, args);
    }
}

@nehmebilal
Copy link
Collaborator

I just created a class library and installed 2.3.4 to it.

I am getting:

    [CompilerGenerated]
    public class StubISomeInterface : ISomeInterface
    {
        private readonly StubContainer<StubISomeInterface> _stubs = new StubContainer<StubISomeInterface>();

        public MockBehavior MockBehavior { get; set; }

        public event global::System.EventHandler<global::System.Collections.Generic.IEnumerable<string>> SomeEvent;

        protected void On_SomeEvent(object sender, global::System.Collections.Generic.IEnumerable<string> args)
        {
            global::System.EventHandler<global::System.Collections.Generic.IEnumerable<string>> handler = SomeEvent;
            if (handler != null) { handler(sender, args); }
        }

        public void SomeEvent_Raise(object sender, global::System.Collections.Generic.IEnumerable<string> args)
        {
            On_SomeEvent(sender, args);
        }

        public StubISomeInterface(MockBehavior mockBehavior = MockBehavior.Loose)
        {
            MockBehavior = mockBehavior;
        }
    }

@billyzkid
Copy link

My bad. It does seem to work. I guess when it updated my nuget reference, there was a lingering nuget .targets file which looked to be referencing the previous version of SimpleStubs. Probably something to do with my recent upgrade to VS 2017, who knows... Thanks!

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

3 participants