Skip to content

Commit 8f29b53

Browse files
committed
Add regression tests for subscribing to & raising redeclared event
fixup regr tests add
1 parent 4ab6ce1 commit 8f29b53

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

‎tests/Moq.Tests/Regressions/IssueReportsFixture.cs‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,77 @@ public virtual void SecondCall()
36883688

36893689
#endregion
36903690

3691+
#region 1175
3692+
3693+
public class Issue1175
3694+
{
3695+
[Fact]
3696+
public void Can_subscribe_to_and_raise_redeclared_event_1()
3697+
{
3698+
var handled = false;
3699+
3700+
var mock = new Mock<IDerived>();
3701+
mock.Setup(x => x.RaiseEvent()).Raises(x => x.Event += null, false);
3702+
mock.Object.Event += _ => handled = true;
3703+
3704+
mock.Object.RaiseEvent();
3705+
3706+
Assert.True(handled);
3707+
}
3708+
3709+
public interface IBase
3710+
{
3711+
event Action Event;
3712+
void RaiseEvent();
3713+
}
3714+
3715+
public interface IDerived : IBase
3716+
{
3717+
new event Action<bool> Event;
3718+
}
3719+
3720+
[Fact]
3721+
public void Can_subscribe_to_and_raise_redeclared_event_2()
3722+
{
3723+
var aEventsMock = new Mock<IGenericHidingEvents<bool>>();
3724+
var aConsumer = new GenericHidingEventConsumer(aEventsMock.Object);
3725+
3726+
aEventsMock.Raise(theO => theO.Created += null, this, true);
3727+
3728+
Assert.True(aConsumer.EventHandled);
3729+
}
3730+
3731+
public interface IEvents
3732+
{
3733+
event EventHandler Created;
3734+
}
3735+
3736+
public interface IGenericHidingEvents<T> : IEvents
3737+
{
3738+
new event EventHandler<T> Created;
3739+
}
3740+
3741+
public class GenericHidingEventConsumer
3742+
{
3743+
private IGenericHidingEvents<bool> myHidingEvents;
3744+
3745+
public GenericHidingEventConsumer(IGenericHidingEvents<bool> theHidingEvents)
3746+
{
3747+
this.myHidingEvents = theHidingEvents;
3748+
this.myHidingEvents.Created += this.HidingEventsOnCreated;
3749+
}
3750+
3751+
private void HidingEventsOnCreated(object theSender, bool theE)
3752+
{
3753+
EventHandled = true;
3754+
}
3755+
3756+
public bool EventHandled { get; set; }
3757+
}
3758+
}
3759+
3760+
#endregion
3761+
36913762
#region 1217
36923763

36933764
public class Issue1217

0 commit comments

Comments
 (0)