2011-03-30 68 views

回答

44

您應該使用.AssignsOutAndRefParameters配置方法:

[Test] 
public void Output_and_reference_parameters_can_be_configured() 
{ 
    var fake = A.Fake<IDictionary<string, string>>(); 
    string ignored = null; 

    A.CallTo(() => fake.TryGetValue("test", out ignored)) 
     .Returns(true) 
     .AssignsOutAndRefParameters("foo"); 

    // This would of course be within you SUT. 
    string outputValue = null; 
    fake.TryGetValue("test", out outputValue); 

    Assert.That(outputValue, Is.EqualTo("foo")); 
} 
+0

它的工作原理!非常感謝 – 2011-03-31 10:06:05

+1

@PatrikHägne,如果我在函數中有2個參數,那麼怎麼把它傳遞給AssignsOutAndRefParameters()函數。 – 2014-12-15 12:18:34

+1

@UmeshaMS,'.AssignsOutAndRefParameters(「out1」,「out2」) – 2016-05-27 18:32:36