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

Creation fake of Amazon.DynamoDBv2.DocumentModel.Search with FakeItEasy

I may doing something wrong but can't find the answer. It seems that line var searchFake = A.Fake(); should simply work. But it always gives me the error Constructor with signature () failed: No usable default constructor was found on the…
Anton Shakalo
  • 437
  • 1
  • 6
  • 23
0
votes
2 answers

How to use Fake It easy with indexed property?

I have a interface that has an indexed property that I need to mock. public interface MultipleLines { [DispId(201)] int Count { [MethodImpl(MethodImplOptions.InternalCall)] [DispId(201)] get; } …
0
votes
0 answers

AutoFakeItEasyDataAttribute populates complex objects with test data but customized fixture won't

I have a complex object several levels deep. Marking my Xunit theory with this custom attribute and passing the complex object to the method as a parameter populates all the properties with test data…
W. Young
  • 357
  • 7
  • 18
0
votes
2 answers

How to fake DbContextOptions

I'm writing a unit test for ConsumerService that uses EntityFramework Core. Below you can see my AppDBContext class, and its one and only constructor. In order to fake it, I'm required to pass DbContext into it, so, I'm trying to fake that one too.…
user21582911
0
votes
1 answer

Unable to create fake of request.Uri

I have a chunk of code that I want to test: public override async Task Invoke(IOwinContext context) { if (context.Request.Uri.AbsolutePath.ToLower().Equals("/data")) { ..other stuff } await this.Next.Invoke(context); } Now I…
Ask
  • 3,076
  • 6
  • 30
  • 63
0
votes
1 answer

How do I refactor a code implementing 'using' key word , so that I can write unit tests for the method?

So, It seems I have arrived at an impasse. I have asked to write unit test for a legacy code base in .Net however I am frequently coming across code that is implementing the 'using' statement. This is problem because I am unable to mock the…
0
votes
1 answer

FakeItEasy class containing fake method not recognized as a fake object problem

I have this code: [Fact] public async Task AnnouncerIndex_Test_1() { //Arrange var fakeContext = A.Fake(); var fakeUserManager = A.Fake< UserManager>(); var controller = new…
0
votes
1 answer

How to mock Dapper call to execute stored procedures with parameters?

I am using the following line in my code to execute the stored procedure, var parameters = new DynamicParameters(); parameters.Add("MYPARAM", field.ListPickListCode, DbType.String, ParameterDirection.Input, int.MaxValue); options =…
tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
0
votes
2 answers

How to check if a public method calls another public method using FakeItEasy

I have the following Interface & Class and I also wrote a unit test as shown down, but I got an exception: Assertion failed for the following call: AsyncConsole.example1.IPlayer.Start(i: 1) Expected to find it once or more but didn't find it among…
Mike Bluer
  • 63
  • 6
0
votes
2 answers

How to fake ASP.NET MVC UrlHelper with FakeitEasy

This is the code of my controller : private readonly ILMS_Service lms_client; private UrlHelper urlHelper; public PackagesController(ILMS_Service client, UrlHelper _urlHelper) { lms_client = client; urlHelper = _urlHelper; } public…
jdistro07
  • 123
  • 2
  • 13
0
votes
1 answer

FakeItEasy A.CollectionOfFake doesn't work

I have a simple WCF service that returns a list of PackagesModel.UnitTypeList to my ASP.NET MVC 4 controller [HttpGet] public ContentResult GetUnitType() { List _result = lms_client.GetUnitType().ToList(); return…
jdistro07
  • 123
  • 2
  • 13
0
votes
2 answers

Fake IMongoQueryable with FakeItEasy

I'm developing an API which communicates with MongoDB and I need to create some statistics from one collection. I have the following service: public class BoxService : IBoxService { private readonly IMongoCollection _boxCollection; …
cs.kali
  • 198
  • 12
0
votes
1 answer

Delegate does not take 9 arguments (FakeItEasy / C# 9.0)

C# 9.0, FakeItEasy 7.3.1 This is probably just me being dumb, but... Why does FakeItEasy complain that the delegate's parameters don't match??? I've been banged my head against the walls for hours. public interface IBaseInterface { //Not…
jeancallisti
  • 1,046
  • 1
  • 11
  • 21
0
votes
1 answer

Why is faked IMemoryCache returning default value on Get

I'm writing a unit test and therefore i need to fake an IMemoryCache. public MyUseCaseTest() { this.myCache = A.Fake(); } When i run the test and the tested method is called, the memory cache is checked if there is already an entry…
Thomas Meinhart
  • 659
  • 2
  • 7
  • 28
0
votes
1 answer

How to Unit Test a Protected Method with database connection inside a public method in C#?

I have the following scenario: public class Child : Parent { private int _eventTypeId; public override Dictionary Execute(IDynamicDatabaseConnection dbConn, IDbTransaction dbTrans) { _eventTypeId = GetEventType(dbConn,…
tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83