![](/img/trans.png)
[英]FluentAssertions: Test if an Enumerable contains "subset" of itself
我正在尋找優雅的表達式來測試可枚舉對象是否包含其自身的“子集”。 讓我用一個例子來說明:[Fact] public void Test1() { // Arrange var expected = new[] { new {F1 = 1, F2 = "1" ...
[英]FluentAssertions: Test if an Enumerable contains "subset" of itself
我正在尋找優雅的表達式來測試可枚舉對象是否包含其自身的“子集”。 讓我用一個例子來說明:[Fact] public void Test1() { // Arrange var expected = new[] { new {F1 = 1, F2 = "1" ...
[英]NUnit tests failed with FLuentValidation in ONion Architecture
我正在嘗試使用 fluentvalidations 實施 nunit 測試,但它顯示了一個失敗的測試和消息: FluentValidation.AsyncValidatorInvokedSynchronouslyException: Validator "AddVehicleCommandValid ...
[英]C# unit testing MassTransit handler with MSTest, Moq and FluentAssertions. Can't verify method called exactly once
我有一個名為 Handler 的 class,它是一個 MassTransit IConsumer : 我有兩個單元測試。 這是一個似乎工作正常的: 這是沒有按照我的預期進行的操作: 兩個單元測試都要求 Handler 只調用一次 MassTransit 上下文的 RespondAsync 方法。 ...
[英]FluentAssertions .Pass declaration
執行測試后,我們通常會執行Assert.True(someCondition) 。 當不需要條件檢查並且僅完成測試就足夠時,我使用Assert.Pass()結束測試。 我正在使用FluentAssertions並且一直在做true.Should().BeTrue(); . 這開始感覺更像是一個 h ...
[英]FluentAssertion, check constraint just for condition
在 ac# 測試中,我使用 FluentAssertion 斷言。 但是,在這個測試中,“斷言”只應該在一個條件下執行(當結果無效時) 這是我的實際代碼:if (!result.IsValid) { result .Errors .Should() ...
[英]How to capture an exception thrown by an invocation using FluentAssertions
在 FluentAssertions 中,如何捕獲調用拋出的異常? Exceptions顯示了基本的代碼示例,但在我的例子中,我有一個帶有公共枚舉的CustomException 。 我想斷言拋出了正確的枚舉值。 ...
[英]How to exclude multiple properties from comparison and diff check objects efficiently in FluentAssertions
在FluentAssertions中,我可以比較兩個相同類型對象的 object 圖,並從比較中排除屬性。 然后我可以手動斷言排除的屬性以確保它們不同或具有特定值: 假設要排除的屬性列表相當大,是否有更簡潔的方法組合上述語句來進行差異檢查? ...
[英]FluentAssertions - "nested" Exclude
我有一個 API 提供了大量的功能,這就是為什么對 generics 有大量的抽象。 請想象(使用下面的代碼)以下場景:每個Dto都有一個Id 。 我想針對服務進行測試,創建項目。 該服務不知道Id ,因為它是由DbContext生成的。 到目前為止很正常。 但是現在想象一下,我有一個嵌套的Dto ...
[英]How to check the order of a nested collection with FluentAssertions
我正在嘗試使用 FluentAssertion 檢查嵌套集合的順序,如下所示。 但這似乎不正確,因為即使我檢查BeInAscendingOrder(x => x.CommentedTime斷言是正確的。如何使用 FluentAssertion 正確測試它? ...
[英]Xunit.net: Validating model returned by an async ASP.NET method
我一直在為 API 編寫單元測試。 我需要檢查 action 方法返回的 model 內的值是否是預期的。[Fact] public async Task MerchantController_GetMGetProductByMerchantId_Merchant() { //Arran ...
[英]How do I express these tests correctly with fluent assertions?
我有下面的record類型。public record CustomFormatGroupItem(string GroupName, string CfName, string CfAnchor); 我有一個返回這些集合的方法,后跟兩個測試斷言:ICollection<CustomFor ...
[英]Checking throws exception in IAsyncEnumerable method - xUnit
我有一個這樣的異步方法: 現在我想測試這個方法拋出異常。 如何使用xUnit或FluentAssertion and xUnit做到這一點? ...
[英]Fluent assertion, ThenBeInAscendingOrder propertyExpression
我不能讓它工作,任何幫助都會非常感激。 有一個來自查詢響應的實體列表,我想測試它們是否按特定順序排列,並且我希望與 Fluent 斷言庫進行比較,但我一直在為解決方案苦苦掙扎幾個小時。 到目前為止,我得到了這個: orderableAttribute 來自[DataTestMethod],[Da ...
[英]How to insert a message at the first line if there is a failure in an AssertionScope in FluentAssertions?
我正在遍歷結果數組並將每個 object 與預期結果數組resultItem.Should().BeEquivalentTo(expectedResultItem)進行比較。 每個項目都有一個唯一的標識符,並希望將其顯示在上方。 這是一個示例結果,前兩行來自 BeEquivalentTo 的單個調 ...
[英]FluentAssertions : Should().BeEquivalentTo fails for un-ordered arrays of enums
我在 C# 中有一個測試,我使用 FluentAssertions 來檢查結果。 使用這樣的枚舉: 我讀到Should().BeEquivalentTo()默認情況下應該在沒有嚴格排列數組的情況下進行比較,但顯然情況並非如此,因為測試失敗,至少對於枚舉的 arrays 而言。 我錯過了什么? ...
[英]Fluent Assertions how to Exclude parameters with generic object
我有一個測試類的通用方法,我想排除幾個實體之間的一些公共參數。 自上一個版本以來,此SelectedMemberPath已被棄用。 有人找到最新版本的通用對象的解決方案嗎? 謝謝! ...
[英]FluentAssertions: collection subset should contain equivalent of list
我有一個收藏: 我想檢查它是否至少包含new { A = 9 }和new { A = 5 }以任何順序。 我可以使用ContainEquivalentOf ,但我必須一個一個地做: 更新:我不能使用Contains ,因為它要求實際對象和預期對象具有相同的類型。 ...
[英]How to do an "AllNotSatisfy" condition in FluentAssertions
考慮這段代碼: 這有效: 但是,我想寫一個斷言,斷言沒有字典包含“4”作為鍵...... 最初我認為我可以這樣做: 但這不起作用...我得到Only assignment, call, increment, decrement, await expression, and new ob ...
[英]FluentAssertions error CS0012: You must add a reference to assembly System.Data
我在使用 .NET Framework 4.6.1 的測試項目中添加了 nuget FluentAssertions 6.7.0 。 我從 Rider 2022.1.1 運行測試。 我是這個 nuget 的新手,我閱讀了介紹並搜索了問題(未找到)。 我來自應該家庭並試圖升級。 我不能用基本的斷言 ...
[英]Assertion for check string value include array of string
我創建了如下的書類 我將書籍數據列表定義為: List<book> books為 我想斷言應該是真的,如果書籍列表中的 bookName 可以在string[] expectResults {"apple", "ap"}中找到就下面的例子 但它總是失敗,任何人都可以建議如何做 ...