Combining SpecFlow table and Moq mocked object

Posted by Confused on Stack Overflow See other posts from Stack Overflow or by Confused
Published on 2012-12-19T12:39:50Z Indexed on 2013/11/03 21:55 UTC
Read the original article Hit count: 267

Filed under:
|
|

I have a situation where I want to use a mocked object (using Moq) so I can create setup and expectations, but also want to supply some of the property values using the SpecFlow Table. Is there a convenient way to create a mock and supply the table for the seed values?

// Specflow feature

Scenario Outline: MyOutline
Given I have a MyObject object as
| Field | Value     |
| Title | The Title |
| Id    | The Id    |


// Specflow step code    

Mock<MyObject> _myMock;

[Given(@"I have a MyObject object as")]
public void GivenIHaveAMyObjectObjectAs(Table table)
{
   var obj = table.CreateInstance<MyObject>();

   _myMock = new Mock<MyObject>();

   // How do I easily combine the two?

}

© Stack Overflow or respective owner

Related posts about c#

Related posts about moq