This is a migrated thread and some comments may be shown as answers.

Mock Thread fails

1 Answer 20 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Edoardo
Top achievements
Rank 1
Edoardo asked on 11 May 2012, 09:28 AM
I'm using JustMock Q1 2012 SP1 (2012.1.508.6) and when I try to create a mock of the Thread class, I get an exception.

I tried the following methods:

- var mock = Mock.Create<Thread>.Create(any argument);
- var mock = Mock.Create<Thread>.Create(new Thread(delegate{}));

Both fails whether I use the MockClass attribute or not.

Any suggestion?
Thanks.

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 15 May 2012, 05:49 PM
Hi Edoardo,
Thanks again for contacting us. Here it is possible to mock the Thread class in one of the following two ways:

#1 : Using Constructor.Mocked so that it does not execute the real constructor:

var mock = Mock.Create<Thread>(Constructor.Mocked);
Assert.IsNotNull(mock);

#2: By injecting the original ParameterizedThreadStart argument:

[TestMethod]
public void TestMethod1()
{
    var parameterizedStart = new ParameterizedThreadStart(target);
    //var mock = Mock.Create<Thread>.Create(any argument);
    var mock = Mock.Create<Thread>(parameterizedStart);
    Assert.IsNotNull(mock);
 
}
 
void target(object sender)
{
 
}


Hope this answers your question.


Kind Regards
Ricky
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Edoardo
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or