With JustMock you can mock internal types with InternalsVisibleToAttribute the same way you mock public types. Without InternalsVisibleToAttribute you are forced to mock as you mock non-public members.
In the further examples, we will use the following sample classes to test:
Mock Internal Type Via Proxy
Provided that the InternalsVisibleTo attribute is included in the AssemblyInfo.cs, let's consider the following example:
Here we verify that the mock is created and its constructor is called.
Thus, foo.Builder will be assigned.
The key to be used in the InternalsVisibleTo attribute is as follows:
[assembly: InternalsVisibleTo("Telerik.JustMock, PublicKey=0024000004800000940000000602000000240000525341310004000001000100098b1434e598c6" +
Create Mock With Internal Constructor
You can mock class that exposes internal constructor in the same way you mock public types.
In the example above, we mock the internal constructor of FooInternalCtor class.
When foo is created the internal constructor will be called with "hello" as argument and the Name property will be assigned "hello" respectively.
We verify that by calling foo.Name in the assertion phase of the AAA pattern.
Mock An Interface Member, Privately Implemented In Base Class
Here is an interface with a single member in it and a class which is inheriting that interface.
The derived class Bar will be our object to mock, in the example below.
We have mocked the Bar class. Then we make arranges about the interface member, Provider and we act. Finally we can assert that the test behavior is as expected.