nsubstitute

    0熱度

    1回答

    我有一個與Nsubstitue對象一起使用.NET集合的問題。 我有一個基類,其中我實現equals(對象),的CompareTo函數 在測試I創建此基類中的兩個精確Nsubstitue對象代理。 將對象放入集合後,集合顯示這兩個對象代理是兩個不同的對象。 我不知道可能是什麼原因導致了這種行爲,以及如何用模型定義集合。 public class KeyTestClass : IKeyTestCla

    1熱度

    1回答

    我有以下代碼: 45 var listMock = Substitute.For<List<EntityTestObject>>(); 46 listMock.Where(Arg.Any<Func<EntityTestObject, bool>>()).Returns(Something); 但我發現了以下錯誤: System.ArgumentNullException:值不能爲空。 參數名:謂語

    1熱度

    1回答

    我創建了一個「部分」模擬,並使用DoNotCallBase()所以我的模擬方法被調用,而不是實際的方法。 由於我需要在測試夾具中多次執行此操作,因此我在安裝時做了一次。 但是對於一個測試,我需要真正的方法,而不是模擬。我可以撤消/清除「DoNotCallBase」嗎?

    0熱度

    2回答

    我想用一個模擬對象的不同行爲執行一個測試方法幾(3)次。所以我可以避免用模擬對象編寫多個Test方法。 守則〔實施例: _mockObj.MockedMethod(Arg.Any<string>(), Arg.Any<string>()).Returns(new objA() { TestProp="bla1" }; _mockObj.MockedMethod(Arg.Any<string>()

    2熱度

    1回答

    我有一個TestFixture標記類,它是單元測試名爲'HideCurrentTitleBarMessageTask'的類的功能。 在這個類中,我使用替代方法模擬[Setup]方法中的接口,並且在測試類中的一些測試中,我從其中一個模擬接口成員設置了返回結果。 [TestFixture] public class TestClass_A { private ITitleBarMessa

    1熱度

    1回答

    我有一個實體,以及驗證: public class Customer : IEntity { /* ... */ } public class CustomerValidator : IValidator<Customer> { /* ... */ } 我想嘲笑驗證工廠: public interface IValidatorFactory { IValidator<TEntit

    2熱度

    1回答

    我試圖模擬一個從SoapHttpClientProtocol繼承的web服務對象,並且我無法在我的單元測試中進行修改。不幸的是,當我嘗試: var myApi = Substitute.ForPartsOf<MyAPIClass>(); 我得到以下錯誤: Message: Test method MyProj.Test.Business.Folder.CalendarEventServiceU

    0熱度

    1回答

    使用NSubstitute,你如何模擬在返回void的方法中引發的異常? 比方說,我們的方法簽名看起來是這樣的: void Add(); 這裏的NSubstitute文檔是怎麼說的嘲笑爲返回void類型拋出異常。但是,這並不編譯:( myService .When(x => x.Add(-2, -2)) .Do(x => { throw new Exception();

    -1熱度

    1回答

    我有一個Singleton類,像這樣: public class XConnector : IXConnector { private static readonly Lazy<XConnector> instance = new Lazy<XConnector>(() => new XConnector()); public stat

    1熱度

    1回答

    public class Device { private readonly IProtocol _protocol; public Device(IProtocol protocol) { _protocol = protocol; } public bool Connect(string port) {