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
3
votes
2 answers

How to mock configuration.GetSection with FakeItEasy syntax?

I have the following appsettings.json configuration. "SettingsConfig": [ { "Name": "Something", "Node": "Something", "SettingName": "Something" }, { "Name": "Something", "Node": "Something", "SettingName": "Something" }] I want to write…
Sarah
  • 65
  • 4
3
votes
1 answer

Can "event Action<>" be invoked with 3 type arguments using fakeiteasy in unit tests

I have looked quite a lot on the internet but somehow I am not grasping the concept to solve my problem. It should not be that complicated. I have a SUT (System Under Test), which has an event action like: event Action
Newbie007
  • 55
  • 6
3
votes
0 answers

C# MissingMethodException with DispatchProxy and FakeItEasy

I'm writing a class library with .NET Core and I'm using interception (DispatchProxy) for handling cross-cutting concerns. Now I have the problem that when unit testing the decorated object I get the following Exception: Exception thrown:…
Josh
  • 287
  • 1
  • 8
3
votes
2 answers

FakeItEasy to mock an object-modifying method

I am trying to write a unit test for a method that relies on a dependency which offers a method that accepts an object and modifies it, but does not return it on a "new path", e.g. as a return value or on a by reference parameter. public class…
Sigurd Garshol
  • 1,376
  • 3
  • 15
  • 36
3
votes
2 answers

Fake Captcha from commonlibnet with FakeItEasy and FluentValidation

I am using the Captcha class from commonlibrary (http://commonlibrarynet.codeplex.com/). My code works and everything but now I'm trying to write the unit test. My validation rule is: RuleFor(x => x.CaptchaUserInput) .NotEmpty() …
DavidS
  • 2,179
  • 4
  • 26
  • 44
3
votes
1 answer

FakeItEasy Returns different value for subsequent calls to the mock method

I have a function called GetNumber() in Math class. I would like to return 1 for the first call, 2 for the second call and so on. I have done this in Mockito something like this…
Muthaiah PL
  • 1,048
  • 3
  • 15
  • 26
3
votes
2 answers

FakeItEasy assert that method call to method

I have an unit-test written with FakeItEasy v2.2.0. The test tests that a method, let call it MethodA call to MethodB. The simple class: public class Foo { public virtual void MethodA() { MethodB(); } public virtual void…
baruchiro
  • 5,088
  • 5
  • 44
  • 66
3
votes
1 answer

FakeItEasy - Is it possible to test constraints asynchronously (i.e. MatchesAsync)?

I've run into difficulty testing System.Net.Http.HttpClient with FakeItEasy. Consider this scenario: //Service that consumes HttpClient public class LoggingService { private readonly HttpClient _client; public LoggingService(HttpClient…
3
votes
1 answer

How to test for exception in Nest?

I am trying to test for the results of certain exceptions when Nest has a value in IGetResponse.OriginalException property. I first set up the response: var response = A.Fake>>(); A.CallTo(() =>…
Sailing Judo
  • 11,083
  • 20
  • 66
  • 97
3
votes
2 answers

Faking an enumerator in FakeItEasy

How can I create a fake with FakeItEasy that allows different return values on successive calls. This is one example of what I would like to be able to do: var enumerator = A.Fake(); A.CallTo(() =>…
hcanber
  • 215
  • 3
  • 9
3
votes
1 answer

How to use FakeItEasy to verify FindOneAndUpdateAsync method ran Against faked MongoCollection?

I am using the FakeItEasy library for unit testing and trying to write a unit test for a mongo update statement and verify that the FindOneAndUpdateAsync method was called using MustHaveHappened(). I have created a unit test that will fake the…
J_Xlin
  • 73
  • 1
  • 10
3
votes
1 answer

Called method name inside FakeItEasy.Invokes()

FakeItEasy is amazing. A big "thank you" to all the contributors. Having said that, I ran across a use case where I would like to know from inside the lambda configured with Invokes what method of the faked object was actually invoked, without…
Optimax
  • 1,534
  • 2
  • 16
  • 23
3
votes
1 answer

Mocking a method which inside another method using FakeItEasy

I wish to mock a "B" method that is called inside the method "A" Here is an example In the below example I want MapPath to always return some "text" whenever it's being called. Both are in different classes public class TestTest { …
Shan
  • 2,822
  • 9
  • 40
  • 61
3
votes
1 answer

FakeItEasy - faking assignment

I have Some code where I have a fake configuration root. I would like to check that a call is made to set a config value. var fakeConfigRoot = A.Fake(); //Do something that will set config item //A call to set the config must…
milo.farrell
  • 662
  • 6
  • 19
3
votes
1 answer

Fake it easy with actions - Says it can't find call but shows it in list

I'm using fake it easy like so : var callBackAction = A.Fake>(); //act token.RegisterChangeCallback(callBackAction, "hi"); //assert A.CallTo(() => callBackAction.Invoke(A.Ignored)).MustHaveHappened(); and I'm getting the…
milo.farrell
  • 662
  • 6
  • 19