Questions tagged [fakeiteasy]

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

fakeiteasy
Filter by
Sorted by
Tagged with
54 votes
4 answers
17k views

Are fakes better than Mocks? [closed]

I stumbled upon this open source project Fake It Easy, and I have to admit, it looks very interesting, however I have my doubts, what are the difference between FIE fakes and say Moq Mocks? Is any one ...
Francisco Noriega's user avatar
33 votes
2 answers
10k views

How to get access to parameters value in Returns() using FakeItEasy?

I have an interface to a factory used to create some data objects. interface IFactory { IData Create (string name, string data); } interface IData { // .... } class Data : IData { ...
Stécy's user avatar
  • 12.2k
29 votes
1 answer
7k views

Out and Ref parameters with FakeItEasy

I have a method that has an out parameter that returns a number of records. I would like to know how to mock it with FakeItEasy.
Charles Ouellet's user avatar
23 votes
1 answer
7k views

The specified object is not recognized as a fake object. Issue

I am having an issue where a FakeItEasy call in an extremely simple test is failing with the error "The specified object is not recognized as a fake object." The call is simple: A.CallTo(myService....
jdscolam's user avatar
  • 998
16 votes
2 answers
4k views

What is a Dummy used for in FakeItEasy?

What is Dummy used for in FakeItEasy? How does it differ from A.Fake or A.Ignored ? Thanks :-)
schmoopy's user avatar
  • 6,529
15 votes
1 answer
8k views

Fake generic method with FakeItEasy without specifying type

I wonder if there is anyway one can fake up a generic method call, for all possible types (or specified sub-types)? For example, suppose we have this wonderful IBar interface. public interface IBar {...
Rokey Ge's user avatar
  • 681
15 votes
1 answer
9k views

how to verify that a method was called with an argument of a specific type

I need to verify that a method was called with an object of a specific type this is the interface with the method that I want to test that it was called: interface IPlayer { void Send(object ...
Omu's user avatar
  • 70.5k
14 votes
2 answers
6k views

How to mock protected virtual members in FakeItEasy?

Moq allows mocking protected virtual members (see here). Is it possible to do the same in FakeItEasy?
Daniel Rose's user avatar
  • 17.4k
14 votes
3 answers
13k views

Why does FakeItEasy throw this exception, and why does making the method virtual fix it?

I have a test (code is below) to test that Method1 calls Method2. The exception I'm getting is The current proxy generator can not intercept the specified method for the following reason: - ...
EF0's user avatar
  • 2,950
14 votes
3 answers
11k views

How to test for exceptions thrown using xUnit, SubSpec and FakeItEasy

I’m using xUnit, SubSpec and FakeItEasy for my unit tests. I’ve so far created some positive unit tests like the following: "Given a Options presenter" .Context(() => presenter = new ...
m_collard's user avatar
  • 2,028
14 votes
1 answer
11k views

Using FakeItEasy, how to get the value set on a property on a fake?

Using FakeItEasy, I am trying to capture the setting of a property value on a fake object: First the interface: interface ISomeInterface { int MyProperty {get;set;} } Then a fragment of unit ...
Stécy's user avatar
  • 12.2k
13 votes
2 answers
18k views

Getting arguments passed to a FakeItEasy-mock without using magic strings?

I have been using Moq for my mocking needs the last years, but after looking at FakeItEasy i wanted to give it a try. I often want to test that a method have been called with the correct parameters, ...
Olsenius's user avatar
  • 313
11 votes
5 answers
9k views

How can I use FakeItEasy with HttpClient, in a unit test?

I'm trying to figure out how to use FakeItEasy with the HttpClient, given the following code: public Foo(string key, HttpClient httpClient = null) { .. } public void DoGet() { .... if (...
Pure.Krome's user avatar
  • 85.8k
10 votes
4 answers
5k views

Faking/mocking an interface gives "no default constructor" error, how can that be?

I'm trying to write a unit test of a repository implementation. The repository uses RavenDB as a database. For the unit tests, I would like to mock the RavenDB parts. In order to create the mocks (...
David Nordvall's user avatar
10 votes
3 answers
10k views

is it possible to mock/fake an extension method?

I'm using a controller extension, and I tried to mock it using FakeItEasy (v 1.7.4) like this: A.CallTo(() => controller.RenderView(A<string>.Ignored,A<object>.Ignored,null)).Returns(""...
Omu's user avatar
  • 70.5k
9 votes
3 answers
6k views

How to Return Null value from method using FakeItEasy

I have a service faked using FakeitEasy and i am trying to call its method. Here is the Code var client = container.Resolve<MyService>(); A.CallTo(() => client.GetUserProfile(...
Ranjit's user avatar
  • 107
9 votes
2 answers
3k views

FakeItEasy - Is it possible to intercept a method and replace it with my own implementation?

I have the following interface : public interface IOuputDestination { void Write(String s); } In my unit test, I mock it like so : var outputDestination = A.Fake<IOutputDestination>(); ...
marco-fiset's user avatar
  • 1,933
8 votes
2 answers
5k views

Return different objects from FakeItEasy A.CallTo()

For my test, I need the first call to a stub to return one object, and the next call to return a different object. I have seen this in other mock object frameworks in record() blocks, but I have not ...
Cork's user avatar
  • 722
8 votes
3 answers
4k views

Test ILogger with FakeItEasy

I'm working on a fun project for myself to learn blazor, a lot of core concepts and just general practice. I'm trying to implement logger extension for FakeItEasy to easier test Microsofts ILogger. ...
JochemQuery's user avatar
  • 1,515
8 votes
1 answer
806 views

Compiler Error for Expression/Func overloads

The screenshot says it pretty much. I have the overloads as seen in the screenshot. When using a string as second parameter the compiler should figure out that the first argument can only be a Func ...
cmart's user avatar
  • 1,001
8 votes
2 answers
8k views

Use FakeItEasy's A.CallTo() on another method in same object

Using FakeItEasy, how do I check to see if my object's method calls another method on this same object? The Test: [TestMethod] public void EatBanana_CallsWillEat() { var banana = new Banana(); ...
Josh Noe's user avatar
  • 2,719
7 votes
2 answers
4k views

FakeItEasy: Reset Fake Calls History / Ignore Call

I would like to reset a Fake Calls History or ignore a Call. The fake asserted method is called in the Init method in the tested class constructor and I want to ignore this call because it's not part ...
maxence51's user avatar
  • 1,024
7 votes
1 answer
5k views

FakeItEasy says MustHaveHappened didn't happen ... but it did

I'm trying to unit test a "service layer" / "application facade layer" method. This is the method I'm trying to unit test: // Create a new order in the database for a customer. Given a customer id, ...
Bob Tabor's user avatar
  • 987
7 votes
2 answers
5k views

FakeItEasy configure fake to throw exception and return value on the next call

We have to implement a retry-mechanism. To test the RetryProvider, I want a fake of a class to throw exceptions on the first two calls, but return a valid object on the third call. Under normal ...
xeraphim's user avatar
  • 4,495
7 votes
2 answers
2k views

How to Assert that an Event Has been Subscribed To with FakeItEasy?

I have a fake class that contains an event. My code should subscribe to that event and I want to test that. I'm using FakeItEasy with NUnit and I'm looking for a way to check that my code actually ...
Shay Friedman's user avatar
7 votes
1 answer
3k views

how to It.IsAny<T> in FakeItEasy?

Does anyone know the equivalent of Moq It.IsAny<T> in FakeItEasy ? I want to do assert that a method was called with an instance of a Type v.Do(new Foo()); I tried: A.CallTo(() => v.Do(A&...
Omu's user avatar
  • 70.5k
7 votes
3 answers
2k views

Why can't I capture a FakeItEasy expectation in a variable?

I'm using FakeItEasy to fake some Entity Framework calls, to make sure a bunch of weird legacy database tables are getting mapped properly. I need to assert that a Customer with an Invoice matching a ...
Dylan Beattie's user avatar
7 votes
2 answers
2k views

Using FakeItEasy, is there a way to fake the setter of a write only property?

Using FakeItEasy, is there a way to fake the setter of a write only property? The interface I have to work with looks something like: Interface IMyInterface { String Foo { set; } } I have tried ...
Kevin Westwood's user avatar
7 votes
3 answers
10k views

Non virtual methods can not be intercepted

I am new to FakeItEasy and try solve a problem. I have a class public class Events { public List<Events> SaveEvents() { // Call to repository and return 1(success) or -1(fail) //If the ...
user2181707's user avatar
7 votes
1 answer
3k views

WithArgumentsForConstructor() extension method calls constructor

According to the FakeItEasy tutorial here the WithArgumentsForConstructor() extension method does not call the class constructor: // Specifying arguments for constructor using expression. This is ...
user avatar
7 votes
1 answer
4k views

FakeItEasy Proxy methods calls to real implementation

I'm trying to proxy calls to a fake object to the actual implementation. The reason for this is that I want to be able to use the WasToldTo and WhenToldTo of Machine.Specifications which only works on ...
Marco's user avatar
  • 4,939
6 votes
4 answers
5k views

How to build an HttpResponseHeaders for the FakeItEasy

I'm using C# and I need to Test one of my methods that accept System.Net.Http.Headers.HttpRequestHeaders as a parameter. We're using FakeItEasy for the test. But it seems that the HttpResponseHeaders ...
KVN's user avatar
  • 913
6 votes
1 answer
335 views

Faking Return value with F# and FakeItEasy

I am trying to use FakeItEasy to mock an interface defined in C# public interface IMyInterface { int HeartbeatInterval { get; set; } } In the F# test i do let myFake = A.Fake<IMyInterface>...
FSharpOrBust's user avatar
6 votes
2 answers
5k views

How to test for a Match with FakeItEasy on a predicate call?

I have the following call in my code: var dbResults = new List<CrossReferenceRelationshipEF>(); dbResults = dateTimeFilter == null ? new List<CrossReferenceRelationshipEF>( ...
VasilisP's user avatar
  • 136
6 votes
1 answer
3k views

How to fake delegates with FakeItEasy

When i try to fake a delegate-type, i get System.InvalidCastException [TestMethod] public void TestDelegateFake() { var func = A.Fake<Func<long, object>>(); A.CallTo(() => ...
Jesper Jensen's user avatar
6 votes
2 answers
2k views

How do I raise an event in FakeItEasy for an event based on a custom delegate?

The application I am testing is full of events based on custom delegates, such as this: public delegate void NameChangedHandler(string name); public event NameChanged OnNameChanged; ... public void ...
pduncan's user avatar
  • 1,430
6 votes
1 answer
863 views

A.Fake<Stream>().Read(...) throwing InvalidOperationException

Using NUnit 2.6.4 & FakeItEasy 1.25.2 to unit test a C# code in Visual Studio 2013 Community Edition The following test fragment executes as expected [Test] public void ...
Richard Lang's user avatar
5 votes
2 answers
6k views

Any Good tutorial on FakeItEasy [closed]

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 ...
Andy's user avatar
  • 2,483
5 votes
1 answer
2k views

FakeItEasy sometimes fails to create a fake when tests are run in parallel

Unit tests that use FakeItEasy randomly fail when trying to fake a simple intefrace. It occurs in different tests occasionally and is not stable. Here is a sample interface I need to fake: public ...
Boris Modylevsky's user avatar
5 votes
1 answer
2k views

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>(ElapsedEventArgs.Empty).Now); The ...
Igal Tabachnik's user avatar
5 votes
2 answers
2k views

FakeItEasy return object that the method is called with

I want to setup my fake like this: A.CallTo(() => this.repository.Create(A<PersonModel>._)).Returns(XYZ); where XYZ is the same variable as was inserted at A<PersonModel>._ so if ...
xeraphim's user avatar
  • 4,495
5 votes
2 answers
2k views

How to test whether a Func<T> has been called using the FakeItEasy framework?

How to check whether a Func has been called using the FakeItEasy framework? Example: Func<bool> myFunc = () => true; // Unfortunately this fails: A.CallTo(myFunc.Invoke()).MustHaveHappened(...
D.R.'s user avatar
  • 20.7k
5 votes
1 answer
1k views

What is the FakeItEasy equivalent of the Moq VerifyNoOtherCalls() method

I'm currently a Moq user and I'm researching other mocking frameworks. When unit testing I frequently call _mock.VerifyNoOtherCalls() so I can be certain there are no unexpected interactions beyond ...
TheCrimsonSpace's user avatar
5 votes
1 answer
2k views

Mocking a class with private ctor and static create method and private id property

I am trying to use AutoFixture to simplify my life. How do I mock a class with non-public constructor and non-public Id and static 'Create' method? Example public class User { private User(){} ...
draptik's user avatar
  • 470
5 votes
1 answer
2k views

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 ...
rsenna's user avatar
  • 11.9k
5 votes
1 answer
2k views

Stubbing out parameters with pre-existing values in FakeItEasy

This is a bit of an odd one. I'm trying to stub a method which has out parameters, I don't care about what the parameters are so I'm ignoring the arguments. It looks like this: List<Foo> ...
James Gregory's user avatar
5 votes
1 answer
6k views

How to check that a call to any overload must have happened with FakeItEasy?

I have a method which I am testing. Given certain inputs, it should write a failure method to the logger (an ILogger). The interface has several overloads for Log(), as well as some properties (ex. a ...
Daniel Rose's user avatar
  • 17.4k
5 votes
1 answer
1k views

Faking a call to an array for a particular index raises an exception

Having the following unit test: public interface ITestMe { object[] Values { get; } } [Test] public void Test () { var sut = A.Fake<ITestMe> (); A.CallTo (() => sut.Values[0])....
Stécy's user avatar
  • 12.2k
5 votes
2 answers
1k views

Asserting a call to a public method on the same mock instance

I have the following test [Test] public void Attack_TargetWith3Damage_CausesAttackerToDeal3DamageToTarget() { var realAttacker = CreateCreature(damage: 3); var wrappedAttacker = A.Fake<...
Davy8's user avatar
  • 31.3k
5 votes
1 answer
2k views

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<Attribute>...
Akim Khalilov's user avatar

1
2 3 4 5
8