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
0 votes
Using Visual Studio Team for Developers, and SQL Server Express.
I am trying to evaluate TypeMock. Below is a test program that
recreates the problem I am seeing.

To run this, you will need to create local database called 'TypeMockTest'
TypeMockTest database needs 1 table (called TestTable) with three columns as below (column name/ data type):

Name / char(20)
TestTableId / uniqueidentifier
Count / int

I see the following exception thrown:
Test method Store.Test.StoreUnitTest.TestAssetDbStore threw exception: System.TypeLoadException: Could not load type 'RBTreeEnumerator' from assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..

and this is the stack trace I see:
at System.Data.RBTree`1.RBTreeEnumerator..ctor(RBTree`1 tree)
at System.Data.RBTree`1.GetEnumerator()
at System.Data.DataRowCollection.GetEnumerator()
at System.Data.Common.ADP.SelectAdapterRows(DataTable dataTable, Boolean sorted)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Store.Test.Agent.Run() in C:srclatestTestsAgentsRecordsAgentRecordsAgent.TestRecordsAgentUnitTest.cs:line 107
at Store.Test.StoreUnitTest.TestAssetDbStore() in C:srclatestTestsAgentsRecordsAgentRecordsAgent.TestRecordsAgentUnitTest.cs:line 77

Note: If I comment out all Mock lines... and change the Launch() method
to 'return 0;' rather than throw an exception, then this unit test passes.


using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using TypeMock;
using System.Data.SqlClient;
using System.Data;


namespace Store.Test
{
    [TestClass]
    public class StoreUnitTest
    {
        public StoreUnitTest()
        {
        }

        [TestInitialize()]
        public void MyTestInitialize()
        {
            MockManager.Init();
        }

        [TestCleanup()]
        public void MyTestCleanup() 
        {
           MockManager.Verify();
        }
        
        void userProcessMock_MockMethodCalled(object sender, MockMethodCallEventArgs e)
        {
            if (!e.CalledMethodName.Equals("Launch"))
            {
                return;
            }

            if (e.SentArguments[0].GetType().Equals(typeof(String)) &&
                e.SentArguments[1].GetType().Equals(typeof(UInt32)))
            {
                return;
            }

            throw new Exception("The method or operation is not implemented.");
        }

        [TestMethod]
        public void TestAssetDbStore()
        {

            Mock userProcessMock = MockManager.MockAll(typeof(UserProcess), Constructor.NotMocked);
            userProcessMock.AlwaysReturn("Launch", (UInt32)0, null);
            userProcessMock.ExpectUnmockedConstructor();
            userProcessMock.MockMethodCalled += new MockMethodCalledEventHandler(userProcessMock_MockMethodCalled);

            Agent agent = new Agent();
            agent.Run();

        }
    }

    public class Agent
    {
        private SqlDataAdapter dataAdapter;
        public Agent()
        {
            String connect = @"server=.SQLExpress;Trusted_Connection=yes;Database=TypeMockTest";
            String sql = @"Select * from TestTable;";
            dataAdapter = new SqlDataAdapter(sql, connect);
        }

        public void Run()
        {
            UserProcess.Launch("", 0);

            // update sql
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds, "Result");
            DataTable dTable = ds.Tables[0];
            DataRow drow = dTable.NewRow();

            drow["Name"] = "example";
            drow["TestTableId"] = new Guid();
            drow["Count"] = 1;

            dataAdapter.Update(dTable);
        }
    }

    public class UserProcess
    {
        public static UInt32 Launch(string s, UInt32 i)
        {
            throw new Exception("should have been mocked");
        }
    }

}

asked by Dale Passmore (600 points)

3 Answers

0 votes
Hi Dale,
First thanks for the example.
We have managed to track down the bug to any Generic struct.

Example:
public struct FailingStruct<T>
{
    public FailingStruct(T d)
    {
    }
}


We will create a fix and send it to you
answered by scott (32k points)
0 votes
Hi,
A fix was sent offline, it will be incorporated in our next patch release.
answered by scott (32k points)
0 votes
This issue is fixed in version 3.0.2 :D
answered by scott (32k points)
...