Questions tagged [fakeiteasy]

A .NET package to create fake objects, mocks, stubs for testing.

The following description is taken from the FakeItEasy homepage:

A .Net dynamic fake framework for creating all types of fake objects, mocks, stubs etc.

  • Easier semantics: all fake objects are just that — fakes. Usage determines whether they're mocks or stubs.
  • Context-aware fluent interface guides the developer
  • Easy to use and compatible with both C# and VB.Net.
359 questions
0
votes
2 answers

Is there any way to create a fake from a System.Type object in FakeItEasy?

Is there any way to create a fake from a System.Type object in FakeItEasy? Similar to: var instance = A.Fake(type); I try to write a fake container for AutoFac that automatically return fakes for all resolved types. I have looked in the code for…
Martin Odhelius
  • 990
  • 6
  • 15
0
votes
1 answer

Mock HttpClient.SendAsync to return response with Content not null

I'm trying to mock var response = await httpClient.SendAsync(request, CancellationToken.None); but my response.Content is always null. My mock looks like... var httpResponseMessage = new…
Robert Green MBA
  • 1,834
  • 1
  • 22
  • 45
0
votes
1 answer

FakeItEasy - Mock the return value during the call interception

Could you please help me with fakeItEasy advanced usage. I got method (suppose it called "Insert") which takes an argument as parameter. This parameter filled with data (a lot of it). I want to return this argument as the result of "Insert"…
Vlad
  • 86
  • 5
0
votes
1 answer

Can I register a fake instance and declare it's return on registration?

I'm building a testing framework for our Xunit tests. I wanted to create a fake SMTP service that will mimic ours but won't actually work for the tests (For obvious reasons). Creating a fake instance was easy and worked like a charm. I've added…
Gezman
  • 29
  • 4
0
votes
1 answer

Testing a method that calls a BackgroundWorker

Description Consider a class such as the following. It has a BackgroundWorker as a property, and a method that lets it report progress: public class MyClass { protected BackgroundWorker _worker; public MyClass(BackgroundWorker worker) …
Al2110
  • 566
  • 9
  • 25
0
votes
2 answers

Faking SqlConnection and embedded methods in the NUnit Test, using FakeItEasy

I have the following class and methods, that will be connecting to a DB, but for testing, I do not need the real connection and would need to fake it. We're using FakeItEasy for this.: public abstract class HandlerBase { public string…
KVN
  • 863
  • 1
  • 17
  • 35
0
votes
1 answer

Mediatr pattern unit testing

I'm trying to setup unit testing for my API controllers. I'm using the mediatr pattern and FakeIteasy. I have the following code. public class ChannelGroupChannelsControllerTests { private readonly ChannelGroupChannelsController _controller; …
0
votes
1 answer

Failed to create fake when default constructor for the object is not empty

I'm new to FakeItEasy, and I have a few test cases which are used to pass before (when I had no specific constructors defined). Then I have created a default constructor for one for the object I'm faking, the default constructor only create…
KVN
  • 863
  • 1
  • 17
  • 35
0
votes
1 answer

Accessing runtime value for a property during FakeItEasy test

We're using FakeItEasy for our unit tests. I have a method1 that returns a value for one property, while updating it another property2 value during runtime. What I need is to get the Updated value for property2 during my test. But it does not return…
KVN
  • 863
  • 1
  • 17
  • 35
0
votes
1 answer

How to do parameter validations of fake method using Fake It Easy

I am new to writing unit test cases using Fake It Easy. I could not able to figure it out that, How can we validate that method is called by some specific parameters? Please see the example below Main Class //Model public class Request { public…
rajk
  • 221
  • 3
  • 19
0
votes
1 answer

FakeItEasy and matching Anonymous types

I having trouble matching an expectation that uses anonymous types. I am new to FakeItEasy but not to mocking and would like some guidance on what is the proper way to match arguments. I understand from this thread…
philipwolfe
  • 338
  • 1
  • 7
0
votes
1 answer

How to fake a nested property by using FakeItEasy?

I have a class like as below: public class NodeOperator { private NodeInfo _nodeInfo; public NodeOperator(NodeInfo nodeInfo) { _nodeInfo = nodeInfo; } public bool DoSomething(int dstRackId, int srcRackId, ModuleBase…
Harris.Dai
  • 21
  • 3
0
votes
2 answers

How to mock class members in C#?

I'm trying to use FakeItEasy to mock an object that is a member of a C# class I'm creating. The FakeItEasy documentation indicates that you fake an object in a way similar to this: private static var m_physics = A.Fake(); That is, using…
Buggieboy
  • 4,636
  • 4
  • 55
  • 79
0
votes
1 answer

Unit testing a service class with dependency on httpclient response

I have a service-class that gets a FlurlHttpClient injected in the constructor. It has a public method which makes a call using the httpClient and then parses the response and returns a class. So basically I want to fake the response from the API…
user5283666
0
votes
1 answer

How to fake ScanResponse?

I am writing Unit test cases for getting the records from Dynamodb. Dynamodb is returning scanResponse. I want to fake ScanResponse. How to do it?