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
Hi,

is anybody using the team edition or suite with the built-in unit testing?
Does that work together with TypeMock :?:
asked by mknaup (8.5k points)

8 Answers

0 votes
Hi Michael,

TypeMock.NET has been tested and verified to work with Team System Unit Tests.
If you have a problem running them together, please post the problem and we will do our best to solve it.
answered by scott (32k points)
0 votes
Hi
Im trying to use typemock with Team system. Basically its working alright
but im still trying to see how do I combine this with the private accessors framework that Microsoft supply.
so far all my attempts failed.
I would appriciate any help on the subject
answered by lior (13.2k points)
0 votes
Hi,
This feature is for Natural Mocks (you don't need it for reflective mocks, just write the method :-) )
When using Natural Mocks, just call the private accessors and they will be mocked.
eg.
TestedClass target = new TestedClass();
MSTest.TestClassLibrary_TestedClassAccessor accessor = new MSTest.TestClassLibrary_TestedClassAccessor(target);

using (RecordExpectations r = RecorderManager.StartRecording())
{
    accessor.PrivateGetVar();
    r.Return(100);
}
answered by scott (32k points)
0 votes
Hi,
The problem is a little more complex, I probably didnt explain it too well sorry.
Anyway, what exactly I am trying to do is to pass a mock (in the ctor) to another class being tested.
the issue is that both classes (the one being tested and the one I want to mock) are internal and therefore they both need to be created using the accessor classes (in MS-Team).
Ive tried several things with reflective mock and all led to an exception being thrown by the inner methods called by the MS_Team (he tries to cast from MockObject to the class being mocked).

is there a way to achieve this in reflective mocks?

let me know if more info is needed.
thanx
answered by lior (13.2k points)
0 votes
Hi,
Simply send MockObject.Object and not the MockObject class.

MockObject mockController = MockManager.MockObject....
PassToConstructor test = new PassToConstructor (mockController.Object);
answered by scott (32k points)
0 votes
Hi,
I think that is what im doing,
here is the code:

tested classes:
class inner
{
    internal void f()
    {    }
}

public class outer
{
    private inner m_inner;

    internal outer(inner a)
    {
        m_inner = a;
    }
    public void g()
    {
        m_inner.f();
    }
}

the test method
[TestMethod()]
  public void gTest()
  {
     MockManager.Init();

     MockObject innerMock = MockManager.MockObject(typeof(inner));
     MockObject innerAcessorMock = MockManager.MockObject(
                          typeof(innerAccessor));
     innerAcessorMock.ExpectGet("Target", innerMock);

     outer target = outerAccessor.CreatePrivate(
                             (innerAccessor)(innerAcessorMock.MockedInstance));
     innerMock.ExpectCall("f");

     target.g();
     MockManager.Verify();
}
answered by lior (13.2k points)
0 votes
Hi,
Try using this magic. 8)
Simply mock the innerClass
(don't create an object now, just hook the system to mock the next future instance)
// mock next instance of inner.
Mock innerMock = MockManager.Mock(typeof(inner)); 
innerMock.ExpectCall("f"); 

target.g(); 
MockManager.Verify(); 


or in reflective mocks:
using (RecordExpectations r = RecorderManager.StartRecording())
{
    innerAccesor mockedInner = Accessor.CreatePrivate();
    mockedInner.f();
}
answered by scott (32k points)
0 votes
thanx
the magic works :D
answered by lior (13.2k points)
...