cost 326 ms
如何為具有內部構造函數的 model 創建測試替身? 使用 c#、xunit 和 nsubstitute

[英]How to create a test double for model that has internal constructor? using c#, xunit and nsubstitute

我有一個調用 azure API 的方法來列出給定容器中的 blob。 然后我有一些業務邏輯(主要基於它們的名稱),然后此方法刪除了一些 blob。 所以調用了BlobContainerClient.GetBlobs 現在我想創建一些單元測試,以確保我的代碼確實按照我的意願執行(使用 xunit ...

Autofixture 凍結間接依賴

[英]Autofixture freeze indirect dependency

使用xunit 、 Autofixture和NSubstitute 我有一個 class MyClass依賴於IServiceB而這又依賴於IServiceA如下所示 然后我有下面的xunit測試 它會失敗。 為什么? 是不是如果MethodA()被frozen為Return("Hello")那么M ...

NSubstitute 分析器錯誤地給出警告?

[英]NSubstitute analyzer giving a warning incorrectly?

在使用 NuGet NSubstitute 4.3.0 和 NSubstitute.Analyzers.CSharp 時,我試圖截取如下呼叫。 此處更改了實際名稱以進行說明。 ExtensionMethod是在IInterface上定義的擴展方法。 顯然 Nsubstitute.Analyzer ...

NSubstitute Mocking 表達式和參數

[英]NSubstitute Mocking Expressions along with params

我有一個名為 TestClass 的以下 class 和一個 function。 在測試類中 這就是我嘗試使用 NSubstitute 模擬上述方法的方式。 它符合要求,但調用時的模擬方法不包括集合中的兩個 Animal object,因為集合長度為零。 我有一種感覺,因為我不是 mocking 參 ...

傳遞 Arg.Any 時出現 NullReferenceException<int> () 作為參數使用 NSubstitute</int>

[英]NullReferenceException when passing Arg.Any<int>() as argument using NSubstitute

我有一個客戶 class,它接受一個 IDbGateway 接口作為構造函數參數。 我需要使用 NUnit 和 NSubstitute 為 class 編寫單元測試 CalculateWage_HourlyPayed_ReturnsCorrectWage。 當我通過anyId時,我的單元測試工作正 ...

如何針對布爾值斷言以確認導致在 C# 中引發異常?

[英]How do I assert against a Boolean value to confirm that causes an exception to be thrown in C#?

我正在為我的應用程序編寫單元測試,並試圖確保在我的一項服務中拋出異常。 該異常是基於真/假條件引發的,但我不確定如何使其工作。 我在單元測試中使用 NSubstitute 進行模擬,在測試框架中使用 MSTest。 這是我的單元測試。 如您所見,測試方法裝飾有預期的異常類型和我們希望看到的消息 ...

使用 NSubstitute 進行多線程單例替換

[英]Multithread Singeleton Substitution with NSubstitute

我在 FooService 中有一個公共方法 ValidateWords。為了測試 ValidateWord 方法,我創建了 IAppSettingWrapper 和 AppSettingWrapper,它們返回 AppSettings 的實例。 在測試方法中,我想使用 NSubstitute 替換 ...

Mocking 帶有可選參數的 function 帶有固定參數,在 C# 中使用 Nsubstitute 返回 null

[英]Mocking a function with optional parameter with fixed parameter using Nsubstitute in C# returns null

我一直在嘗試模擬一個 function,它包含帶有固定參數的可選參數,但每次我得到一個 null 值時,這里是我在接口中定義的 function,我想模擬它: 調用此 function 的方法: 這是我的測試方法: 每當我在 ExportSpecimens 中點擊function時,我都會得到nu ...

AutoFixture 與 AutoNSubstituteCustomization:在 ReadOnly IEnumerable 上設置 object 計數<t>財產</t>

[英]AutoFixture with AutoNSubstituteCustomization: Set object count on ReadOnly IEnumerable<t> property

我的測試要求我在主實體集合的 IEnumerable 屬性中有不同數量的對象。 我一直在搜索有關此的文檔,但找不到任何東西。 這是我的意思的示例(請注意,基本實體是使用AutoNSubstituteCustomization創建的) ITransaction的樣子 我知道我可以設置fixture. ...

如何使用 xUnit 和 NSubstitute 模擬 DbSet?

[英]How to mock DbSet using xUnit and NSubstitute?

我開始使用 xUnit 和 NSubstitute 進行單元測試。 我想模擬以下方法。 我嘗試了它,但無法讓它工作。 我目前的測試 class 如下; 但是,我收到以下錯誤: “源 'IQueryable' 的提供程序未實現 'IAsyncQueryProvider'。只有實現 'IAsyncQ ...

使用虛方法模擬具體類

[英]Mocking a concrete class with a virtual method

我想用虛方法測試一個依賴於另一個類的類。 現在我想測試HostClass與Autofixture + NSubstitute。 我的期望: 事實上,當我執行Freeze().Get().Returns() ,真正的Get方法被調用。 如何自定義 Autofixture 來模擬所有虛擬方法? ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM