fakeiteasy

Getting arguments passed to a FakeItEasy-mock without using magic strings?

和自甴很熟 提交于 2019-12-05 02:24:10
I have been using Moq for my mocking needs the last years, but after looking at FakeItEasy i wanted to give it a try. I often want to test that a method have been called with the correct parameters, but i found no satisfactory way to do this with FakeItEasy. I have the following code to test: public class WizardStateEngine : IWizardStateEngine { private readonly IWorkflowInvoker _workflowInvoker; private List<CustomBookmark> _history; public WizardStateEngine(IWorkflowInvoker workflowInvoker) { _workflowInvoker = workflowInvoker; } public void Initialize(List<CustomBookmark> history) {

FakeItEasy Proxy methods calls to real implementation

北城以北 提交于 2019-12-04 05:24:40
I'm trying to proxy calls to a fake object to the actual implementation. The reason for this is that I want to be able to use the WasToldTo and WhenToldTo of Machine.Specifications which only works on fakes of an interface type. Therefore I'm doing the following to proxy all calls to my real object. public static TFake Proxy<TFake, TInstance>(TFake fake, TInstance instance) where TInstance : TFake { fake.Configure().AnyCall().Invokes(x => x.Method.Invoke(instance, x.Arguments.ToArray())); return fake; } I would use that like this. var fake = Proxy<ISomeInterface, SomeImplementation>(A.Fake

How to test for exceptions thrown using xUnit, SubSpec and FakeItEasy

不羁的心 提交于 2019-12-03 10:37:48
I’m using xUnit, SubSpec and FakeItEasy for my unit tests. I’ve so far created some positive unit tests like the following: "Given a Options presenter" .Context(() => presenter = new OptionsPresenter(view, A<IOptionsModel>.Ignored, service)); "with the Initialize method called to retrieve the option values" .Do(() => presenter.Initialize()); "expect the view not to be null" .Observation(() => Assert.NotNull(view)); "expect the view AutoSave property to be true" .Observation(() => Assert.True(view.AutoSave)); But now I want to write some negative unit tests and check that certain methods don't

How to update a property on a parameter using FakeItEasy

旧城冷巷雨未停 提交于 2019-12-02 04:36:15
问题 I have an interface that includes a member that looks like: void ExecuteSqlCommand(string procedureName, SqlParameter[] parameters); I am using FakeItEasy to create a mock of this to pass to one of my classes. The code I am testing calls this method, then checks the value of one of the SqlParameters. How do I use FakeItEasy to set the Value property of this parameter when the method is called? I appreciate that this is probably not the best practice for getting individual pieces of

How to update a property on a parameter using FakeItEasy

守給你的承諾、 提交于 2019-12-02 01:13:21
I have an interface that includes a member that looks like: void ExecuteSqlCommand(string procedureName, SqlParameter[] parameters); I am using FakeItEasy to create a mock of this to pass to one of my classes. The code I am testing calls this method, then checks the value of one of the SqlParameters. How do I use FakeItEasy to set the Value property of this parameter when the method is called? I appreciate that this is probably not the best practice for getting individual pieces of information out of a database, but I am working with existing stored procedures, some of which have OUT

Use FakeItEasy's A.CallTo() on another method in same object

依然范特西╮ 提交于 2019-11-29 10:47:54
Using FakeItEasy, how do I check to see if my object's method calls another method on this same object? The Test: [TestMethod] public void EatBanana_CallsWillEat() { var banana = new Banana(); var myMonkey = new Monkey(); myMonkey.EatBanana(banana); //this throws an ArgumentException, because myMonkey is a real instance, not a fake A.CallTo(() => myMonkey.WillEat(banana) .MustHaveHappened(); } The Class: public class MyMonkey { private readonly IMonkeyRepo _monkeyRepo; public MyMonkey(IMonkeyRepo monkeyRepo) { _monkeyRepo = monkeyRepo; } public void EatBanana(Banana banana) { //make sure the

How to test for a Match with FakeItEasy on a predicate call?

梦想与她 提交于 2019-11-29 07:42:48
I have the following call in my code: var dbResults = new List<CrossReferenceRelationshipEF>(); dbResults = dateTimeFilter == null ? new List<CrossReferenceRelationshipEF>( CrossReferenceRelationshipRepository.GetAll() .ToList().OrderBy(crr => crr.ToPartner)) : new List<CrossReferenceRelationshipEF>( CrossReferenceRelationshipRepository.SearchFor( crr => crr.HistoricEntries .Any(he => he.ModifiedDatetime > dateTimeFilter)) .ToList().OrderBy(crr => crr.ToPartner)); and I am trying to use FakeItEasy to verify that when the dateTimeFilter has a value, the SearchFor(…) is being called within my

is it possible to mock/fake an extension method?

北慕城南 提交于 2019-11-28 12:16:19
I'm using a controller extension, and I tried to mock it using FakeItEasy (v 1.7.4) like this: A.CallTo(() => controller.RenderView(A<string>.Ignored,A<object>.Ignored,null)).Returns(""); but I get this error: System.NullReferenceException : Object reference not set to an instance of an object. at System.Object.GetType() at FakeItEasy.Creation.ProxyGeneratorSelector.MethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget, ref String failReason) at FakeItEasy.Configuration.DefaultInterceptionAsserter.AssertThatMethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget)

Use FakeItEasy's A.CallTo() on another method in same object

点点圈 提交于 2019-11-28 03:50:09
问题 Using FakeItEasy, how do I check to see if my object's method calls another method on this same object? The Test: [TestMethod] public void EatBanana_CallsWillEat() { var banana = new Banana(); var myMonkey = new Monkey(); myMonkey.EatBanana(banana); //this throws an ArgumentException, because myMonkey is a real instance, not a fake A.CallTo(() => myMonkey.WillEat(banana) .MustHaveHappened(); } The Class: public class MyMonkey { private readonly IMonkeyRepo _monkeyRepo; public MyMonkey

How to test for a Match with FakeItEasy on a predicate call?

主宰稳场 提交于 2019-11-28 01:33:38
问题 I have the following call in my code: var dbResults = new List<CrossReferenceRelationshipEF>(); dbResults = dateTimeFilter == null ? new List<CrossReferenceRelationshipEF>( CrossReferenceRelationshipRepository.GetAll() .ToList().OrderBy(crr => crr.ToPartner)) : new List<CrossReferenceRelationshipEF>( CrossReferenceRelationshipRepository.SearchFor( crr => crr.HistoricEntries .Any(he => he.ModifiedDatetime > dateTimeFilter)) .ToList().OrderBy(crr => crr.ToPartner)); and I am trying to use