fakeiteasy

FakeItEasy - problems with new modifier

北城以北 提交于 2019-12-11 11:49:10
问题 It appears that the following code doesn't behave as I would expect: using FakeItEasy; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { var derived = A.Fake<IDerived>(); A.CallTo(() => derived.Dependency).Returns(null); IBase baseObj = derived; Assert.IsNull(baseObj.Dependency); //Fails } } public interface IDerived : IBase { new IDependency Dependency { get; } } public interface IBase { IDependency Dependency {

FakeItEasy: mocked method is not returning expected result

醉酒当歌 提交于 2019-12-11 09:24:22
问题 Im using FakeItEasy as mocking framework in my unit tests. Method fakeUserService.AddUser is mocked to returned new MwbeUser object with some non-empty values inside method AddUser A.CallTo(() => fakeUserService.AddUser(new MwbeUserRegistrationIn() { UserName = userName, FirstName = firstName, SecondName = secondName, Password = passwd, Email = email, BirthDate = birthdate })).Returns(new MwbeUser { UserName = userName, Email = email, FirstName = firstName, SecondName = secondName, BirthDate

Faking an enumerator in FakeItEasy

跟風遠走 提交于 2019-12-10 18:54:32
问题 How can I create a fake with FakeItEasy that allows different return values on successive calls. This is one example of what I would like to be able to do: var enumerator = A.Fake<IDictionaryEnumerator>(); A.CallTo(() => enumerator.MoveNext()).Returns(true); //Expected value for first call A.CallTo(() => enumerator.Key).Returns("key1"); A.CallTo(() => enumerator.Value).Returns("value1"); A.CallTo(() => enumerator.MoveNext()).Returns(false); //Expected value for second call Assert.IsTrue

What is the FakeItEasy equivalent of the Moq VerifyNoOtherCalls() method

一个人想着一个人 提交于 2019-12-10 18:24:39
问题 I'm currently a Moq user and I'm researching other mocking frameworks. When unit testing I frequently call _mock.VerifyNoOtherCalls() so I can be certain there are no unexpected interactions beyond the ones that I have already verified. I've searched the FakeItEasy docs and cannot find the equivalent option in their framework. Can anyone suggest how I might do this? 回答1: Strict fakes FakeItEasy supports strict fakes (similar to strict mocks in Moq): var foo = A.Fake<IFoo>(x => x.Strict());

Faking/mocking an interface gives “no default constructor” error, how can that be?

二次信任 提交于 2019-12-08 17:10:04
问题 I'm trying to write a unit test of a repository implementation. The repository uses RavenDB as a database. For the unit tests, I would like to mock the RavenDB parts. In order to create the mocks (fakes) I'm using FakeItEasy. I figured there wouldn't be any problems with the mocking/faking since the RavenDB API is accessed through interfaces. I do however have a problem when trying to instantiate a specific mock. The relevant parts of my unit test code looks like this: [Fact] public void Test

How do I test extension method of Nhibernate which does not return the value even after specifying return in fakeiteasy?

て烟熏妆下的殇ゞ 提交于 2019-12-08 04:50:31
问题 I have a class like below where using Fluent Nhibernate I am getting data from database public class MyActualClass { public MyActualClass(ISessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public List<AnnualInformation> GetData() { using (session = sessionFactory.OpenSession()) { var result = session.QueryOver<AnnualInformation>() .SelectList(list => list .Select(x => x.Id) .Select(x => x.CreationDate) .Select(x => x.AnnualAmount) .Select(x => x.AnnualCurrency) .Select(

MustHaveHappened fails when called twice on the same object

天涯浪子 提交于 2019-12-08 01:52:59
问题 Given the following class under test (and associated DTO class and interface): public class Foo { private readonly IBar _bar; public Foo(IBar bar) { _bar = bar; } public void DoStuff() { var dto = new DTO(); dto.Num = 1; _bar.Test(dto); dto.Num = 2; _bar.Test(dto); } } public class DTO { public int Num { get; set; } } public interface IBar { void Test(DTO dto); } And this test method (which attempts to verify that IBar.Test() gets called twice: once with Num = 1 and once with Num = 2): public

FakeItEasy ReturnLazily with more than 4 arguments method

自闭症网瘾萝莉.ら 提交于 2019-12-08 00:59:02
问题 With FakeItEasy, I want to fake an interface method to return some custom list, the method has more than 4 arguments, signature of method is this: IList<Employee> FindAll(DateTime dateFrom, DateTime dateTill, Guid locationId, Gender gender, int age); While FakeItEasy has ReturnsLazily method which has supports till only 4 arguments, so for this 5 arguments method I cannot use ReturnsLazily functionality. A.CallTo(() => repAssign.FindAll(A<DateTime>.Ignored,A<DateTime>.Ignored,A<Guid>.Ignored

Why can't I capture a FakeItEasy expectation in a variable?

▼魔方 西西 提交于 2019-12-07 04:01:08
问题 I'm using FakeItEasy to fake some Entity Framework calls, to make sure a bunch of weird legacy database tables are getting mapped properly. I need to assert that a Customer with an Invoice matching a specific DeliveryAddress is being added to the database. If I do this: A.CallTo(() => db.Customers.Add( A<Customer>.That.Matches( c => c.Invoices.First().Address == EXPECTED_ADDRESS) ) )).MustHaveHappened(); the code works perfectly. I want to streamline the syntax by moving the expectation

Why can't I capture a FakeItEasy expectation in a variable?

自作多情 提交于 2019-12-05 07:16:08
I'm using FakeItEasy to fake some Entity Framework calls, to make sure a bunch of weird legacy database tables are getting mapped properly. I need to assert that a Customer with an Invoice matching a specific DeliveryAddress is being added to the database. If I do this: A.CallTo(() => db.Customers.Add( A<Customer>.That.Matches( c => c.Invoices.First().Address == EXPECTED_ADDRESS) ) )).MustHaveHappened(); the code works perfectly. I want to streamline the syntax by moving the expectation elsewhere, but when i do this: var expected = A<Customer>.That.Matches( c => c.Invoices.First().Address ==