chevron-thin-right
chevron-thin-left
brand
cancel-circle
search
youtube-icon
google-plus-icon
linkedin-icon
facebook-icon
twitter-icon
toolbox
download
check
linkedin
phone
twitter-old
google-plus
facebook
profile-male
chat
calendar
profile-male
Products
Isolator for C++
Isolate ++
Isolator for .NET
Suggest
Isolate
Smart Runner
Coverage – Part of Typemock Isolator Complete .NET
Isolator for Build Server
Download
C++
.NET
Pricing
Resources
Documentation
Isolator++
Isolator
Learning Center
Tutorials
Webinars
Articles
Case Studies
Partners
Blog
Support
C++ Community
.NET Community
Premium Support
Products
Isolator for C++
Isolate ++
Isolator for .NET
Suggest
Isolate
Smart Runner
Coverage – Part of Typemock Isolator Complete .NET
Isolator for Build Server
Download
C++
.NET
Pricing
Resources
Documentation
Isolator++
Isolator
Learning Center
Tutorials
Webinars
Articles
Case Studies
Partners
Blog
Support
C++ Community
.NET Community
Premium Support
Menu
Search
Remember
Register
Typemock Q&A
Ask a question
All Activity
Questions
Hot!
Unanswered
Tags
Users
Ask a Question
The Unit Testing Company
Development Resources
Knowledge Base
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
Related questions
Issue with firing an event for an interface that has two Eventhandlers of the same name
Naturally Mocking an Event
fake an event call
Fire of multiple mocked event handlers
Mocking Abstract Class Implementing Interface with Event
mocking firing of an event
0
votes
Hi. I am trying to mock the firing of an event in 3.7.1 (enterprise license) and am getting the following error:
Test method UnitTest.ClassDerivedTest.TestOnResetEventIsCalled threw exception: TypeMock.TypeMockException:
*** No handlers are registered to the event.
This is happening in the case where my event is in the base class. I have created a small example.
using System;
namespace EventBug
{
public class ClassBase
{
public delegate void ResetHandler();
public event ResetHandler OnReset;
}
public class ClassDerived : ClassBase
{
public ClassDerived()
{
OnReset += new ResetHandler(MyOnReset);
}
public void MyOnReset()
{
Console.WriteLine("Handler is called");
}
}
}
My test is
// The following code was generated by Microsoft Visual Studio 2005.
// The test owner should check each test for validity.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;
using EventBug;
using TypeMock;
namespace UnitTest
{
/// <summary>
///This is a test class for EventBugTypeMock.ClassDerived and is intended
///to contain all EventBugTypeMock.ClassDerived Unit Tests
///</summary>
[TestClass()]
public class ClassDerivedTest
{
[TestMethod()]
public void TestOnResetEventIsCalled()
{
Mock mockEvent = MockManager.MockAll(typeof(ClassBase)); // I have also tried ClassDerived here.
MockedEvent onReset = mockEvent.ExpectAddEvent("OnReset");
ClassDerived dc = new ClassDerived();
onReset.Fire();
MockManager.Verify();
}
}
}
I am not sure what is wrong. I have a test working where the event is not part of a base class.
Thanks for your help.
Sam
asked
Mar 9, 2007
by
darkelf1217
Report User
(
1.3k
points)
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
2
Answers
0
votes
Hi
The problem is that by default the constructor is mocked
so if you'll change the mock statement to
Mock mockEvent = MockManager.MockAll(typeof(ClassDerived), Constructor.NotMocked);
The test will run just fine 8)
answered
Mar 9, 2007
by
ohad
Report User
(
35.4k
points)
Please
log in
or
register
to add a comment.
0
votes
Thanks Ohad. That fixed the test for 1 of my 2 event handlers. The other one is exactly the same but comes from an abstract class. It works in my little test case (with an abstract class) but not in my real code. I'll have to look into it more.
Sam
answered
Mar 12, 2007
by
darkelf1217
Report User
(
1.3k
points)
Please
log in
or
register
to add a comment.
...
×
Choose the product type:
WINDOWS
LINUX DEB
LINUX RMP
×