- Install through Nuget
2. Download the website (the official website does not point here)
3. Help documentation
Business Edition and Free Edition difference overview
Mockingcontainer
Test class Preparation: Generally, it is also a business class
public class Classundertest { private ifirstdependency firstdep; Private iseconddependency SECONDDEP; Public Classundertest (ifirstdependency first, iseconddependency second) { THIS.FIRSTDEP = first; THIS.SECONDDEP = second; } Public ilist<object> Collectionmethod () { var firstcollection = Firstdep.getlist (); return firstcollection; } public string Stringmethod () { var secondstring = seconddep.getstring (); return secondstring; } } Public interface ifirstdependency { ilist<object> GetList (); } Public interface iseconddependency { string GetString (); }
Unit Test
[TestMethod] public void Shouldmockdependencieswithcontainer () {//ARRANGE// Creating a mockingcontainer of classundertest. To instantiate the system Uder test (the container) your should use the Instance property//For Example:co Ntainer. Instance. var container = new mockingcontainer<classundertest> (); String expectedstring = "Test"; Arranging:when the GetString () method from the Iseconddependecy interface//was called from T He container, it should return expectedstring. Container. Arrange<iseconddependency> (SECONDDEP = seconddep.getstring ()). Returns (expectedstring); Act-calling Sringmethod () from the mocked instance of classundertest var actualstring = container. Instance.stringmethod (); ASSERT assert.areequal (expectedstring, actualstring); }
It is important to note that the Mockingcontainer constructor has an optional parameter, automocksettings, where automocksettings one of the main functions is when classundertest has more than one constructor, Specify the appropriate constructor to instantiate the object
When there is a parameterless constructor in the business class, a parameterless constructor is executed by default without setting automocksettings,
You can specify the required constructors as follows
Automocksettings settings = new Automocksettings { constructorargtypes = new type[]{ typeof ( Ifirstdependency), typeof (Iseconddependency) } }; ARRANGE //Creating a mockingcontainer of classundertest. To instantiate the system Uder test (the container) your should use the Instance property //For Example:container . Instance. var container = new mockingcontainer<classundertest> (settings);
Justmock Lite (Free Mocking Framework for. NET)