<commit_before>﻿module Foq.WithTests

open Foq
open NUnit.Framework

[<Test>]
let ``test mock with multiple members`` () =
    let xs =
        Mock<System.Collections.Generic.IList<char>>.With(fun xs ->
            <@ xs.Count --> 2 
               xs.Item(0) --> '0'
               xs.Item(1) --> '1'
               xs.Contains(any()) --> true
               xs.RemoveAt(2) ==> System.ArgumentOutOfRangeException()
            @>
        )
    Assert.AreEqual(2, xs.Count)
    Assert.AreEqual('0', xs.Item(0))
    Assert.AreEqual('1', xs.Item(1))
    Assert.AreEqual(true, xs.Contains('0'))
    Assert.Throws<System.ArgumentOutOfRangeException>(fun () ->
        xs.RemoveAt(2)
    ) |> ignore

[<Test>]
let ``test fallthrough when matching a specific member`` () =
    let xs =
        Mock<System.Collections.Generic.IList<char>>.With(fun xs ->
            <@ xs.Item(0) --> '0'
               xs.Item(1) --> '1'
               xs.Item(any()) --> '2' @>
        )
    Assert.AreEqual('0', xs.Item(0))
    Assert.AreEqual('1', xs.Item(1))
    Assert.AreEqual('2', xs.Item(2))

[<Test>]
let ``test mock with exception on member`` () =
    let xs =
        Mock<System.Collections.Generic.IList<char>>.With(fun xs -><commit_msg>Added example of Mock.With using a setup function<commit_after>﻿module Foq.WithTests

open System.Collections.Generic
open Foq
open NUnit.Framework

[<Test>]
let ``test mock with multiple members`` () =
    let xs =
        Mock<IList<char>>.With(fun xs ->
            <@ xs.Count --> 2 
               xs.Item(0) --> '0'
               xs.Item(1) --> '1'
               xs.Contains(any()) --> true
               xs.RemoveAt(2) ==> System.ArgumentOutOfRangeException()
            @>
        )
    Assert.AreEqual(2, xs.Count)
    Assert.AreEqual('0', xs.Item(0))
    Assert.AreEqual('1', xs.Item(1))
    Assert.AreEqual(true, xs.Contains('0'))
    Assert.Throws<System.ArgumentOutOfRangeException>(fun () ->
        xs.RemoveAt(2)
    ) |> ignore

let membersSetup (xs:IList<char>) =
    <@ xs.Count --> 2 
       xs.Item(0) --> '0'
       xs.Item(1) --> '1'
       xs.Contains(any()) --> true
     @>

let ``test mock with multiple members via setup function`` () =
    let xs = Mock.With(membersSetup)           
    Assert.AreEqual(2, xs.Count)
    Assert.AreEqual('0', xs.Item(0))
    Assert.AreEqual('1', xs.Item(1))
    Assert.AreEqual(true, xs.Contains('0'))

[<Test>]
let ``test fallthrough when matching a specific member`` () =
    let xs =
        Mock<System.Collections.Generic.IList<char>>.With(fun xs ->
            <@ xs.Item(0) --> '0'
               xs.Item(1) --> '1'
               xs.Item(any()) --> '2' @>
        )
    Assert.AreEqual('0', xs.Item(0))
    Assert.AreEqual('1', xs.Item(1))
    Assert.AreEqual('2', xs.Item(2))

[<Test>]
let ``test mock with exception on member`` () =
    let xs =
        Mock<System.Collections.Generic.IList<char>>.With(fun xs ->
{'fraction_non_alphanumeric': 0.17991775188485265, 'fraction_numerical': 0.02021932830705963, 'mean_word_length': 2.1936542669584247, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5192758', 'n_tokens_mistral': 1029, 'n_tokens_neox': 971, 'n_words': 190}