Mocking
Even though Foq is calling itself a mocking framework, a mock is really a recorder of events on a dependency. You can use it to verify the interactions between parts in your system.
Let's say we have a situation where we want to synchronize customer data from a CRM system onto our local database. We could have interfaces as shown in the following code:
type Customer = { ID : int; Name : string } type ICustomerService = abstract member GetCustomers : unit -> Customer list type ICustomerDataAccess = abstract member GetCustomer : int -> Customer option abstract member InsertCustomer : Customer -> unit abstract member UpdateCustomer : Customer -> unit
We write a simple scheduled job that will synchronize data nightly:
let synchronize (service : ICustomerService) (dataAccess : ICustomerDataAccess) = // get customers from service let customers = service.GetCustomers() // partition into inserts and updates let inserts, updates = customers...