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

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(); A.CallTo(() => client.GetUserProfile(userName)).Returns(null); The method GetUserProfile…
Ranjit
  • 107
  • 1
  • 6
9
votes
2 answers

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(); What I want to do, is intercept the Write method so that…
marco-fiset
  • 1,933
  • 1
  • 19
  • 31
8
votes
1 answer

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 and not an expression. But the compiler throws an…
cmart
  • 991
  • 3
  • 11
  • 19
8
votes
2 answers

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 figured out how to do it in FakeItEasy. FakeItEasy…
Cork
  • 722
  • 6
  • 20
7
votes
2 answers

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 subscribes to that event. Thanks!
Shay Friedman
  • 4,808
  • 5
  • 35
  • 51
7
votes
2 answers

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 circumstances (without throwing exceptions) we could…
xeraphim
  • 4,375
  • 9
  • 54
  • 102
7
votes
1 answer

how to It.IsAny in FakeItEasy?

Does anyone know the equivalent of Moq It.IsAny 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.Ignored)).MustHaveHappened(); but this also accepts…
Omu
  • 69,856
  • 92
  • 277
  • 407
7
votes
3 answers

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 specific DeliveryAddress is being added to the…
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
7
votes
2 answers

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 the following but the syntax doesn't…
Kevin Westwood
  • 7,739
  • 8
  • 38
  • 52
7
votes
1 answer

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 refactoring friendly! // The constructor seen here is…
user152949
7
votes
1 answer

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 fakes of an interface type. Therefore I'm doing…
Marco
  • 4,817
  • 5
  • 34
  • 75
7
votes
2 answers

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(); var myMonkey = new Monkey(); …
Josh Noe
  • 2,664
  • 2
  • 35
  • 37
7
votes
1 answer

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, // will create a new order and return an OrderDto…
Bob Tabor
  • 967
  • 1
  • 13
  • 23
6
votes
4 answers

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 - does not have the construcotr (and it's…
KVN
  • 863
  • 1
  • 17
  • 35
6
votes
1 answer

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() A.CallTo(fun () ->…
FSharpOrBust
  • 115
  • 3
1
2
3
23 24