Breaking News

c# – How to handle mocking (Rhino Mock) and unity container in different unit test classes?-Exceptionshub

Questions:

I am working on a large desktop application. The application communicates with number of external services and application is using Unity container to resolve the objects. I am facing issue in writing unit test using rhino mock. I am mocking those services that communicates with external services. I have a class “HatAgent.cs” that communicates with external service. I mock this class in my unit test. The life time scope of “HatAgent.cs” is singleton.

If i have different unit test classes and in one class if i mock “HatAgent.cs” and override it like below:

var agent = MockRepository.GenerateMock();
//Stub methods.....
IocContainerFactory.Instance.OverrideRegistrations(c => c.RegisterInstance(typeof(IHatAgent), agent ));

It works fine when i run unit test of that classe. But if i mock this in different unit test classes and when run all unit test together, my test fails. The reason in my methods when IHatAgent resolves, it gets the mock object of those unit test class which constructor runs last.

How to handle this?

Also, how unit test order runs?

How to&Answers:

About rankhawks

Check Also

c# – Acumatica upgrade from 18.210 to 18.217 (Unable to cast object of type ‘PX.Data.PXResult`2[PX.Objects.FS.FSServiceOrder,PX.Objects.AR.Customer]’-Exceptionshub

Questions: The source code of the button action is public PXAction CreateSalesOrder; [PXUIField(DisplayName = "Create …

jQuery offline slideshow on Android-Exceptionshub

(function($){ $.fn.chocolate = function(args) { // Default Options var options = $.extend({ interval : 1000, …

javascript – Actualize Database Data with Functions Cloud-Exceptionshub

Questions: I am developing an Android application and I have a problem that I cannot …

valgrind for Android devices (Crystax). configure: error: C compiler cannot create executables-Exceptionshub

Questions: Using and adapting the script(https://gist.github.com/smits/27060b310546ca6f76568f24838118c3) I get and error ” C compiler cannot create …

c# – Save position of Snake and Detect Collison with it self. Whats wrong?-Exceptionshub

Questions: using System; using System.Windows.Forms; using System.Collections.Generic; using System.Drawing; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTK.Graphics; …

Leave a Reply

Your email address will not be published. Required fields are marked *