cost 119 ms
C# 使用 MSTest、Moq 和 FluentAssertions 對 MassTransit 處理程序進行單元測試。 無法驗證只調用一次的方法

[英]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 聲明

[英]FluentAssertions .Pass declaration

執行測試后,我們通常會執行Assert.True(someCondition) 。 當不需要條件檢查並且僅完成測試就足夠時,我使用Assert.Pass()結束測試。 我正在使用FluentAssertions並且一直在做true.Should().BeTrue(); . 這開始感覺更像是一個 h ...

FluentAssertion,僅針對條件檢查約束

[英]FluentAssertion, check constraint just for condition

在 ac# 測試中,我使用 FluentAssertion 斷言。 但是,在這個測試中,“斷言”只應該在一個條件下執行(當結果無效時) 這是我的實際代碼:if (!result.IsValid) { result .Errors .Should() ...

如何使用 FluentAssertions 捕獲調用引發的異常

[英]How to capture an exception thrown by an invocation using FluentAssertions

在 FluentAssertions 中,如何捕獲調用拋出的異常? Exceptions顯示了基本的代碼示例,但在我的例子中,我有一個帶有公共枚舉的CustomException 。 我想斷言拋出了正確的枚舉值。 ...

如何在 FluentAssertions 中有效地從比較和差異檢查對象中排除多個屬性

[英]How to exclude multiple properties from comparison and diff check objects efficiently in FluentAssertions

在FluentAssertions中,我可以比較兩個相同類型對象的 object 圖,並從比較中排除屬性。 然后我可以手動斷言排除的屬性以確保它們不同或具有特定值: 假設要排除的屬性列表相當大,是否有更簡潔的方法組合上述語句來進行差異檢查? ...

FluentAssertions - “嵌套”排除

[英]FluentAssertions - "nested" Exclude

我有一個 API 提供了大量的功能,這就是為什么對 generics 有大量的抽象。 請想象(使用下面的代碼)以下場景:每個Dto都有一個Id 。 我想針對服務進行測試,創建項目。 該服務不知道Id ,因為它是由DbContext生成的。 到目前為止很正常。 但是現在想象一下,我有一個嵌套的Dto ...

如何使用 FluentAssertions 檢查嵌套集合的順序

[英]How to check the order of a nested collection with FluentAssertions

我正在嘗試使用 FluentAssertion 檢查嵌套集合的順序,如下所示。 但這似乎不正確,因為即使我檢查BeInAscendingOrder(x => x.CommentedTime斷言是正確的。如何使用 FluentAssertion 正確測試它? ...

如何使用流利的斷言正確表達這些測試?

[英]How do I express these tests correctly with fluent assertions?

我有下面的record類型。public record CustomFormatGroupItem(string GroupName, string CfName, string CfAnchor); 我有一個返回這些集合的方法,后跟兩個測試斷言:ICollection<CustomFor ...

Fluent 斷言,ThenBeInAscendingOrder propertyExpression

[英]Fluent assertion, ThenBeInAscendingOrder propertyExpression

我不能讓它工作,任何幫助都會非常感激。 有一個來自查詢響應的實體列表,我想測試它們是否按特定順序排列,並且我希望與 Fluent 斷言庫進行比較,但我一直在為解決方案苦苦掙扎幾個小時。 到目前為止,我得到了這個: orderableAttribute 來自[DataTestMethod],[Da ...

如果 FluentAssertions 中的 AssertionScope 出現故障,如何在第一行插入消息?

[英]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 對於枚舉的無序 arrays 失敗

[英]FluentAssertions : Should().BeEquivalentTo fails for un-ordered arrays of enums

我在 C# 中有一個測試,我使用 FluentAssertions 來檢查結果。 使用這樣的枚舉: 我讀到Should().BeEquivalentTo()默認情況下應該在沒有嚴格排列數組的情況下進行比較,但顯然情況並非如此,因為測試失敗,至少對於枚舉的 arrays 而言。 我錯過了什么? ...

FluentAssertions:集合子集應包含等效的列表

[英]FluentAssertions: collection subset should contain equivalent of list

我有一個收藏: 我想檢查它是否至少包含new { A = 9 }和new { A = 5 }以任何順序。 我可以使用ContainEquivalentOf ,但我必須一個一個地做: 更新:我不能使用Contains ,因為它要求實際對象和預期對象具有相同的類型。 ...

如何在 FluentAssertions 中執行“AllNotSatisfy”條件

[英]How to do an "AllNotSatisfy" condition in FluentAssertions

考慮這段代碼: 這有效: 但是,我想寫一個斷言,斷言沒有字典包含“4”作為鍵...... 最初我認為我可以這樣做: 但這不起作用...我得到Only assignment, call, increment, decrement, await expression, and new ob ...

FluentAssertions 錯誤 CS0012:您必須添加對程序集 System.Data 的引用

[英]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"}中找到就下面的例子 但它總是失敗,任何人都可以建議如何做 ...


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