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
53
votes
4 answers

Are fakes better than Mocks?

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 better for particular uses? EDIT: What is it…
Francisco Noriega
  • 13,725
  • 11
  • 47
  • 72
32
votes
2 answers

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 { public Data (string name, string data) { //…
Stécy
  • 11,951
  • 16
  • 64
  • 89
28
votes
1 answer

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
  • 6,338
  • 3
  • 41
  • 57
22
votes
1 answer

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…
jdscolam
  • 988
  • 8
  • 20
16
votes
2 answers

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
  • 6,419
  • 11
  • 54
  • 89
15
votes
1 answer

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 { int Foo(); } Can I fake a dependency…
Rokey Ge
  • 681
  • 8
  • 18
15
votes
1 answer

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 message); } the test: var player1 =…
Omu
  • 69,856
  • 92
  • 277
  • 407
14
votes
1 answer

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 test: var myObject = A.Fake(); int…
Stécy
  • 11,951
  • 16
  • 64
  • 89
14
votes
2 answers

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
  • 17,233
  • 9
  • 65
  • 88
14
votes
3 answers

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: - Sealed methods can not be intercepted. The method under…
EF0
  • 2,940
  • 4
  • 17
  • 23
14
votes
3 answers

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 OptionsPresenter(view, …
m_collard
  • 2,008
  • 4
  • 29
  • 51
13
votes
2 answers

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, but i found no satisfactory way to do this with…
Olsenius
  • 313
  • 1
  • 2
  • 7
11
votes
5 answers

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 (_httpClient == null) { _httpClient = new…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
10
votes
3 answers

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.Ignored,A.Ignored,null)).Returns(""); but I get this error: System.NullReferenceException : Object…
Omu
  • 69,856
  • 92
  • 277
  • 407
10
votes
4 answers

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 (fakes) I'm using FakeItEasy. I figured there…
David Nordvall
  • 12,404
  • 6
  • 32
  • 52
1
2 3
23 24