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

C# - Set URL of request of controller for unit tests

I am writing a unit test where I need to set the URL of the incoming request in order evaluate the URL inside the controller's method. I am using FakeItEasy and NUnit3. Here is the code under test and the relevant part: [HttpPost] public async…
mgtb
  • 27
  • 7
1
vote
1 answer

FakeItEasy ControllerTest HttpGet Calls

I want to start using FakeItEasy for testing queries. The tests I want to write should check if entities are returned on HttpGet calls (get all and get by Id) The Controller: public class ToDoController : ControllerBase { private readonly…
BHANG
  • 354
  • 1
  • 5
  • 16
1
vote
1 answer

WithArgumentsForConstructor with A.That.Contains

I would like to test if execution invokes a method with string that contains given part AND an instantiation of class that contains (on it's constructor) part of given string. [TestMethod] public void TestMethod1() { // Arrange var…
fiskolin
  • 1,421
  • 2
  • 17
  • 36
1
vote
1 answer

FakeItEasy - Expected to find it once or more but no calls were made to the fake object

I have an event creation method that should return me an object EventoDto, I'm using fakeiteasy and create the object with values because have a problems with the validations, now this is my code. HOw I should make this test? [Fact] public async…
CoolLife
  • 1,419
  • 4
  • 17
  • 43
1
vote
1 answer

Injecting a fake concrete class via FakeItEasy and AutoFixture

I've got a class I want to test where a concrete class (MyClient) is being injected. private readonly MyClient _client; public Sync(MyClient client) { _client = client; } For testing we're using xUnit, AutoFixture and FakeItEasy. This all…
Jan_V
  • 4,244
  • 1
  • 40
  • 64
1
vote
2 answers

Faking an Extension Method in a 3rd Party Library

Have I written an untestable method? As the library I am using has an important method which is implemented as an extension method, it seems like I am unable to fake it. And thus, unable to test my method. First, I'll set out a truncated version of…
onefootswill
  • 3,707
  • 6
  • 47
  • 101
1
vote
1 answer

Change mocked function parameter value with FakeItEasy?

I am looking for a way to change the value of a Parameter for a Mock function with FakeItEasy. I have something like: var objParam = new ObjParam(); objParam.SomeIntValue = 0; A.CallTo(() =>…
Kiroul
  • 465
  • 2
  • 9
1
vote
1 answer

Raising events with FakeItEasy in VB.Net to verify that event handler is wired properly

I am attempting to test that the event handlers between an interface and controller are wired properly. The system is set up like the example below: 'Interface for Display Public Interface IClientLocationView Event…
user728033
  • 13
  • 2
1
vote
1 answer

Can't get right parameters right in my A.CallTo FakeItEasy method

I'm trying to create a simple test to check if the search method to the elasticsearch client has been called. public async Task> MySearch(string term) { var searchResponse = _elasticClient.Search(s…
NorwegianClassic
  • 935
  • 8
  • 26
1
vote
1 answer

A.CallTo method that uses expression as a parameter

I'm trying to do something like this, and it doesn't work, although it kinda should be A.CallTo(() => partyRepo.Where(o => o.Person != null)) .Returns(new[] {new Party()}); the call to this method with this exact code as a…
Omu
  • 69,856
  • 92
  • 277
  • 407
1
vote
0 answers

How to Mock or Fake MongoDB 's static method FindAsync() in .Net Unit test cases using MOQ or FakeItEasy or Pose

I have been trying to mock/fake the static method FindAsync() in my Unit test cases using Wrappers, some concepts of Pose. As the static methods cannot be mocked or faked normally. It is not successful. The code in the repository layer which I…
Te Jas
  • 45
  • 9
1
vote
1 answer

FakeItEasy faking abstract class with custom attributes with parameters in constructor throws ArgumentException

I am getting following exception: System.ArgumentException: 'Only constant and single-dimensional array expressions are supported' While trying to fake some abstact object with additional attribute that takes parameters in constructor. var foo =…
zajer
  • 649
  • 6
  • 17
1
vote
1 answer

Unit test multiple calls that "MustHaveHappenedOnceExactly"

I want to verify that the method I test calls a service multiple times with different arguments. The service method has a required and a optional argument: public void Foo(object o1, object[] o2 = null); I am expecting Foo to get called 2 times,…
user2900970
  • 751
  • 1
  • 5
  • 24
1
vote
1 answer

FakeItEasy returning the wrong return

In the code below, I have the "howmanystringasync" method which is calling two others methods. Those two are faked. The second fake's return does not work because of the ".ToList()". I usually returns IEnumerable because in some case I want to…
olleo
  • 378
  • 3
  • 14
1
vote
1 answer

How to pass more than 4 arguments to FakeItEasy Invokes()?

I am trying to convert a helper method I wrote mocking ILogger using Moq to FakeItEasy. The Log() method mocked in the ILogger requires 5 arguments. Log(LogLevel, EventId, FormattedLogValues, Exception, Func) It appears…
Sailing Judo
  • 11,083
  • 20
  • 66
  • 97