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
I'm not sure if I'm doing something wrong or if there's a problem with TypeMock (the former is more likely).

I have the following code that I'd like to test:

   #region Entity
    public interface IEntity
    {
        int Id {get;}
    }
    public class Company : IEntity
    {
        public int Id
        {
            get { return 1; }
        }
        public string Name;
    }
    #endregion Entity

    #region Repository
    public interface IEntityRepo
    {
        T Get<T>(int i);
    }
    public class Repo : IEntityRepo
    {
        public T Get<T>(int i) 
        {
            IEntity company = new Company();  //this part is for demonstration
            ((Company)company).Name = "test"; //this part is for demonstration

            T t = (T)company;
            return t;
        }
    }
    #endregion Repository

    #region Client
    public class MyClient
    {
        IEntityRepo repo;
        public IEntityRepo Repo
        {
            get 
            {
                if (repo == null)
                    repo = new Repo();
                return repo; 
            }
            set { repo = value; }
        }
        public Company GetCompany(int i)
        {
            Company c = Repo.Get<Company>(i);
            return c;
        }
    }
    #endregion Client


And I have the following two tests.
The "GetCompanyIntegrationTest" works but when I try to mock the repository in GetCompanyTestUsingTypeMock, I get an exceptioin from TypeMock (see error below)

        [TestMethod()]
        public void GetCompanyTestUsingTypeMock()
        {
            MyClient target = new MyClient();
            MockManager.Init();
            TypeMock.MockObject mockRepo = TypeMock.MockManager.MockObject(typeof(IEntityRepo));
            Company c = new Company();
            c.Name = "test";
            mockRepo.ExpectAndReturn("Get", c, 1);
            target.Repo = (IEntityRepo)mockRepo.Object;
            Assert.AreEqual(target.GetCompany(1).Name, "test");
        }
 
        [TestMethod()]
        public void GetCompanyIntegrationTest() 
        {
            MyClient target = new MyClient();
            target.Repo = new Repo();
            Assert.AreEqual(target.GetCompany(1).Name, "test");
        }




So when I run "GetCompanyTestUsingTypeMock" I get:

TestCase 'TestProject1.MyConsumerTest.GetCompanyTestUsingTypeMock' failed: System.TypeLoadException: Method 'Get' in type 'MockIEntityRepo' from assembly 'DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(Int32 handle, Module module)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at s.a(Type A_0, Object[] A_1)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject(Type type, Object[] args)
C:Documents and SettingsgregMy DocumentsVisual Studio 2005ProjectsNMockGenericsTestTestProject1Class1Test.cs(123,0): at TestProject1.MyConsumerTest.GetCompanyTestUsingTypeMock()



Any Ideas?
Greg
asked by gbanister (600 points)

2 Answers

0 votes
Hi,
This is actually a bug in TypeMock. We will send you a fix offline.
answered by scott (32k points)
0 votes
Fixed in version 3.1
answered by scott (32k points)
...