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

C# Raising Events with custom delegate type on fake object with fakeiteasy

According to the documentation of fakeiteasy all I have to do is: public delegate void CustomEventHandler(object sender, CustomEventArgs e); event CustomEventHandler CustomEvent; fake.CustomEvent += Raise.With(fake,…
janhamburg
  • 25
  • 7
0
votes
2 answers

FakeItEasy - capture exception to assert message

I have the following test: [Test] public void Save_WhenExceptionIsThrown_ThenExceptionIsLogged() { A.CallTo(() => this.personRepository.Save(A._)).Throws(new Exception("Expected Exception")); var personen =…
xeraphim
  • 4,375
  • 9
  • 54
  • 102
0
votes
1 answer

Should my MVC Controller tests return Objects from the database? Am I doing something wrong?

I am testing some MVC Controllers. I am relatively new to this particular method of testing. When I mock the controller and method properties, then execute the method, the method returns . So either it is supposed to do that or I am not…
jward01
  • 750
  • 4
  • 11
  • 26
0
votes
1 answer

How to mock Request.IsAjaxRequest() to true using FakeItEasy?

Following is the code snippet for which I want to write unit tests: [HttpGet] public ActionResult Edit(string id) { if (Request.IsAjaxRequest()) { EditModel model = new EditModel(); ..... } return View(); } I…
Nirman
  • 6,715
  • 19
  • 72
  • 139
0
votes
1 answer

FakeItEasy error: No calls were made to the fake object

I have a small class which has a small method which gets invoked when the event is raised. public class DemoUI { public DemoUI(TestRunner runner) { runner.UserMessage += OnEventRunThis; } protected void OnEventRunThis(object…
NotAgain
  • 1,927
  • 3
  • 26
  • 42
0
votes
2 answers

C# mock not working in actual code

I currently have the following method with code: public bool SendMail(ref MailData data) SmtpClient smtpClient = this.smtpClient; Console.WriteLine("SMTP CLIENT: " + smtpClient.ToString()); Console.WriteLine("SMTP PORT: " +…
gigha
  • 41
  • 1
  • 10
0
votes
1 answer

How can I fake a Class used insite SUT using FakeItEasy

Am having a little trouble understanding what and what cannot be done using FakeItEasy. Suppose I have a class public class ToBeTested{ public bool MethodToBeTested(){ SomeDependentClass dependentClass = new SomeDependentClass(); var…
Karthik Balasubramanian
  • 1,127
  • 4
  • 13
  • 36
0
votes
1 answer

FakeitEasy return null object

I made a repository class to access my DB and then I made a unit test using the FakeItEasy library. Using a real repository I got the expected result, while using the fake repository returns null. [TestClass] public class clientRepositoryTest { …
Joy
  • 1,707
  • 7
  • 29
  • 44
0
votes
1 answer

fakeiteasy initializing private members in constructor

I want to test methods in my controller, I know about this... myController = new MyController(); A.CallTo(()=>myController.SomeMethodIWantToTest().Returns(someValueIAmTesting); The problem is that inside that parameterless constructor, I call…
0
votes
1 answer

FakeItEasy expectation fail against HashSet comparisons

I am using Xamarin Studio 5.2 on Mac OS X 10.9.4 with NUnit 2.6.3 and FakeItEasy 1.23.0. When I run tests for this code: using System; using ValueSet = System.Collections.Generic.HashSet; using NUnit.Framework; using FakeItEasy; namespace…
Tron Thomas
  • 871
  • 7
  • 20
0
votes
1 answer

How can I fake a DbSet using FakeItEasy when the classes are internal?

I'm using Entity Framework 6 and want to unit test some of my business logic code. Following Microsoft's example on how to do this, they provide the following example using MOQ: var mockSet = new Mock>(); var mockContext = new…
Tim Long
  • 13,508
  • 19
  • 79
  • 147
0
votes
1 answer

Can I use FakeItEasy to fake Properties.Settings.Default properties?

I am trying to do something similar to A.CallTo(() => MyProject.Properties.Settings.Default.SomeProperty).Returns("Hello, World! ;-)");, but I do get… Non virtual methods can not be intercepted. … in return. Any ideas?
Ali
  • 1,396
  • 14
  • 37
0
votes
1 answer

How to fake ValidationContext using FakeItEasy?

I have one class which is derived from ValidationAttribute (of DataAnnotation in MVC) Following is the overridden method of this class: protected override ValidationResult IsValid(object value, ValidationContext validationContext) { …
Nirman
  • 6,715
  • 19
  • 72
  • 139
0
votes
0 answers

Fake DbQuery with FakeitEasy

i was reading this How to make Entity Framework Data Context Readonly because I have a read-only context that uses SQL views as entities. Is it possible to fake DbQuery so I can test my other logic? FakeItEasy returns these errors: var…
jmzagorski
  • 1,135
  • 18
  • 42
0
votes
1 answer

ComponentNotRegisteredException when trying to resolve from a Fake IContainer

I'm trying to test out a part of my program that resolves instances of types. To do this I created a fake IContainer: this.container = A.Fake(); However, when I reach this line of code: container.Resolve(); It's throwing a…
xofz
  • 5,600
  • 6
  • 45
  • 63
1 2 3
23
24