microsoft / SimpleStubs

*SimpleStubs* is a simple mocking framework that supports Universal Windows Platform (UWP), .NET Core and .NET framework. SimpleStubs is currently developed and maintained by Microsoft BigPark Studios in Vancouver.
Other
66 stars 29 forks source link

Error with events and IEnumerable<T> #27

Closed Portikus closed 7 years ago

Portikus commented 7 years ago

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 commented 7 years ago

Hi @Portikus,

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

nehmebilal commented 7 years ago

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

billyzkid commented 7 years ago

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

nehmebilal commented 7 years ago

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

nehmebilal commented 7 years ago

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

billyzkid commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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!