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

Moq to FakeItEasy migration - How to migrate Verify()?

I'm in the process of migrating Moq tests to FakeItEasy and I have runned into a case which I don't know how to migrate. The case is: [TestMethod] public void Should_EditItem() { _itemMock.Verify( item =>…
AfroMogli
  • 577
  • 5
  • 18
2
votes
4 answers

No default constructor error when there is a default constructor

Edit: going to expose production code on SO! Hope no one steals my secrets! I have a Controller class for communicating with a device over TCP using the Modbus protocol. I use the NModbus library. Here are the interfaces the controller class…
xofz
  • 5,600
  • 6
  • 45
  • 63
2
votes
1 answer

Unit tests failing when run altogether - API restriction: The assembly has already loaded from a different location

I've got a set on unit tests, which, if I run all together (using resharper) I get this error: SetUp : System.TypeInitializationException : The type initializer for 'FakeItEasy.Core.FakeScope' threw an exception. ----> …
Alex
  • 37,502
  • 51
  • 204
  • 332
2
votes
1 answer

Why does this MustHaveHappened call on a FakeItEasy object fail in MSpec?

When running following test all the assertions fail. Can't figure out why they fail, because the actual implementation does have a call to the objects. Is this a known bug? Because some other tests do succeed. [Subject("Pst Cleanup")] public class…
Marco
  • 4,817
  • 5
  • 34
  • 75
2
votes
2 answers

Equivalent of JustMock's ReturnsCollection() in FakeItEasy?

With JustMock I can mock DataContext tables with lists in Linq to SQL easily like this, where an IEnumerable is taking the place of each DataContext's table through ReturnsCollection() allowing me to plug in fake data: [TestMethod] public void…
frontsidebus
  • 120
  • 1
  • 9
2
votes
2 answers

Dependency injection refactoring

I have this ctor: public Section() { _tabs = new TabCollection(this); _sections = new SubSectionCollection(this); } I would like to get something like this: public Section() : this(new TabCollection(this), new…
IonutC
  • 607
  • 1
  • 6
  • 11
2
votes
1 answer

C# FakeItEasy fake method that have been overrided

I have problem with faking my class: Class A has a method: protected virtual int method(int argument) { implementation return int; } Class B extends class A and overrides the method: protected override int method(int argument) { int…
Tomasz
  • 2,051
  • 3
  • 31
  • 64
2
votes
1 answer

How to mock an interface returned as property from another mock?

I have the following interfaces: interface IManufacturing { IJobApi JobApi {get;} } interface IJobApi { IList GetSpecs (string wo, string name); } I have a class which uses IManufacturing and calls GetSpecs() like so: var specs =…
Stécy
  • 11,951
  • 16
  • 64
  • 89
2
votes
1 answer

generated service mock: everything but RhinoMocks fails?

See this code: TicketStoreService fakeTicketStoreService = MockRepository.GenerateMock(); fakeTicketStoreService.Expect(service => service.DoSomething(Arg.Is(new Guid())) …
hko
  • 923
  • 9
  • 17
1
vote
3 answers

Using Reflection Invoke static generic method passing a Lamba as parameter

Is it possible to write the following code via Reflection? var fake = A.Fake( o => o.WithArgumentsForConstructor(new[] { "Hello" })); Where o is: Action> Where WithArgumentsForConstructor…
Nikos Baxevanis
  • 10,868
  • 2
  • 46
  • 80
1
vote
1 answer

Fake class which inherits from multiple interfaces

How do you fake a class with FakeItEasy that implements multiple interfaces. e.g. A class that implements both IFoo and IBar I've tried the following but it doesn't work A.Fake(builder => builder.Implements());
EC99
  • 137
  • 10
1
vote
1 answer

How to mock EventHubProducerClient from Azure Event Hubs?

I need to write unit tests for the EventHubProducerClient class, which many instances of used in my repo. Modifying the original class is not an option. More specifically, I need to mock the CreateBatchAsync() method of the EventHubProducerClient…
1
vote
1 answer

Object reference not set to an instance of an object at ASP.NET MVC Session on Unit Testing using Fake it Easy

I have an ASP.NET MVC 4 project with a controller that calls an external WCF to authenticate user login on the VerifyAccount method. This external WCF returns an AuthModelUserVerification class back to the controller and creates a Session containing…
jdistro07
  • 123
  • 2
  • 13
1
vote
2 answers

Xunit.net: Validating model returned by an async ASP.NET method

I have been writing unit testing for the API. I need to check whether values inside the model returned by the action method are expected or not. [Fact] public async Task MerchantController_GetMGetProductByMerchantId_Merchant() { //Arrange …
1
vote
1 answer

X unit test with fakeitesay faking async methods asp.net

The return type of result and expected are different unable to fake an async method my code on x unit testing using Amazon.Controllers; using Amazon.Models; using Amazon.Repository; using FakeItEasy; using FluentAssertions; using…
akhil
  • 23
  • 4