foq

Using Foq with F# function types

回眸只為那壹抹淺笑 提交于 2020-07-08 11:52:48
问题 I am using F# type definitions to prevent hard dependencies between my functions, for example type IType1 = int -> int type IType2 = int-> string let func1 (i : int) : int = i * i let func2 (i : int) : string = i |> string let higherFunc (dep1 : IType1) (dep2 : IType2) (input : int) : string = input |> dep1 |> dep2 let curriedFunc = higherFunc func1 func2 let x = curriedFunc 2 output x : "4" Obviously this is quite contrived and simple but imagine the dependencies are a parser and a sorter or

Using Ninject with mocks in F#

♀尐吖头ヾ 提交于 2019-12-13 18:36:03
问题 This question is part of larger question that can be found here As in out production code we use Ninject and constructor injection our services tend to look like this public class Service : IService { private readonly IRepository _repository; public Service(IRepository repository) { _repository = repository; } public Task<IEnumerable<SelectOption>> GetAlLogicOptions() { return _repository.GetOptionsAsync(); } } how ever list of constructor parameters may and will change over time. This is the

Mocking Non-Standard Events in F# Foq

萝らか妹 提交于 2019-12-11 03:20:17
问题 I'm new to F#, and I'm putting myself through some exercises to learn the language. The one I'm currently trying to do is to write a unit test for a custom Castle.Windsor Facility, and I am trying to Mock the Kernel to raise a "ComponentRegistered" event. The tools I'm using are FsUnit/xUnit/Foq. My Code: let event = Event<_,_>() let kernel = Mock<IKernel>() .SetupEvent(fun k -> <@ k.ComponentRegistered @>) .Publishes(event.Publish) .Create() Error Message: Error 4 The event