internal
class
InternalClass
{
public
int
GetInt() {
return
5; }
}
internal
class
InternalOwner
{
public
int
GetInt() {
return
5; }
public
InternalClass InternalClassField =
new
InternalClass();
public
InternalClass InternalClassProp
{
get
{
return
InternalClassField; }
}
}
...
[Test]
public
void
Test5()
{
InternalOwner io = Mock.Create<InternalOwner>();
// Mock.Arrange(() => io.GetInt()).Returns(6); // Test1, works.
// Mock.Arrange(() => io.InternalClassField.GetInt()).Returns(6); // Test2, works.
Mock.Arrange(() => io.InternalClassProp.GetInt()).Returns(6);
// Test3, FAILS.
}
Adding the InternalsVisibleto assembly attribute has no effect.
9 Answers, 1 is accepted
Thanks again for reporting the issue. However, in your test I found that you have the following line:
Mock.Arrange(() => io.InternalClassField.GetInt()).Returns(6); .
This is invalid anyway since you can't mock a field as there is no way to intercept it. Next, adding the InternalsVisibleTo attribute from the following post made it work.
http://www.telerik.com/help/justmock/basic-usage-mock-internal-types-via-proxy.html
I have also included the test project to let you have a look. However, I found an exception accessing the InternalClass from this line:
Assert.AreEqual(6, io.InternalClassProp.GetInt());
For the above case, i am creating a task at PITS which you can follow here:
http://www.telerik.com/support/pits.aspx#/public/justmock/10540
I am also adding some telerik points into your account for your awesome support.
Kind Regards,
Mehfuz
the Telerik team

Test 'MsTestApp1.TestSuite1.Test6' failed: Test method MsTestApp1.TestSuite1.Test6 threw exception:
System.TypeAccessException: Attempt by method 'InternalOwner_Interceptor_fdecbacbc82243e184fd89253931c3c2.Intercept(InternalOwner, Boolean ByRef)' to access type 'MsTestApp1.TestSuite1+InternalClass' failed.
at InternalOwner_Interceptor_fdecbacbc82243e184fd89253931c3c2.Intercept(InternalOwner , Boolean& )
D:\_UserData\Development\Workspaces\CSharpTesting\JustMockTesting\MsTestApp1\TestSuite1.cs(25,0): at MsTestApp1.TestSuite1.InternalOwner.get_InternalClassProp()
D:\_UserData\Development\Workspaces\CSharpTesting\JustMockTesting\MsTestApp1\TestSuite1.cs(60,0): at MsTestApp1.TestSuite1.Test6()
I hope you can get that fixed quickly as it's a bit of a showstopper.
Don't you support mocking via Nunit? That's probably not a showstopper but Nunit has a good reputation (and I've never had any problems with it before) whereas most TDD guys suggest MsTest is pretty vile.
Thanks again for the reply. I am attaching the updated project with NUnit for your convenience and yes JustMock officially supports NUnit.
In addition, we are also looking into the issue mentioned in the following PITS entry and hopefully it will be fixed in coming release.
http://www.telerik.com/support/pits.aspx#/public/justmock/10540
Kind regards,
Mehfuz
the Telerik team

Thanks again for your reply. I will try to prepare an internal build next week once the issue is fixed. In the meantime, should you face any other problem please don't hesitate to contact me.
Kind Regards
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Thanks again for contacting us. I am still working on the issue. Hopefully I will send you a build early next week.
Thank you for your patience.
Kind Regards
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Thanks again for contacting us.
I am having some issues in fixing the bug. However, we have fixed a similar issue in SP1 that I would highly recommend to check out. In addition, I will hopefully get around the problem and send you a build next week, also let you know for any exceptions.
In addition, you can always reach me at mehfuz.hossain@telerik.com
Kind Regards
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>