Questions tagged [foq]

Foq is a lightweight thread-safe mocking library for F#, C# & VB.Net.

Foq is a lightweight thread-safe mocking library for F#, C# & VB.Net.

12 questions
6
votes
1 answer

Mocking a class with an explicitly implemented interface using Foq

I wanted to mock an entityframwork DbSet using Foq. It goes something like: let patients = ([ Patient(Guid "00000000-0000-0000-0000-000000000001"); Patient(Guid "00000000-0000-0000-0000-000000000002"); Patient(Guid…
albertjan
  • 7,739
  • 6
  • 44
  • 74
5
votes
1 answer

Using Foq with F# function types

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 :…
Ryan
  • 2,109
  • 1
  • 15
  • 19
3
votes
1 answer

Using Foq to mock Microsoft.Extensions.Logging.ILogger

I'm having difficulties to Mock Microsoft ILogger with Foq. module MockExample open Microsoft.Extensions.Logging open NUnit.Framework open Foq //open Foq.Linq // Implementation type Worker (logger:ILogger) = member this.DoSomething…
Alex 75
  • 2,798
  • 1
  • 31
  • 48
3
votes
3 answers

Foq Mock.Expect with Times > 1 always fails

None of the Mock.Expect examples I've found use Times other than 0 or 1 (never, once). I modifed one of the existing tests from Foq.Usage.fsx to attempt something that's not 0 or 1, but I can't make it work. Does anyone see anything wrong? let…
MickeyPickle
  • 103
  • 4
3
votes
1 answer

Mocking Non-Standard Events in F# Foq

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"…
Mitchell Lee
  • 456
  • 3
  • 14
3
votes
1 answer

How to set up a mock in Foq that returns an async?

I try to set up a mock using Mock.With(fun y -> <@ y.DoIt (any()) --> async {()} @>) This leads to a NotSupportedException being raised in the function toCall. How should I mock Async in Foq? Is it supported?
Remko
  • 754
  • 3
  • 15
3
votes
1 answer

Using Foq Verify methodsmatch fails on interface with type parameter

I have an interface like this type IAppDatabase = abstract Get<'T> : seq -> Task> abstract Set<'T> : seq<'T> -> Task abstract GetIds<'T> : unit -> Task> I try to mock like this let results = seq [DT.Result…
Remko
  • 754
  • 3
  • 15
2
votes
1 answer

Can you set up recursive mocks in foq?

I'd let to mock an IBus with Foq. One of the methods on the IBus is OpenPublishChannel, which returns an IPublishChannel. IPublishChannel in turn has a Bus property that returns the parent IBus. My current code is below, but obviously it doesn't…
mavnn
  • 9,101
  • 4
  • 34
  • 52
1
vote
1 answer

Testing interfaces with foq

I am trying to use Foq to testing an interface with Foq. So far, all examples I have seen for this have been relatively simple, such as the following: let users = [|{ID = 1; pass = true};{ID = 2; pass= false}|] type IFoo = abstract member…
Pash101
  • 631
  • 3
  • 14
1
vote
0 answers

Using Ninject with mocks in F#

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; …
Icen
  • 441
  • 6
  • 14
1
vote
1 answer

Configuring C# out parameters with Foq in F#

I am using F# and Foq to write unit tests for a C# project. I am trying to set up a mock of an interface whose method has an out parameter, and I have no idea how to even start. It probably has to do with code quotations, but that's where my…
TeaDrivenDev
  • 6,591
  • 33
  • 50
0
votes
1 answer

Mocking an abstract class with a virtual internally settable property in Foq

I have written an Azure durable function in F# and am trying to write unit tests, following the guidelines at https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-unit-testing. I have attempted to use Foq to create a…
Blisco
  • 601
  • 6
  • 14