Raise.With does not work properly in release mode
See original GitHub issueJust try to execute this code in release and in debug mode. Debug works, release fails. Tried with FakeItEasy version 1.25.3
public interface ITestA
{
event EventHandler Closed;
event EventHandler Loaded;
void DoStuff ();
void Wicked ();
}
public interface ITestB
{
void DoStuff ();
void Wicked ();
void Wicked1 (ITestA a);
}
public class TestB
{
private readonly ITestA _a;
private readonly ITestB _b;
public TestB (ITestA a, ITestB b)
{
_a = a;
_b = b;
}
public void Attach ()
{
WeakEventManager<ITestA, EventArgs>.AddHandler(_a, EventNames.Closed, Closed);
WeakEventManager<ITestA, EventArgs>.AddHandler(_a, EventNames.Loaded, Loaded);
_a.Wicked();
_b.Wicked();
}
private void Loaded (object sender, EventArgs e)
{
_b.DoStuff();
}
private void Closed (object sender, EventArgs e)
{
_a.DoStuff();
// _b.Wicked1(_a.Value);
}
}
[TestFixture]
public class MyTest
{
[Test]
[Repeat (1000)]
public void Test ()
{
var a = A.Fake<ITestA>();
var b = A.Fake<ITestB>();
var inst = new TestB(a, b);
inst.Attach();
A.CallTo(() => a.Wicked()).MustHaveHappened(Repeated.Exactly.Once);
A.CallTo(() => b.Wicked()).MustHaveHappened(Repeated.Exactly.Once);
a.Closed += Raise.With(null, new EventArgs()).Now;
A.CallTo(() => a.DoStuff()).MustHaveHappened(Repeated.Exactly.Once);
// A.CallTo(() => b.Wicked1(a)).MustHaveHappened(Repeated.Exactly.Once);
a.Loaded += Raise.With(null, new EventArgs()).Now;
A.CallTo(() => b.DoStuff()).MustHaveHappened(Repeated.Exactly.Once);
}
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
My code does not work on Release mode while ...
A program that works in debugging mode but fails in release mode is often caused by a bad operation on a pointer (dereferencing...
Read more >The program works in Debug mode but not in Release mode
Hey, I have been working on a program and it works perfectly in the CVI environment during debug mode but when I am...
Read more >App works in debug mode but does not work in release mode
I am making a chat app..with firebase and CloudFirestore...in debug mode the app is working fine ..the chat and all is loading but...
Read more >App doesn't work in release apk but works fine in debug ...
My app works fine in debug mode but when i make its release build blank screen comes up as soon as internet is...
Read more >Is throwing exceptions in Debug mode a bad idea? [closed]
For that reason I want to log exceptions only in Release mode but not in Debug mode. Let's say my intention is to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MrVermond, it doesn’t appear to be
Raise
. I sloppily rewrote the test so we could raise the events via a public method:and got this failure:
This lead me to believe that the problem is that the runtime thinks we’re done with some objects so we can start unhooking events.
Indeed, adding this line to the bottom either of my new test or your original test causes them to pass:
So I think we may just be seeing normal
WeakEventManager
behaviour.@MrVermond, I’m glad to have been of assistance.