الكركدن يسخر - التحقق من مجموعة خصائص عندما يكون العقار لم احصل

StackOverflow https://stackoverflow.com/questions/526267

  •  22-08-2019
  •  | 
  •  

سؤال

إذا كان لديك عقار:

public class Fred
{
   public string UserName
   {
     set
     {
        userName=value;
     }
   }
}

وكيف كنت تستخدم الكركدن تزييف للتأكد من أن

fred= new Fred();
fred.UserName="Jim";

ويسمى.

Expect.Call(mockFred.UserName).SetPropertyWithArgument("Jim");

ولا ترجمة.

هل كانت مفيدة؟

المحلول

ويجب عليك فقط أن تكون قادرة على القيام التحقق من جميع على مجموعة الخصائص

[TestClass]
public class FredTests
{
    [TestMethod]
    public void TestFred()
    {
        var mocker = new MockRepository();
        var fredMock = mocker.DynamicMock<IFred>();

        fredMock.UserName = "Name";
        // the last call is actually to the set method of username
        LastCall.IgnoreArguments(); 
        mocker.ReplayAll();

        fredMock.UserName = "Some Test that does this.";
        mocker.VerifyAll();
    }

}

public interface IFred
{
    string UserName { set; }
}

نصائح أخرى

public interface IFred
{
    string UserName { set; }
}

[Test]
public void TestMethod1()
{
    IFred fred = MockRepository.GenerateMock<IFred>();
    fred.UserName = "Jim";
    fred.AssertWasCalled(x => x.UserName = "Jim");
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top