Click here to Skip to main content
15,891,248 members
Everything / Mocking

Mocking

mocking

Great Reads

by Richard Silveira
EntityFramework.MoqHelper library to work with Entity Framework 6 and Moq libraries doing mocks of Entity Framework main methods that access database.
by Pavel Durov
This tip briefly shows how to change your user agent or any other data in window.navigator object.
by Ivan Yakimov
Cases when you may, and when you should not use mocking framework
by Vlad Neculai Vizitiu
Mocking/stubbing lambda expressions to have a bit more control over our unit tests

Latest Articles

by Pete O'Hanlon
Easy way to test HttpClient with Goldlight.HttpClientTestSupport
by Vlad Neculai Vizitiu
Mocking/stubbing lambda expressions to have a bit more control over our unit tests
by Daan Acohen
Some functionality of Moq can be really important but can also be easily forgotten as explained here
by Mirnes Mrkaljevic
This article shows how to use JSON response from REST service using Java GSON API.

All Articles

Sort by Score

Mocking 

31 Oct 2015 by Richard Silveira
EntityFramework.MoqHelper library to work with Entity Framework 6 and Moq libraries doing mocks of Entity Framework main methods that access database.
9 Oct 2015 by Pavel Durov
This tip briefly shows how to change your user agent or any other data in window.navigator object.
10 Mar 2017 by Ivan Yakimov
Cases when you may, and when you should not use mocking framework
8 Aug 2020 by Vlad Neculai Vizitiu
Mocking/stubbing lambda expressions to have a bit more control over our unit tests
15 Jan 2016 by BillWoodruff
How about reading discussions on the MOQ discussion forum (Google Group) that deal specifically with Abstract Classes: [^].And, then, consider posting a message to that group ? Of course, I would never under-estimate the possibility of someone on CodeProject showing up soon with righteous...
7 Jun 2022 by C Pottinger
I am changing a project of mine to use plug-ins for certain components (called FeedReaders), instead of having them defined in the main solution. I am following the technique present here by Duke of Haren. I am also using NUnit as by unit testing...
21 Oct 2014 by Member 11169453
I've calls to my data access from another class.So while implementing moq I have :var mockdac = new Mock();mockDac.SetUp(o => o.MyMethod(params)).Returns("something");Inside MyMethod I have :var reader = Database.ExecuteReader(cmd);while(reader.Read()){ //Some logic}My...
25 Oct 2014 by Tomas Takac
For what's worth, I wrote this article based on your question: IDataReader Stub[^]
17 Nov 2014 by Member 11052680
I have written a test class for my controller class using NUnit and Moq framework.My classes are following,public class ClientTypeControllerTest { ClientTypeController objClientTypeController;[SetUp]public void Initialize(){ _clientTypeServiceMock = new...
11 May 2015 by gsdvenkatesh
Hello,I am starting to write unit tests for my web application. I am confused in choosing the best mocking framework for it. I am using DevExpress controls all through my application and unfortunately they don't have a mocking framework. What is the best mocking framework that i can use...
11 May 2015 by gsdvenkatesh
Found this link to be very helpful - http://stackoverflow.com/questions/9677445/mock-framework-vs-ms-fakes-frameworks[^]
11 May 2015 by F-ES Sitecore
Most people use moq or rhinomock. Moq probably edges it for me, the main difference is in the syntaxes and what seems to make more sense to you. What's more important that which one you choose is that you fully get to grips with how you use it to mock various things, they're all much of a...
26 Jun 2015 by Member 11354558
Hi,I'm using SAPNcoconnector libraries to fetch the data from SAP server. I'm trying to create nUnit test cases for this.In the below example when I tried to access Repository property it is throwing exception because I've provide dummy SAP credentials and I've created dest object with...
8 Dec 2015 by pratik015
I am writing a unit test case for my application.In my application, I am using SQLite datebase.I want to mock following methods.Like,ExecuteNonQuery, ExecuteScalar, GetDataSet.I am writing my methods below.Please, any one help me to write mock unit test case for following...
8 Dec 2015 by F-ES Sitecore
That code isn't really unit-testable. When you unit test you have to convert your code into services that are accessed via interfaces and it is those services\interfaces that you moq. So create an IMyData interface with a GetJobs method, then create a MyData class that implements this...
15 Jan 2016 by Member 12266619
For Example:Consider a abstract class implementing an interfacepublic abstract class ClassA : IClassA{ protected abstract string Method();}So how can I mock Method() using MOQ mocking framework.Please help!!!!
3 Aug 2016 by Member 7730622
I would like to write unit test for one of my application which uses Azure Redis Cache. Since I am completely new to writing unit test code using mock/stub/fake, I am looking for help in how I can start with the basic script for mocking/stubbing cache component. It would be great, if somebody...
28 Aug 2016 by yeleswarapu ramakrishna
below is the method i tried to test but it fails for Employee.CurrentEmployee.IsManager this is a boolean value being fetched from a nested class which is dependent on the session so when i run unit test for this it fails cause there is no session created while i am running unit test so i tried...
28 Aug 2016 by FranzBe
you have some magic numbers there in your controller code. Why don't you swap this out in some extra class, thereby you get some interface you can mock against.e.g.void Main(){ var a = new PlanAuthorizationProvider(); var result = a.IsAuthorized(true, 387484); //result.Dump(); ...
19 Dec 2018 by Iris Shing
I'm writing APIs using c#.Net Core One of my APIs is used to generate captcha then store to the session, I'm using Redis to store session here. And now I'm trying to write a unit test for the APIs. Cause the login API needed to pass captcha, so I need to get the captcha value from the session....
17 Feb 2019 by deepaksharma0390
Hi, I am trying to test the LDAP authentication in an application. For authentication we are getting the InitialDirContext by passing the hashtable arguments. Is there a way I can mock this call. What I have tried: I tried mocking the InitialDirContext as below. ...
2 Oct 2021 by Simon_Whale
I need help with Mocking on Unit Tests. I am trying to call a method in a WebApi Controller that has the Authorization attribute on it, for example [Authorize] [HttpGet] [ActionName("FineOutcome")] [ProducesResponseType(typeof(Response), 200)] [ProducesResponseType(401)] public...
21 Feb 2019 by F-ES Sitecore
Unit tests are for testing your code and mocking is for replacing the parts of the functionality that are provided by third-parties that don't work in your testing environment (HttpContext being a good example, your unit tests are not running in the context of a web site), or that you need to...
14 May 2019 by IlanGreen
I need to mock objects and change method behavior in c++. The problem is that Gmock requires my methods to be virtual in order to inherit from them and change the behavior but I am not able to change my methods to virtual. What I have tried: I have tried Typemock Isolator++, it can access any...
14 May 2019 by Richard MacCutchan
Take your pick: List of unit testing frameworks - Wikipedia[^].
27 Mar 2021 by Mariusz Siedlecki
I have a Mock in Test that has JSON and it's big. How to load it from a file. Whether Mock should be in the resource directory or should it be in the test directory. @ExtendWith(MockitoExtension.class) class HubServiceTest { @InjectMocks...
7 Jun 2022 by blog.vitorrubio.com.br
I had same problem and tried some workarounds 1) make your plugin classes to be necessarily sealed and filter only by sealed types var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s =>...
14 Oct 2014 by Mario Majčica
When and how to use the Callback method on Moq in your unit tests.
21 Aug 2023 by Pete O'Hanlon
Easy way to test HttpClient with Goldlight.HttpClientTestSupport
8 Nov 2015 by Michael Pan
Presenting techniques for effective usage of Google unit test frameworks in embedded environment.
13 Oct 2016 by MaDOnos
Adapter implemantation to mock DbContext easily
10 Aug 2016 by Aless Alessio
Design your solution and code your classes as loosely-coupled objects. Learn how to use MOQ and Ninject for mocking your Service and injecting it at runtime with Ninject.
11 May 2016 by witnes
Examples of Mock usages
10 Mar 2019 by Mirnes Mrkaljevic
This article shows how to use JSON response from REST service using Java GSON API.
26 May 2020 by Daan Acohen
Some functionality of Moq can be really important but can also be easily forgotten as explained here
11 May 2015 by khanqamarali
FakeItEasy Framework Jump Start
30 Oct 2014 by suma_sarur
Hi,I have to automate my already existing (production) application, which is implemented using Visual Studio 2010.I am looking for some free (open source) Mocking tool which supports for Non Virtual members, b'coz my application does not have any virtual members and I can't change my...
22 May 2018 by Member 12658724
Please see the example. Say I have the data model as public class Model { [Required(ErrorMessage = "You must enter a username.")] [StringLength(10, MinimumLength = 4, ErrorMessage = "The username must be between 4 and 10 characters long")] [RegularExpression(@"^[a-zA-Z]+$",...
22 May 2018 by F-ES Sitecore
I googled "unit test mvc model validation" and this was the first result TDD for ASP.NET MVC Part 4: Unit Testing View Model Validation -- Visual Studio Magazine[^] If you google yourself you'll find others. In general though you should only unit test your own code, the model validation is...
30 May 2019 by DavidTypemock
Disclaimer - I work at Typemock the unit-testing company. You can easily change the behavior of a method with our API, for example: WHEN_CALLED(MyClass::GetSomething()).Return(15); In that way, in all of your tests, GetSomehting will return 15. It will work on Non Static methods too