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

FakeItEasy setting property with no get accessor?

I'm trying to use FakeItEasy 2.0.0 to fake a property in a simple interface: public interface IPerson { int Age { set; } } Note that I don't have a get accessor. The test I'm trying to write is: public void SetsAge() { var fakePerson =…
WalderFrey
  • 575
  • 2
  • 17
2
votes
1 answer

FakeItEasy: Fake a call to a generic method without specifying the type

I have a type that relies on an external component that executes queries through a generic method. Here's a simplified version of what's in play: public class UnitUnderTest { private IQueryEngine _engine; public UnitUnderTest(IQueryEngine…
Dan
  • 901
  • 11
  • 25
2
votes
2 answers

FakeItEasy - Retrieve Faked object

Is there any way to retrieve the fake objects which were inserted into a faked class? E.g. Let's say I have the following interface + class; public interface IFakeable { void FakeYou(); } public class SomeClass { private readonly…
Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118
2
votes
2 answers

FakeItEasy failed assertion with randomly param (and there is a match in the calls)

I'm trying to implement a unit test with a methodcall assertion. (MustHaveHappened) I'm using the following code: [Fact] public void Should_set_setting_and_map_new_value_for_non_existing_setting() { //Arrange …
Tim
  • 939
  • 1
  • 7
  • 13
2
votes
1 answer

Should I care about the number of calls to a mocked object

The title is self explanatory but I'll elaborate. I'm using FakeItEasy framework where I have the option to check the number of times a method have been invoked. A.CallTo(() => foo.Bar()).MustHaveHappened(); But by doing this I'm testing the…
Tsahi
  • 445
  • 4
  • 22
2
votes
1 answer

how to write unit tests for Routes (RouteConfig.cs) using FakeItEasy

I am trying to write unit tests for RouteConfig.cs files to evaluate the routes. For example, "~/" should map to default action and default controllers, and like that. I am using xUnit and FakeItEasy in my project. Earlier, I could achieve it using…
Nirman
  • 6,715
  • 19
  • 72
  • 139
2
votes
1 answer

FakeItEasy - faking setter behaviour to store a value and then getter

Ultimately I want to have an internal interface with a setter and a public one with a getter. The code that replicates this scenario is roughed below: [TestMethod] public void TestMethod3() { var fake1 = A.Fake(a =>…
johnildergleidisson
  • 2,087
  • 3
  • 30
  • 50
2
votes
2 answers

Inconsistent behaviour on a fake(interface vs abstract class) using fakeiteasy

I had following code public interface IFoo { void Execute(); } public abstract class FooBar: IFoo { public void Execute() { OnExecute(); } public abstract void OnExecute(); } and following test case to test the…
resp78
  • 1,414
  • 16
  • 37
2
votes
1 answer

How to specify the class to use when faking a property?

I find that I am often faking IDbSet from Entity Framework. I typically have an interface like this: public interface IContext : IDisposable { IDbSet Cats { get; set; } IDbSet Dogs { get; set; } } Which I fake like…
Buh Buh
  • 7,443
  • 1
  • 34
  • 61
2
votes
1 answer

FakeItEasy - How to have an interface fake inherit from abstract?

I have an interface interface IInterface {} An abstract class abstract class AbstractClass : IInterface { } Concrete class class Irrelevant { Irrelevant (IInterface service) {} } I'm writing a unit test against Irrelevant and the abstract class…
johnildergleidisson
  • 2,087
  • 3
  • 30
  • 50
2
votes
1 answer

C# FakeItEasy and Method Chaining: Only First Call Is Recognized

I have a call to a factory interface that creates an IMachine in a command handler. This returned IMachine from the factory has methods that can be chained together to create itself inside of a builder class. The problem I am running into with…
jmzagorski
  • 1,135
  • 18
  • 42
2
votes
1 answer

FakeItEasy Setup object is not returning in test method

I am testing a method with FakeItEasy fake object. Fake object is a MemoryStream. [TestFixture] public class ServerClientTests { private IWebClient webClient; private ServerClient serverClient; [SetUp] public void Setup() { …
barteloma
  • 6,403
  • 14
  • 79
  • 173
2
votes
1 answer

FakeItEasy How to raise event, type delegate

namespace Elektrobit.Guide.Studio.Model.Elements { public delegate void ModifiedChangedHandler(); public interface IProject : IModelElement { event ModifiedChangedHandler ModifieChanged; } } I need to raise this event using…
Vitaliy Litvinov
  • 298
  • 4
  • 13
2
votes
1 answer

Errors mocking TreeView in FakeItEasy

Using FakeItEasy and xBehave.net, I'm trying to mock a System.Windows.Forms.TreeView. I get the following error: FakeItEasy.Core.FakeCreationException : Failed to create fake of type "System.Windows.Forms.TreeView". Below is a list of reasons for…
Vimes
  • 10,577
  • 17
  • 66
  • 86
2
votes
1 answer

Winrt Testproject using FakeItEasy

I've created a Testproject for my Windows 8.1 Class Library. In the TestInitialize function a like to fake a Service. A.Fake(); But I get this exception: The type initializer for 'FakeItEasy.Core.FakeScope' threw an exception. "Could not…
Dani
  • 971
  • 12
  • 31