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
1
vote
1 answer

need to unit test a controller's ActionMethod that is returning a RedirectResult along with an anchor tag

Here is the controller's return statement: var url = Url.Action("method", "controller", new { id = id }) + "#anchor-tag"; return new RedirectResult(url); So, in my test method, I need to assign the Controller's (sut) UrlHelper so I don't get a null…
Michael McCarthy
  • 1,502
  • 3
  • 18
  • 45
1
vote
1 answer

Faking a INI Configuration File Settings with FakeItEasy in C#

I have a class that inherits from the abstract Configuration class, and then each class implements the reader for INI files, XML, conf, or proprietary formats. I am having a problem in creating the objects to be tested using FakeItEasy. The object…
Steven Scott
  • 10,234
  • 9
  • 69
  • 117
1
vote
2 answers

Fake It Easy - A.Ignored() with string - A.Ignored()

I've a method with a string parameter and a bool return value. I want to ensure that it always returns true I tried myClass.Foo(A.Ignored) .WithReturnType() .Returns(true); Now I get the following…
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
1
vote
1 answer

FakeItEasy CallsBaseMethod Nested Fake CallTo isn't called

I'm trying to mix CallsBaseMethod and CallTo and it's not calling the one I have setup. Please see the code below and my comments. Is there a way to get this to work or a different approach with FakeItEasy? public LayoutManager(ICompanyManager…
AlignedDev
  • 8,102
  • 9
  • 56
  • 91
1
vote
1 answer

Warnings when using Fake.InitializeFixture

I'm using Fake.InitializeFixture like this: [Fake] private ISomeDependency _someDependency; [UnderTest] private SomethingToTest _somethingToTest; [SetUp] public void SetUp() { Fake.InitializeFixture(this); } ... It works fine when running the…
Allrameest
  • 4,364
  • 2
  • 34
  • 50
1
vote
2 answers

How fake System.Security.Principal.IIdentity using FakeItEasy?

In my app users loging in via WIF. User's credentials is stored in System.Security.Principal.IIdentity. Now i want to test CreateUser() method. I have to in some way fake that object. I try to do something like this: -extract method which returns…
Kamil Będkowski
  • 1,092
  • 4
  • 16
  • 36
0
votes
2 answers

Test using fake if a method logs an error when an exception is thrown within that method

enter code hereI have a method that logs errors when an exception is thrown within that method. The method is non-static inside a singleton. public object MethodA() { try { //code …
Tech Xie
  • 927
  • 4
  • 12
  • 24
0
votes
1 answer

How do you stub out calls to get properties?

Consider the following interface... public interface MyInterface { bool MyProperty { get; } } I am attempting to stub out a call to the get function of this property in fakeiteasy. [Test] public void Foo() { var fake =…
Jesse Webb
  • 43,135
  • 27
  • 106
  • 143
0
votes
0 answers

How to fake a static function using FakeItEasy

I have the function like this : public class myClass { public static string myFunction() { return "returnValue"; } } I want to fake myClass() using FakeItEasy. And I wrote: var fakeMyClass = A.Fake(); A.CallTo(() =>…
bobo
  • 1
  • 1
0
votes
0 answers

FakeItEasy - how to mock service that is not used directly in test

I have a .NET 6 app and I am creating integration tests for this system. I use FakeItEasy and I have a problem with mocking a service which is not used directly in my test. The process looks like this: Prepare data for the test Send first command -…
0
votes
0 answers

Hangfire Background job to requeue failed jobs unit test

I have created a Hangfire Background job that triggers the failed job as per some CRON schedule. I am facing issues to write Unit test case for the same, specially in mocking for 1st 2 lines. Framework used: xUnit, FakeItEasy var monitor =…
Sharad
  • 435
  • 1
  • 5
  • 18
0
votes
0 answers

Faking a service does not work. It calls the actual implementation of the service instead

I am faking a service using FakeItEasy string phone = "123456"; var response = new VerifyResponse(); var fakeVerifyService = A.Fake(); var verifyCall = A.CallTo(() => fakeVerifyService.Verify( A._, …
Isaac Ikusika
  • 116
  • 1
  • 1
  • 8
0
votes
0 answers

Autofac mocking doesn't work with .Include(...)

I'm trying to do some unit tests that include some Linq to Entities queries. I've recently added .AsNoTracking() and possibly .Includes(x => x.table) to the queries and now they start failing. I've fixed the .AsNoTracking() issue by adding…
Dries
  • 995
  • 2
  • 16
  • 45
0
votes
1 answer

Mocking an AWS ScheduledEvent class using C# .NET

I am trying to verify that data coming in the Detail property of an AWS ScheduledEvent object is correct. The information should be coming in from EventBridge with JSON in the Detail property that matches this class: public class EventBatchData { …
0
votes
1 answer

Using FakeItEasy to fake an AsyncPageable

I've run into a problem while testing an Azure Function which runs on top of Azure Tables: How can I fake the result of a table query which returns an AsyncPageable? Here's the code under test... public async Task GetProjectByIdAsync(Guid…
awj
  • 7,482
  • 10
  • 66
  • 120