Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the problem with mocking the mockfactory?


Asked by Coen Reid on Dec 08, 2021 FAQ



I think the problem with my test is that the way I setup the moq of the factory mockFactory.Setup (m => m.GetSkuCountsByRetailerVm ()).Returns (new SkuCountByRetailerVm ()); the vm just points to the same object, so I would rather need to have it instantiate a new vm each time?
In addition,
If a property is mockable, a mock is automatically returned. The constructor of the MockFactory needs a MockBehaviour parameter. 3 values are possible, Default, Loose and Strict. Strict mock makes mocked object throw an exception for every call to a mocked object that doesn’t have an expectation.
Just so, Moq have factories to help centralize the mocking configuration. The only two configuration available is CallBase and DefaultValue. Every mock created with the factories will allow you to reuse the configuration and reduce the amount of line for setting up the mock. Here’s a sample for the factory initialization:
Also Know,
This is called “Partial Mock”. It allows to mock certain part of a class without having to mock everything. There is 2 possible values here. One of them is “Empty” which return default value of the class. The one used in the example is “Mock” which allows “automocking”. If a property is mockable, a mock is automatically returned.
Besides,
The one used in the example is “Mock” which allows “automocking”. If a property is mockable, a mock is automatically returned. The constructor of the MockFactory needs a MockBehaviour parameter. 3 values are possible, Default, Loose and Strict.