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

Any Good tutorial on FakeItEasy

We are considering using FakeItEasy to be our mocking framework. To conduct a workshop for the team on FakeItEasy, I am looking for a good tutorial that explains this framework in much details. I tried looking at the documentation at github, but…
Andy
  • 2,393
  • 4
  • 18
  • 20
5
votes
1 answer

Faking a generic method FakeItEasy

How would you go about faking the following: public interface IBlah { Func ApplyFilter(Func predicate) where T:IMessage; } What I would like is for the fake to simply return it's argument without any changes. However, I…
ashic
  • 6,367
  • 5
  • 33
  • 54
5
votes
1 answer

FakeItEasy deep nested types faking

I have a complex object that I'm trying to fake. interface IContext { User User { get; } } A.CallTo( () => _fakeContext.User.Subscription.Attributes) .Returns(new List()); But I get the next exception: The current proxy…
Akim Khalilov
  • 1,019
  • 4
  • 16
  • 31
5
votes
1 answer

Using FakeItEasy to have a faked method call raise an event?

I'm trying to do something along the lines of: A.CallTo(() => fakeTimer.Start()).Invokes(() => fakeTimer.Elapsed += Raise.With(ElapsedEventArgs.Empty).Now); The fakeTimer is a fake of ITimer, a wrapper interface per this…
Igal Tabachnik
  • 31,174
  • 15
  • 92
  • 157
5
votes
1 answer

Does FakeItEasy support the idea of Partial Mocks?

Similar to this question about NSubstitute, I want to know if one is able to implement partial mocks using the FakeItEasy library. FakeItEasy seems to have an overall nicer syntax than moq (like the strongly-typed way the former deals with passing…
rsenna
  • 11,775
  • 1
  • 54
  • 60
4
votes
1 answer

FakeItEasy & "params" arguments

I have a method with the following signature. Foo GetFooById( int id, params string[] children ) This method is defined on an interface named IDal. In my unit test I write the following: IDal dal = A.Fake(); Foo fooToReturn = new…
Craig W.
  • 17,838
  • 6
  • 49
  • 82
4
votes
1 answer

How to make any instance creation a fake (FakeItEasy)?

I have this block of code that I would like to test class SearchEngine { public void Search() { var module = new SearchModule(); module.Search(); } } I have simplified it but I cannot provide a searchmodule instance as a…
Gil Sand
  • 5,802
  • 5
  • 36
  • 78
4
votes
1 answer

Why can most of the mock frameworks in .NET (Core) not mock static and private methods?

My question is about the technical reason for this limitation, not about how to fix it. Why do some frameworks like Telerik JustMock and Typemock Isolator support these features, but we can not have these in Moq or FakeItEasy or NSubstitute,…
HamedFathi
  • 3,667
  • 5
  • 32
  • 72
4
votes
2 answers

FakeItEasy return object that the method is called with

I want to setup my fake like this: A.CallTo(() => this.repository.Create(A._)).Returns(XYZ); where XYZ is the same variable as was inserted at A._ so if Create is called with mySamplePersonModel I want the method to return…
xeraphim
  • 4,375
  • 9
  • 54
  • 102
4
votes
2 answers

.NET CORE Testing - Mock IHttpContextAccessor with FakeItEasy

I'm stuck on mocking the IHttpContextAccessor for some web api integration tests. My goal is to be able to mock the IHttpContextAccessor and return NameIdentifier claim and RemoteIpAddress. Test public class InsertUser : TestBase { private…
Reft
  • 2,333
  • 5
  • 36
  • 64
4
votes
1 answer

.NET core with FakeItEasy

Can FakeItEasy work with .NET core? I have installed it through NuGet but I can't reference it in the project as using FakeItEasy because it doesn't find it. I have checked under NuGet dependencies and I see it as FakeItEasy (3.3.2)
Norgul
  • 4,613
  • 13
  • 61
  • 144
4
votes
2 answers

How to mock a SOAP Service class in C#

I want to fake the getCustomerName Service call here and mock it with fake Data My class is "CustomerName" which calls a SOAPService call which returns the CustomerName for an CustomerNumber.I want to fake the SOAPService call to return some…
Shan
  • 2,822
  • 9
  • 40
  • 61
4
votes
1 answer

Fake singleton with FakeItEasy

I have some problems testing a singleton. When I run this code, I get an error in TestGetLogicalDevices(). CallTo() failed because service is no fake object. When I try to create a fake object (commented code), it gives an error because RestService…
4
votes
1 answer

FakeItEasy Property doesnt get updated

For the first time, I'm using FakeItEasy to mock a complex data structure. When mocking an object and setting a property like this, the proprety doesnt get updated. It will always be false. var @object =…
Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143
4
votes
1 answer

FakeItEasy - how to test virtual method

I am using FakeItEasy to fake class to do the following unit test. When I debug the unit test step by step, noticed that it will not step into original method -->IsOrderHasToBeCharged(). Instead, it always default the returned value as False. Is it…
CJ_
  • 69
  • 9