Skip to content

Exception in multiple mockery instanciation of the same type  #3

@karak

Description

@karak

Hi.

I'd like to try unit-testing with mocks in F# as well as other .NET languages,
and your library looks powerful and so cool.

But I came across a problem on an elementary program as following.

When I try to create 2 mock instances of the same type,
it throws System.ArgumentException with a message
such as "An item is already added that contains same key".

I'm sorry but the message is not accurate because it was translated to my mother language...

What shall I do to make multiple mockery-instanciation work?

Karak

-- code for reproduction
#light
module MultipleInstanciation

open NaturalSpec

type IFoo = interface
  end

let binaryFunc (foo1: IFoo) (foo2: IFoo) : unit = ()

type FooImpl = class
  new() = {}
    interface IFoo
  end

[<Scenario>]
let ``try to create 2 mock-instance``() =
  let foo1 = mock<IFoo> "mock1"
  let foo2 = mock<IFoo> "mock2" // throw Exception!
  //let foo2 = new FooImpl ()

  Given foo2
    |> When calculating binaryFunc foo1
    |> Verify

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions