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
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.
0 votes
Okay, bear with me...this is an intersting problem and I am mainly just looking for an explanation for my education. I don't think it is necessarily a "problem" or bug with TypeMock. I'm sure it has to do with my lack of understanding of exactly how Mock objects work.

I am using TypeMock 3.1.0 with Nunit 2.2.7. I am running the tests through TestDriven.net in VS2005.

I have the following setup in my TestFixture
[TestFixture]
public class sqlHelperFixture
{
     private Mock exeQueryMock;

    [Setup]
    public void Setup()
    {
          exeQueryMock = MockManager.Mock(typeof(SqlHelper), Constructor.Mocked);
    }
}


Now I have this test which does _Not_ attempt to make use of this Mock instance.
    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
        public void ExecuteNonQueryWithNullStrConnException()
        {
            SqlHelper.ExecuteNonQuery((SqlConnection)null, "ProcedureName", (SqlParameter[])null);
            
        }


When I run the test it fails but then the expected exception is thrown out to the console.

The expected behavior here is that the exception to be caught as expected and the test should pass.

When I removed the declaration at the class level and started using local Mock objects in each of my tests, the above test began working.

Thanks in advance for any explanations.
asked by IfValueEqNull (1.1k points)

1 Answer

0 votes
Hi,
I have tried your example in house and it work fine.
My guess is that you are mocking the constructor, you might have some static fields that are not being correctly initialized causing some errors.
You can use the TypeMock Tracer to see what methods are being called or try to mock without mocking the constructors.
In any case if this doesn't work please send the detailed error.
answered by scott (32k points)
...