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
4
votes
1 answer

Using FakeItEasy to assert that an event was raised

I can do the following to verify if the ErrorOccurred event of my Consumer class was raised: using System; using FakeItEasy; using Microsoft.VisualStudio.TestTools.UnitTesting; public interface IService { event EventHandler…
johnildergleidisson
  • 2,087
  • 3
  • 30
  • 50
4
votes
1 answer

Error when method being tested calls IQueryable.SingleOrDefault

I'm using Entity Framework and FakeItEasy for unit testing. Have numerous unit testing methods, all of them are ok - DbSet's are being mocked, all fine. This one, in particular, fails because of concrete's method call to…
Cesar
  • 497
  • 5
  • 15
4
votes
2 answers

Mocking a method within a method with FakeItEasy

How can I mock/facke the result from a function that is called in another function? Usually Test2 would be a DataAccess method that I dont like to fetch real data. What I like my unittest to test is the business logic. This Is what I have now but…
Sturla
  • 3,446
  • 3
  • 39
  • 56
4
votes
2 answers

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

How to check whether a Func has been called using the FakeItEasy framework? Example: Func myFunc = () => true; // Unfortunately this fails: A.CallTo(myFunc.Invoke()).MustHaveHappened();
D.R.
  • 20,268
  • 21
  • 102
  • 205
4
votes
2 answers

How to fake an action<> with FakeItEasy

I'm working with the FakeItEasy library to create fakes for my unit tests. I have a ClassUnderTest on which I want to test the method MethodToTest(Data dataObject). This method is calling a method of an interface which I want to fake: public…
rhe1980
  • 1,557
  • 1
  • 15
  • 36
4
votes
2 answers

How to make a FakeItEasy faked object's method throw on first invocation and return on second?

I have a method which is invoked multiple times within a foreach loop, each time with the same parameter values. foreach (var item in myCollection) { // do some stuff with item // then... var result = _myService.Foo(aConstant,…
Jesse Webb
  • 43,135
  • 27
  • 106
  • 143
4
votes
2 answers

Disable FakeItEasy's AutoMocking

Say I have an interface public interface IDatabase { IObjectSet Table1 {get;} IObjectSet Table2 {get;} //goes on to around Table400 } So when I create an instance with FakeItEasy: var fakeDb = A.Fake(); All the…
Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
4
votes
1 answer

How to use FakeItEasy to assert a method was not called

I want to assert that nothing was dispatched, a.k.a. _dispatcher.Dispatch was not called. interface being faked/mocked: interface IDispatcher { void Dispatch(T command, Stuff stuff = null, TimeSpan?…
Scoobie
  • 1,097
  • 2
  • 12
  • 22
4
votes
1 answer

MustHaveHappened fails when called twice on the same object

Given the following class under test (and associated DTO class and interface): public class Foo { private readonly IBar _bar; public Foo(IBar bar) { _bar = bar; } public void DoStuff() { var dto = new DTO(); …
MrDustpan
  • 5,508
  • 6
  • 34
  • 39
4
votes
1 answer

Creating a fake DbDataAdapter throws FakeItEasy.Core.FakeCreationException

I set up a simple test project in Visual Studio 2010. For unit tests I use nunit 2.6.1 and for mocking FakeItEasy 1.7.4582.63 which I install via NuGet. I try to fake a DbDataAdapter using the following code: using System.Data.Common; using…
Joerg Reinhardt
  • 358
  • 4
  • 9
4
votes
1 answer

How to fake a generic method call using FakeItEasy?

I am faking an IDbConnection and I want to fake the call to QueryOne() (a Dapperextension) but I get a NullReferenceException when doing so. Here´s my code: IDbConnection myConnection = A.Fake(); A.CallTo(() =>…
3
votes
1 answer

first steps with FakeItEasy and problems with Action type

I have the following (here simplified) code which I want to test with FakeItEasy. public class ActionExecutor : IActionExecutor { public void TransactionalExecutionOf(Action action) { try { // ... …
Khh
  • 2,521
  • 1
  • 25
  • 42
3
votes
3 answers

Using Expression Trees as an argument constraint

Can I use an Expression Tree as an argument constraint in a FakeIteasy CallTo assertion? Given a method on an interface with the following signature: interface IRepository { TEntity Single(Expression>…
3
votes
1 answer

How to update a property on a parameter using FakeItEasy

I have an interface that includes a member that looks like: void ExecuteSqlCommand(string procedureName, SqlParameter[] parameters); I am using FakeItEasy to create a mock of this to pass to one of my classes. The code I am testing calls this…
Jon Lawson
  • 582
  • 1
  • 6
  • 16
3
votes
3 answers

How do I assert that a method is called only once?

[Subject(typeof(OnceADayProcessor))] public class When_processing_process_twice { private static ICanBeProcessedOnceADay ProcessedOnceADay; private Establish context = () => { OnceADayProcessor.Now = () => new DateTime(2011, 1, 1, 0, 0, 0,…
Rookian
  • 19,841
  • 28
  • 110
  • 180