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
1
vote
1 answer

How to make FakeItEasy capture full argument state?

I have a piece of code like this (simplified): await realApiClient.DoSomething(entity); entity.Email = newEmail; await realApiClient.DoSomethingElse(entity); In my test I have created a fake and want to check that both DoSomething and…
JustAMartin
  • 13,165
  • 18
  • 99
  • 183
1
vote
0 answers

Inexplicable random "000000" Guid values in fake method - FakeItEasy in .Net 6

So I have this fake object definition, that has a fake method in it : // Note: This is a simplified version of my code. // If it turns out that such issues could come from complex method prototypes, // then I'll post the full…
jeancallisti
  • 1,046
  • 1
  • 11
  • 21
1
vote
1 answer

FakeItEasy - Invokes with option member arguments in F#

When attempting to supply a fake delegate for a method with an optional parameter in a faked object type MyType () = abstract B: ?s:string -> unit default x.B (?s: string) = Option.iter (printfn "Implemented: %s") s [] let doit…
OrdinaryOrange
  • 2,420
  • 1
  • 16
  • 25
1
vote
1 answer

Mock repository that depends on DBContext using FakeItEasy

I'm developing an application with .NET Core and EF. I'm trying to implement some unit test using FakeItEasy and NUnit. Here's my problem. I've a DbContext as this one: public class PostgresDbContext : IdentityDbContext, int>…
Miguel Andrade
  • 346
  • 3
  • 13
1
vote
2 answers

Unit testing with FakeItEasy against nested Entity Framework member

We are trying to unit test code that relies on the Entity Framework 4.1. I've seen several posts that implement unit testing against POCOs, but we would like to retain the default EF plumbing, so that we can easily use the EF Caching…
1
vote
1 answer

Fake Xrm Easy: How to emulate a plugin's behaviour on orgService.Create()?

Microsoft Dynamics CRM 2015. I test Asp.Net Core controller's action. When I create new Lead record some plugin generates new Guid for lead.new_master_id field (it's type is string). Therefore after creating I retrive the record to get it's…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
1
vote
1 answer

How to use A.CallTo with context.T.AddAsync

In my test method, I want to test context.T.AddAsync method and Its output. Below is the code for the method. var addRequest = await _context.AddAsync(requestEntity, cancellationToken); if (addRequest.State ==…
Ayesh Nipun
  • 568
  • 12
  • 28
1
vote
1 answer

Call to FakeItEasy mocked mediatr.send method fails assertion

I am new to FakeItEasy and I am having a problem asserting if an async method has been called. It fails assertion because it hasn't been called. I have done my best to ensure the assertion matches the configured call but still no dice. …
idflyfish
  • 43
  • 3
1
vote
1 answer

FakeItEasy - I cannot see if a protected method was called when the caller method is protected overriden

I'm new to FakeItEasy, sorry if the solution is obvious. This is the simplified code which reproduces the problem: I have a base class: public abstract class BaseClass { public void Do() { Do_Override(); } …
cdi
  • 33
  • 5
1
vote
1 answer

Mocking with FakeItEasy and DBContext does not work

Why is this test code not working? Methode CheckDbAsync() in test-Class: public async Task CheckDbAsync() { return await DbContext .GetDatabase() .CanConnectAsync(default); } Testcode with…
Jens B
  • 121
  • 1
  • 6
1
vote
1 answer

Faking a generic method call in C# is not returning the correct object with FakeItEasy

I have this method I need to test public async Task Completed(string nprUserId, [FromBody] DateRangeDto model) { var result = await _geAppService.Completed(nprUserId, model.StartDate, model.EndDate); …
Zinov
  • 3,817
  • 5
  • 36
  • 70
1
vote
0 answers

FakeItEasy: How check if param is changed when method is calling?

I have following service method public async Task> QueryAsync(Context context, string schemaIdOrName, Q q) { Guard.NotNull(context, nameof(context)); if (q == null) { …
Stefan Hansch
  • 1,550
  • 4
  • 22
  • 55
1
vote
1 answer

FakeItEasy Returning Func with origin arguments in C#

I try to run some tests with FakeItEasy and my purpose is to replace one method by another for a different return value. The tricky thing for me is to redirect the origin call argument to the replace method. Invokes works fine but dont change the…
1
vote
1 answer

How to mock a service with FakeItEasy?

I have a simple entity framework repository that is accessed via a service call (please refer to this UML diagram to see the relevant classes). I am trying to test the service as follows public class ProductServiceTests { private IProductService…
user13411021
1
vote
1 answer

Unit testing: verifying a method was called, with an object created inside the tested method as parameter

Description of the problem A method to be tested creates objects of some type, let's call it Item. It initialises these objects' properties with data passed into it. This method calls another method, which takes an Item as a parameter. How can it be…
Al2110
  • 566
  • 9
  • 25