title: Getting arguments passed to a FakeItEasy-mock without using magic strings?
body: <p>I have been using <a href="http://code.google.com/p/moq/">Moq</a> for my mocking needs the last years, but after looking at <a href="http://code.google.com/p/fakeiteasy/">FakeItEasy</a> i wanted to give it a try.</p>
  
  <p>I often want to test that a method have been called with the correct parameters, but i found no satisfactory way to do this with FakeItEasy.</p>
  
  <p>I have the following code to test:</p>
  
  <pre><code>    public class WizardStateEngine : IWizardStateEngine
  {
      private readonly IWorkflowInvoker _workflowInvoker;
      private List&lt;CustomBookmark&gt; _history;
  
      public WizardStateEngine(IWorkflowInvoker workflowInvoker)
      {
          _workflowInvoker = workflowInvoker;
      }
  
      public void Initialize(List&lt;CustomBookmark&gt; history)
      {
          _history = history;
      }
  
      public WizardStateContext Execute(Command command, WizardStateContext stateContext, CustomBookmark step)
      {
          Activity workflow = new MyActivity();
          var input = new Dictionary&lt;string, object&gt;();
          input["Action"] = command;
          input["Context"] = stateContext;
          input["BookmarkHistory"] = _history;
  
          var output = _workflowInvoker.Invoke(workflow, input);
  
          _history = output["BookmarkHistory"] as List&lt;CustomBookmark&gt;;
  
          return output["Context"] as WizardStateContext;
      }
  
      public List&lt;CustomBookmark&gt; GetBookmarkHistory()
      {
          return _history;
      }
  }
  </code></pre>
  
  <p>I want to write some tests that verifies the input to _workflowInvoker.Invoke(). 
  My TestInitialize method sets up the needed resources and save the input dictionary to _workflowInvoker.Invoke() as a local field _wfInput.</p>
  
  <pre><code>    [TestInitialize]
      public void TestInitialize()
      {
          _wizardStateContext = new WizardStateContext();
          _workflowInvoker = A.Fake&lt;IWorkflowInvoker&gt;();
          _wizardStateEngine = new WizardStateEngine(_workflowInvoker);
  
          _outputContext = new WizardStateContext();
          _outputHistory = new List&lt;CustomBookmark&gt;();
          _wfOutput = new Dictionary&lt;string, object&gt;
                          {{"Context", _outputContext}, {"BookmarkHistory", _outputHistory}};
  
          _history = new List&lt;CustomBookmark&gt;();
  
          A.CallTo(() =&gt;
                   _workflowInvoker.Invoke(A&lt;Activity&gt;.Ignored, A&lt;Dictionary&lt;string, object&gt;&gt;.Ignored))
              .Invokes(x =&gt; _wfInput = x.Arguments.Get&lt;Dictionary&lt;string, object&gt;&gt;("input"))
              .Returns(_wfOutput);
  
          _wizardStateEngine.Initialize(_history);
      }
  </code></pre>
  
  <p>After the setup i have multiple tests like this:</p>
  
  <pre><code>    [TestMethod]
      public void Should_invoke_with_correct_command()
      {
          _wizardStateEngine.Execute(Command.Start, null, null);
  
          ((Command) _wfInput["Action"]).ShouldEqual(Command.Start);
      }
  
      [TestMethod]
      public void Should_invoke_with_correct_context()
      {
          _wizardStateEngine.Execute(Command.Start, _wizardStateContext, null);
  
          ((WizardStateContext) _wfInput["Context"]).ShouldEqual(_wizardStateContext);
      }
  
      [TestMethod]
      public void Should_invoke_with_correct_history()
      {
          _wizardStateEngine.Execute(Command.Start, _wizardStateContext, null);
  
          ((List&lt;CustomBookmark&gt;) _wfInput["BookmarkHistory"]).ShouldEqual(_history);
      }
  </code></pre>
  
  <p>I do not like the magic string "input" in the TestInitialize for getting the passed argument (or magic number). I can write the tests without the local field like this:</p>
  
  <pre><code>    [TestMethod]
      public void Should_invoke_with_correct_context()
      {
          _wizardStateEngine.Execute(Command.Start, _wizardStateContext, null);
  
          A.CallTo(() =&gt;
                   _workflowInvoker.Invoke(A&lt;Activity&gt;._,
                                           A&lt;Dictionary&lt;string, object&gt;&gt;.That.Matches(
                                               x =&gt; (WizardStateContext) x["Context"] == _wizardStateContext)))
              .MustHaveHappened();
      }
  </code></pre>
  
  <p>But i find the tests with the local field more readable.</p>
  
  <p>Are there any way to setup saving of the input as a field i my test class without magic numbers or strings?</p>
  
  <p>I hope the updated example in the question shows why i would like to use the local field. I am more than willing to write my tests without the local field if i can find a nice readable way to do it. </p>