├── .editorconfig ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── CI.yml │ └── publish.yml ├── .gitignore ├── .vscode ├── settings.json └── tasks.json ├── CODE_OF_CONDUCT.md ├── CSharpFunctionalExtensions.FluentAssertions.sln ├── Directory.Build.props ├── Directory.Build.targets ├── LICENSE ├── README.md ├── images └── nitro-devs-logo.png ├── src └── CSharpFunctionalExtensions.FluentAssertions │ ├── CSharpFunctionalExtensions.FluentAssertions.csproj │ ├── MaybeExtensions.cs │ ├── ResultExtensions.cs │ ├── ResultTEExtensions.cs │ ├── ResultTExtensions.cs │ └── UnitResultExtensions.cs └── tests └── CSharpFunctionalExtensions.FluentAssertions.Tests ├── CSharpFunctionalExtensions.FluentAssertions.Tests.csproj ├── MaybeAssertionsTests.cs ├── ResultAssertionTests.cs ├── ResultTAssertionsTests.cs ├── ResultTEAssertionTests.cs └── UnitResultAssertionTests.cs /.editorconfig: -------------------------------------------------------------------------------- 1 | # Severity levels of analyzers https://docs.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview?view=vs-2019#severity-levels-of-analyzers 2 | 3 | root = true 4 | 5 | [*.cs] 6 | end_of_line = crlf 7 | indent_size = 4 8 | indent_style = space 9 | insert_final_newline = true 10 | 11 | # Formatting Rules 12 | 13 | ## IDE0055: Fix formatting 14 | dotnet_diagnostic.IDE0055.severity = error 15 | 16 | dotnet_sort_system_directives_first = true 17 | dotnet_separate_import_directive_groups = false 18 | 19 | ## C# Formatting Rules https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules 20 | 21 | ### Newline options 22 | csharp_new_line_before_open_brace = all 23 | csharp_new_line_before_else = true 24 | csharp_new_line_before_catch = true 25 | csharp_new_line_before_finally = true 26 | csharp_new_line_before_members_in_object_initializers = true 27 | csharp_new_line_before_members_in_anonymous_types = true 28 | csharp_new_line_between_query_expression_clauses = true 29 | 30 | ### Indentation options 31 | csharp_indent_case_contents = true 32 | csharp_indent_switch_labels = true 33 | csharp_indent_labels = one_less_than_current 34 | csharp_indent_block_contents = true 35 | csharp_indent_braces = false 36 | csharp_indent_case_contents_when_block = false 37 | 38 | ### Spacing options 39 | csharp_space_after_cast = false 40 | csharp_space_after_keywords_in_control_flow_statements = true 41 | csharp_space_between_parentheses = false 42 | csharp_space_before_colon_in_inheritance_clause = true 43 | csharp_space_after_colon_in_inheritance_clause = true 44 | csharp_space_around_binary_operators = before_and_after 45 | csharp_space_between_method_declaration_parameter_list_parentheses = false 46 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 47 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 48 | csharp_space_between_method_call_parameter_list_parentheses = false 49 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 50 | csharp_space_between_method_call_name_and_opening_parenthesis = false 51 | csharp_space_after_comma = true 52 | csharp_space_before_comma = false 53 | csharp_space_after_dot = false 54 | csharp_space_before_dot = false 55 | csharp_space_after_semicolon_in_for_statement = true 56 | csharp_space_before_semicolon_in_for_statement = false 57 | csharp_space_around_declaration_statements = false 58 | csharp_space_before_open_square_brackets = false 59 | csharp_space_between_empty_square_brackets = false 60 | csharp_space_between_square_brackets = false 61 | 62 | ### Wrap options 63 | csharp_preserve_single_line_statements = false 64 | csharp_preserve_single_line_blocks = true 65 | 66 | ### Using directive options 67 | csharp_using_directive_placement = outside_namespace : error 68 | dotnet_diagnostic.IDE0065.severity = error 69 | 70 | # Code Style Rules 71 | 72 | ## .NET Code Style 73 | 74 | dotnet_style_qualification_for_event = false : error 75 | dotnet_style_qualification_for_field = false : error 76 | dotnet_style_qualification_for_method = false : error 77 | dotnet_style_qualification_for_property = false : error 78 | dotnet_diagnostic.IDE0003.severity = error 79 | dotnet_diagnostic.IDE0009.severity = error 80 | 81 | dotnet_style_predefined_type_for_locals_parameters_members = true : error 82 | dotnet_style_predefined_type_for_member_access = true : error 83 | dotnet_diagnostic.IDE0049.severity = error 84 | 85 | dotnet_style_require_accessibility_modifiers = always : error 86 | dotnet_diagnostic.IDE0040.severity = error 87 | 88 | dotnet_style_readonly_field = true : error 89 | dotnet_diagnostic.IDE0044.severity = error 90 | 91 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity : warning 92 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity : warning 93 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : warning 94 | dotnet_style_parentheses_in_other_operators = always_for_clarity : warning 95 | dotnet_diagnostic.IDE0047.severity = warning 96 | dotnet_diagnostic.IDE0048.severity = warning 97 | 98 | dotnet_style_object_initializer = true : error 99 | dotnet_diagnostic.IDE0017.severity = error 100 | 101 | dotnet_style_explicit_tuple_names = true : error 102 | dotnet_diagnostic.IDE0033.severity = error 103 | 104 | csharp_prefer_simple_default_expression = true : error 105 | dotnet_diagnostic.IDE0034.severity = error 106 | 107 | dotnet_style_prefer_inferred_tuple_names = true : error 108 | dotnet_style_prefer_inferred_anonymous_type_member_names = true : error 109 | dotnet_diagnostic.IDE0037.severity = error 110 | 111 | dotnet_style_prefer_conditional_expression_over_assignment = true : error 112 | dotnet_diagnostic.IDE0045.severity = error 113 | 114 | dotnet_style_prefer_conditional_expression_over_return = true : silent 115 | dotnet_diagnostic.IDE0046.severity = refactoring 116 | 117 | dotnet_style_prefer_compound_assignment = true : error 118 | dotnet_diagnostic.IDE0054.severity = error 119 | dotnet_diagnostic.IDE0074.severity = error 120 | 121 | dotnet_style_prefer_simplified_boolean_expressions = true : warning 122 | dotnet_diagnostic.IDE0075.severity = warning 123 | 124 | dotnet_style_coalesce_expression = true : error 125 | dotnet_diagnostic.IDE0029.severity = error 126 | dotnet_diagnostic.IDE0030.severity = error 127 | 128 | dotnet_style_null_propagation = true : error 129 | dotnet_diagnostic.IDE0031.severity = error 130 | 131 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true : error 132 | dotnet_diagnostic.IDE0041.severity = error 133 | 134 | dotnet_style_collection_initializer = true : error 135 | dotnet_diagnostic.IDE0028.severity = error 136 | 137 | dotnet_style_prefer_auto_properties = true : warning 138 | dotnet_diagnostic.IDE0032.severity = warning 139 | 140 | dotnet_code_quality_unused_parameters = all : error 141 | dotnet_diagnostic.IDE0060.severity = error 142 | 143 | dotnet_remove_unnecessary_suppression_exclusions = none : warning 144 | dotnet_diagnostic.IDE0079.severity = warning 145 | 146 | dotnet_style_prefer_simplified_interpolation = true : error 147 | dotnet_diagnostic.IDE0071.severity = error 148 | 149 | ## Rules without Style Options 150 | 151 | # IDE0010: Add missing cases 152 | dotnet_diagnostic.IDE0010.severity = error 153 | 154 | # IDE0001: Simplify name 155 | dotnet_diagnostic.IDE0001.severity = error 156 | 157 | # IDE0002: Simplify member access 158 | dotnet_diagnostic.IDE0002.severity = error 159 | 160 | # IDE0004: Remove unnecessary cast 161 | dotnet_diagnostic.IDE0004.severity = error 162 | 163 | # IDE0005: Using directive is unnecessary. 164 | dotnet_diagnostic.IDE0005.severity = error 165 | 166 | # IDE0100: Remove redundant equality 167 | dotnet_diagnostic.IDE0100.severity = error 168 | 169 | # IDE0035: Remove unreachable code 170 | dotnet_diagnostic.IDE0035.severity = warning 171 | 172 | # IDE0051: Remove unused private member 173 | dotnet_diagnostic.IDE0051.severity = warning 174 | 175 | # IDE0052: Remove unread private member 176 | dotnet_diagnostic.IDE0052.severity = warning 177 | 178 | # IDE0058: Remove unnecessary expression value 179 | dotnet_diagnostic.IDE0058.severity = refactoring 180 | 181 | # IDE0059: Remove unnecessary value assignment 182 | dotnet_diagnostic.IDE0059.severity = warning 183 | 184 | # IDE0070: Use 'System.HashCode.Combine' 185 | dotnet_diagnostic.IDE0070.severity = error 186 | 187 | ## C# Code style 188 | 189 | csharp_style_pattern_local_over_anonymous_function = true : suggestion 190 | dotnet_diagnostic.IDE0039.severity = refactoring 191 | 192 | csharp_style_deconstructed_variable_declaration = true : warning 193 | dotnet_diagnostic.IDE0042.severity = warning 194 | 195 | csharp_style_implicit_object_creation_when_type_is_apparent = true 196 | dotnet_diagnostic.IDE0090.severity = error 197 | 198 | csharp_style_conditional_delegate_call = true : error 199 | dotnet_diagnostic.IDE1005.severity = error 200 | 201 | csharp_style_throw_expression = true : error 202 | dotnet_diagnostic.IDE0016.severity = error 203 | 204 | csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async : warning 205 | dotnet_diagnostic.IDE0036.severity = warning 206 | 207 | csharp_prefer_static_local_function = true 208 | dotnet_diagnostic.IDE0062.severity = warning 209 | 210 | csharp_style_inlined_variable_declaration = true : error 211 | dotnet_diagnostic.IDE0018.severity = error 212 | 213 | csharp_style_var_elsewhere = true : error 214 | csharp_style_var_for_built_in_types = false : error 215 | csharp_style_var_when_type_is_apparent = true : error 216 | dotnet_diagnostic.IDE0007.severity = error 217 | dotnet_diagnostic.IDE0008.severity = error 218 | 219 | csharp_style_expression_bodied_constructors = true : error 220 | dotnet_diagnostic.IDE0021.severity = error 221 | 222 | csharp_style_expression_bodied_methods = true : error 223 | dotnet_diagnostic.IDE0022.severity = error 224 | 225 | csharp_style_expression_bodied_operators = true : error 226 | dotnet_diagnostic.IDE0023.severity = error 227 | dotnet_diagnostic.IDE0024.severity = error 228 | 229 | csharp_style_expression_bodied_properties = true : error 230 | dotnet_diagnostic.IDE0025.severity = error 231 | 232 | csharp_style_expression_bodied_indexers = true : error 233 | dotnet_diagnostic.IDE0026.severity = error 234 | 235 | csharp_style_expression_bodied_accessors = true : error 236 | dotnet_diagnostic.IDE0027.severity = error 237 | 238 | csharp_style_expression_bodied_lambdas = true : error 239 | dotnet_diagnostic.IDE0053.severity = error 240 | 241 | csharp_style_expression_bodied_local_functions = true : error 242 | dotnet_diagnostic.IDE0061.severity = error 243 | 244 | csharp_style_pattern_matching_over_as_with_null_check = true : error 245 | dotnet_diagnostic.IDE0019.severity = error 246 | 247 | csharp_style_pattern_matching_over_is_with_cast_check = true : error 248 | dotnet_diagnostic.IDE0020.severity = error 249 | 250 | csharp_style_prefer_switch_expression = true : error 251 | dotnet_diagnostic.IDE0066.severity = error 252 | 253 | csharp_style_prefer_pattern_matching = true : error 254 | dotnet_diagnostic.IDE0078.severity = error 255 | 256 | csharp_style_prefer_not_pattern = true : error 257 | dotnet_diagnostic.IDE0083.severity = error 258 | 259 | csharp_prefer_braces = true : error 260 | dotnet_diagnostic.IDE0011.severity = error 261 | 262 | csharp_prefer_simple_using_statement = true : error 263 | dotnet_diagnostic.IDE0063.severity = error 264 | 265 | csharp_style_prefer_index_operator = true : warning 266 | dotnet_diagnostic.IDE0056.severity = warning 267 | 268 | csharp_style_prefer_range_operator = true : warning 269 | dotnet_diagnostic.IDE0057.severity = warning 270 | 271 | ## Rules without Style Options 272 | 273 | # IDE0050: Convert anonymous type to tuple 274 | dotnet_diagnostic.IDE0050.severity = warning 275 | 276 | # IDE0064: Make readonly fields writable 277 | dotnet_diagnostic.IDE0064.severity = error 278 | 279 | # IDE0072: Add missing cases to switch expression 280 | dotnet_diagnostic.IDE0072.severity = error 281 | 282 | # IDE0082: Convert typeof to nameof 283 | dotnet_diagnostic.IDE0082.severity = error 284 | 285 | # IDE0080: Remove unnecessary suppression operator 286 | dotnet_diagnostic.IDE0080.severity = error 287 | 288 | # IDE0110: Remove unnecessary discard 289 | dotnet_diagnostic.IDE0110.severity = warning 290 | 291 | # IDE1006: Naming Styles 292 | dotnet_diagnostic.IDE1006.severity = error 293 | 294 | # Naming Conventions 295 | dotnet_naming_symbols.const_field_symbols.applicable_kinds = field 296 | dotnet_naming_symbols.const_field_symbols.required_modifiers = const 297 | dotnet_naming_symbols.const_field_symbols.applicable_accessibilities = * 298 | dotnet_naming_style.const_field_symbols.capitalization = pascal_case 299 | 300 | dotnet_naming_rule.const_fields_must_be_pascal_case.severity = error 301 | dotnet_naming_rule.const_fields_must_be_pascal_case.symbols = const_field_symbols 302 | dotnet_naming_rule.const_fields_must_be_pascal_case.style = const_field_symbols 303 | 304 | dotnet_naming_symbols.private_field_symbol.applicable_kinds = field 305 | dotnet_naming_symbols.private_field_symbol.applicable_accessibilities = private 306 | dotnet_naming_style.private_field_style.capitalization = camel_case 307 | dotnet_naming_rule.private_fields_are_camel_case.severity = warning 308 | dotnet_naming_rule.private_fields_are_camel_case.symbols = private_field_symbol 309 | dotnet_naming_rule.private_fields_are_camel_case.style = private_field_style 310 | 311 | dotnet_naming_symbols.non_private_field_symbol.applicable_kinds = field 312 | dotnet_naming_symbols.non_private_field_symbol.applicable_accessibilities = public,internal,friend,protected,protected_internal,protected_friend 313 | dotnet_naming_style.non_private_field_style.capitalization = pascal_case 314 | dotnet_naming_rule.non_private_fields_are_pascal_case.severity = warning 315 | dotnet_naming_rule.non_private_fields_are_pascal_case.symbols = non_private_field_symbol 316 | dotnet_naming_rule.non_private_fields_are_pascal_case.style = non_private_field_style 317 | 318 | dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter 319 | dotnet_naming_style.parameter_style.capitalization = camel_case 320 | dotnet_naming_rule.parameters_are_camel_case.severity = warning 321 | dotnet_naming_rule.parameters_are_camel_case.symbols = parameter_symbol 322 | dotnet_naming_rule.parameters_are_camel_case.style = parameter_style 323 | 324 | dotnet_naming_symbols.non_interface_type_symbol.applicable_kinds = class,struct,enum,delegate 325 | dotnet_naming_style.non_interface_type_style.capitalization = pascal_case 326 | dotnet_naming_rule.non_interface_types_are_pascal_case.severity = error 327 | dotnet_naming_rule.non_interface_types_are_pascal_case.symbols = non_interface_type_symbol 328 | dotnet_naming_rule.non_interface_types_are_pascal_case.style = non_interface_type_style 329 | 330 | dotnet_naming_symbols.interface_type_symbol.applicable_kinds = interface 331 | dotnet_naming_style.interface_type_style.capitalization = pascal_case 332 | dotnet_naming_style.interface_type_style.required_prefix = I 333 | dotnet_naming_rule.interface_types_must_be_prefixed_with_I.severity = error 334 | dotnet_naming_rule.interface_types_must_be_prefixed_with_I.symbols = interface_type_symbol 335 | dotnet_naming_rule.interface_types_must_be_prefixed_with_I.style = interface_type_style 336 | 337 | dotnet_naming_symbols.member_symbol.applicable_kinds = method,property,event 338 | dotnet_naming_style.member_style.capitalization = pascal_case 339 | dotnet_naming_rule.members_are_pascal_case.severity = error 340 | dotnet_naming_rule.members_are_pascal_case.symbols = member_symbol 341 | dotnet_naming_rule.members_are_pascal_case.style = member_style 342 | 343 | # Prefer file scoped namespace, severity error 344 | csharp_style_namespace_declarations = file_scoped:error -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [KyleMcMaster] -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "monthly" 12 | open-pull-requests-limit: 10 13 | -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: .NET Build and Test 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v2 18 | with: 19 | dotnet-version: 6.0.x 20 | - name: Restore dependencies 21 | run: dotnet restore 22 | - name: Build 23 | run: dotnet build --no-restore 24 | - name: Test 25 | run: dotnet test --no-build --verbosity normal 26 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: 'Release: Publish to NuGet' 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | reason: 7 | description: 'The reason for running the workflow' 8 | required: true 9 | default: 'Manual run' 10 | 11 | jobs: 12 | createArtifacts: 13 | name: Generate NuGet Packages 14 | runs-on: ubuntu-latest 15 | env: 16 | PROJECT_PATH: './src/CSharpFunctionalExtensions.FluentAssertions/CSharpFunctionalExtensions.FluentAssertions.csproj' 17 | 18 | steps: 19 | - uses: actions/checkout@v3 20 | 21 | #- name: Set Environment Variables 22 | # uses: ./.github/actions/set-env 23 | 24 | - uses: actions/checkout@v2 25 | 26 | - name: Setup dotnet 27 | uses: actions/setup-dotnet@v2 28 | with: 29 | dotnet-version: 6.0.x 30 | 31 | - name: Install dependencies 32 | run: dotnet restore 33 | 34 | - name: Build 35 | run: dotnet build -c Release --no-restore 36 | 37 | - name: Create PreRelease Artifact 38 | run: dotnet pack ${{ env.PROJECT_PATH }} -c Release --no-build --include-symbols -o ./artifacts/prerelease --version-suffix prerelease-$GITHUB_RUN_NUMBER-$GITHUB_RUN_ATTEMPT 39 | 40 | - name: 'Save prerelease artifact' 41 | uses: actions/upload-artifact@v4 42 | with: 43 | name: prerelease 44 | path: ./artifacts/prerelease/* 45 | 46 | - name: Create Release Artifact 47 | run: dotnet pack ${{ env.PROJECT_PATH }} -c Release --no-build --include-symbols -o ./artifacts/release 48 | 49 | - name: 'Save release artifact' 50 | uses: actions/upload-artifact@v4 51 | with: 52 | name: release 53 | path: ./artifacts/release/* 54 | 55 | publishPreRelease: 56 | name: Publish PreRelease NuGet Package 57 | environment: prerelease 58 | needs: createArtifacts 59 | runs-on: ubuntu-latest 60 | steps: 61 | - name: Download artifact 62 | uses: actions/download-artifact@v4 63 | with: 64 | name: prerelease 65 | 66 | - name: Publish NuGet Package 67 | run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} 68 | 69 | publishRelease: 70 | name: Publish Release NuGet Package 71 | environment: release 72 | needs: [createArtifacts, publishPreRelease] 73 | runs-on: ubuntu-latest 74 | steps: 75 | - name: Download artifact 76 | uses: actions/download-artifact@v4 77 | with: 78 | name: release 79 | 80 | - name: Publish NuGet Package 81 | run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": true, 4 | "**/.svn": true, 5 | "**/.hg": true, 6 | "**/CVS": true, 7 | "**/.DS_Store": true 8 | }, 9 | 10 | "search.exclude": { 11 | "**/node_modules": true, 12 | "**/bower_components": true, 13 | "**/*.code-search": true, 14 | "**/bin": true, 15 | "**/obj": true 16 | }, 17 | "omnisharp.useEditorFormattingSettings": true, 18 | "dotnet.defaultSolution": "CSharpFunctionalExtensions.FluentAssertions.sln", 19 | "dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true 20 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "command": "dotnet", 9 | "type": "shell", 10 | "args": [ 11 | "build", 12 | // Ask dotnet build to generate full paths for file names. 13 | "/property:GenerateFullPaths=true", 14 | // Do not generate summary otherwise it leads to duplicate errors in Problems panel 15 | "/consoleloggerparameters:NoSummary" 16 | ], 17 | "group": "build", 18 | "presentation": { 19 | "reveal": "silent" 20 | }, 21 | "problemMatcher": "$msCompile" 22 | }, 23 | 24 | { 25 | "label": "restore", 26 | "command": "dotnet", 27 | "type": "shell", 28 | "args": ["restore"], 29 | "group": "build", 30 | "presentation": { 31 | "reveal": "silent" 32 | }, 33 | "problemMatcher": "$msCompile" 34 | }, 35 | 36 | { 37 | "label": "clean", 38 | "command": "dotnet", 39 | "type": "shell", 40 | "args": ["clean"], 41 | "group": "build", 42 | "presentation": { 43 | "reveal": "silent" 44 | }, 45 | "problemMatcher": "$msCompile" 46 | } 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [INSERT CONTACT METHOD]. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | 135 | -------------------------------------------------------------------------------- /CSharpFunctionalExtensions.FluentAssertions.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D26F7D3F-2856-4D6E-8C7D-EDEE24A1EABE}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpFunctionalExtensions.FluentAssertions", "src\CSharpFunctionalExtensions.FluentAssertions\CSharpFunctionalExtensions.FluentAssertions.csproj", "{E35A4F87-8CAE-463E-9375-1FC0D2C5244E}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpFunctionalExtensions.FluentAssertions.Tests", "tests\CSharpFunctionalExtensions.FluentAssertions.Tests\CSharpFunctionalExtensions.FluentAssertions.Tests.csproj", "{37BC9486-168F-445E-A655-01119763C63B}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E390A936-6E5C-422A-95DC-00F46739BD4E}" 13 | ProjectSection(SolutionItems) = preProject 14 | .editorconfig = .editorconfig 15 | .gitignore = .gitignore 16 | LICENSE = LICENSE 17 | README.md = README.md 18 | EndProjectSection 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{5A7E4E59-DF1A-4670-AD80-EA61E910A40B}" 21 | ProjectSection(SolutionItems) = preProject 22 | Directory.Build.props = Directory.Build.props 23 | Directory.Build.targets = Directory.Build.targets 24 | README.md = README.md 25 | EndProjectSection 26 | EndProject 27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2678B648-43F9-4FAA-917E-0D1F88FCA7AD}" 28 | EndProject 29 | Global 30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 31 | Debug|Any CPU = Debug|Any CPU 32 | Release|Any CPU = Release|Any CPU 33 | EndGlobalSection 34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 35 | {E35A4F87-8CAE-463E-9375-1FC0D2C5244E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {E35A4F87-8CAE-463E-9375-1FC0D2C5244E}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {E35A4F87-8CAE-463E-9375-1FC0D2C5244E}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {E35A4F87-8CAE-463E-9375-1FC0D2C5244E}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {37BC9486-168F-445E-A655-01119763C63B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {37BC9486-168F-445E-A655-01119763C63B}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {37BC9486-168F-445E-A655-01119763C63B}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {37BC9486-168F-445E-A655-01119763C63B}.Release|Any CPU.Build.0 = Release|Any CPU 43 | EndGlobalSection 44 | GlobalSection(SolutionProperties) = preSolution 45 | HideSolutionNode = FALSE 46 | EndGlobalSection 47 | GlobalSection(NestedProjects) = preSolution 48 | {E35A4F87-8CAE-463E-9375-1FC0D2C5244E} = {D26F7D3F-2856-4D6E-8C7D-EDEE24A1EABE} 49 | {37BC9486-168F-445E-A655-01119763C63B} = {2678B648-43F9-4FAA-917E-0D1F88FCA7AD} 50 | EndGlobalSection 51 | GlobalSection(ExtensibilityGlobals) = postSolution 52 | SolutionGuid = {5F46ABAA-BCF2-49FC-8A58-35A3A9A5121E} 53 | EndGlobalSection 54 | EndGlobal 55 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NitroDevs 6 | $(Company) 7 | Copyright © $(Company) $([System.DateTime]::Now.Year) 8 | $(Company)™ 9 | 3.0.0 10 | CSharpFunctionalExtensions.FluentAssertions 11 | $(Product) 12 | MIT 13 | https://github.com/NitroDevs/CSharpFunctionalExtensions.FluentAssertions 14 | nitro-devs-logo.png 15 | README.md 16 | Monad;FluentAssertions;CSharpFunctionalExtensions;Testing 17 | https://github.com/NitroDevs/CSharpFunctionalExtensions.FluentAssertions/releases 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | 1591 28 | 29 | 30 | 31 | true 32 | true 33 | true 34 | true 35 | snupkg 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2025 NitroDevs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSharpFunctionalExtensions.FluentAssertions 2 | 3 | - [![NuGet Package](https://img.shields.io/nuget/v/CSharpFunctionalExtensions.FluentAssertions.svg)](https://www.nuget.org/packages/CSharpFunctionalExtensions.FluentAssertions) **CSharpFunctionalExtensions.FluentAssertions** 4 | 5 | A small set of extensions to make test assertions more fluent when using CSharpFunctionalExtensions! Wow! 6 | 7 | ## Star History 8 | 9 | 10 | 11 | 12 | 13 | Star History Chart 14 | 15 | 16 | 17 | ## Learn More 18 | 19 | * [Announcing CSharpFunctionalExtensions.FluentAssertions](https://www.kylemcmaster.com/blog/announcing-csharpfunctionalextensions-fluentassertions) 20 | 21 | ## Dependencies 22 | 23 | This library is compatible with .NET 6+. It requires the following minimum package versions: 24 | 25 | CSharpFunctionalExtensons >= 3.0.0 26 | 27 | FluentAssertions >= 7.2.0 28 | 29 | ## Installation 30 | 31 | This library is available on Nuget and can be installed with the .NET CLI using the following command: 32 | 33 | ```bash 34 | dotnet add package CSharpFunctionalExtensions.FluentAssertions 35 | ``` 36 | 37 | ## Usage 38 | 39 | ### Maybe Assertions 40 | 41 | ```csharp 42 | var maybe = Maybe.From("foo"); 43 | 44 | maybe.Should().HaveSomeValue(); // passes 45 | maybe.Should().HaveValue("foo"); // passes 46 | maybe.Should().HaveValue("bar"); // throws 47 | maybe.Should().HaveNoValue(); // throws 48 | ``` 49 | 50 | ```csharp 51 | Maybe maybe = null; 52 | 53 | maybe.Should().HaveNoValue(); // passes 54 | maybe.Should().HaveValue("foo"); // throws 55 | ``` 56 | 57 | ### Result Assertions 58 | 59 | ```csharp 60 | var result = Result.Success(); 61 | 62 | result.Should().Succeed(); // passes 63 | result.Should().Fail() // throws 64 | ``` 65 | 66 | ```csharp 67 | var result = Result.Failure("error"); 68 | 69 | result.Should().Fail() // passes 70 | result.Should().FailWith("error"); // passes 71 | result.Should().FailWith("some other error"); // throws 72 | result.Should().Succeed(); // throws 73 | ``` 74 | 75 | ### Generic Result of T Assertions 76 | 77 | ```csharp 78 | var result = Result.Success(420); 79 | 80 | result.Should().Succeed(); // passes 81 | result.Should().SucceedWith(420); // passes 82 | result.Should().SucceedWith(69); // throws 83 | result.Should().Fail(); // throws 84 | ``` 85 | 86 | ```csharp 87 | var result = Result.Failure("error"); 88 | 89 | result.Should().Fail() // passes 90 | result.Should().FailWith("error"); // passes 91 | result.Should().FailWith("some other error"); // throws 92 | result.Should().Succeed(); // throws 93 | ``` 94 | 95 | ### Generic Result of T:Value and E:Error Assertions 96 | 97 | ```csharp 98 | var result = Result.Success(420); 99 | 100 | result.Should().Succeed(); // passes 101 | result.Should().SucceedWith(420); // passes 102 | result.Should().SucceedWith(69); // throws 103 | result.Should().Fail(); // throws 104 | result.Should().FailWith(new Exception("error")); // throws 105 | ``` 106 | 107 | ```csharp 108 | var result = Result.Failure(new Exception("error")); 109 | 110 | result.Should().Fail(); // passes 111 | result.Should().FailWith(new Exception("error")); // passes 112 | result.Should().FailWith(new Exception("some other error")); // throws 113 | result.Should().Succeed(); // throws 114 | result.Should().SucceedWith(4680); // throws 115 | ``` 116 | 117 | ### UnitResult Assertions 118 | 119 | ```csharp 120 | var result = UnitResult.Success(); 121 | 122 | result.Should().Succeed(); // passes 123 | result.Should().Fail(); // throws 124 | result.Should().FailWith("error"); // throws 125 | ``` 126 | 127 | ```csharp 128 | var result = UnitResult.Failure("error"); 129 | 130 | result.Should().Fail(); // passes 131 | result.Should().FailWith("error"); // passes 132 | result.Should().Succeed(); // throws 133 | ``` 134 | 135 | ## Related Projects 136 | 137 | * [CSharpFunctionalExtensions](https://github.com/vkhorikov/CSharpFunctionalExtensions) 138 | * [FluentAssertions.CSharpFunctionalExtensions](https://github.com/pedromtcosta/FluentAssertions.CSharpFunctionalExtensions) 139 | * [Typescript Functional Extensions](https://github.com/seangwright/typescript-functional-extensions) 140 | 141 | ## Acknowledgements 142 | 143 | Special thanks to [Sean Wright](https://github.com/seangwright) for all his guidance and contributions over the design, development, and release of this project. His insights are invaluable! :smile: 144 | -------------------------------------------------------------------------------- /images/nitro-devs-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NitroDevs/CSharpFunctionalExtensions.FluentAssertions/9da951c2fb54c5477d4f94fb92187e2165209a34/images/nitro-devs-logo.png -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/CSharpFunctionalExtensions.FluentAssertions.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | enable 6 | 7 | This package provides a set of extensions to FluentAssertions to simplify the testing of project using CSharpFunctionalExtensions 8 | 9 | 10 | CSharpFunctionalExtensions.FluentAssertions 11 | $(Product) 12 | $(PackageTags) 13 | FluentAssertions 14 | 15 | 16 | 17 | 18 | 19 | 20 | all 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/MaybeExtensions.cs: -------------------------------------------------------------------------------- 1 | using CSharpFunctionalExtensions; 2 | using FluentAssertions.Execution; 3 | using FluentAssertions.Primitives; 4 | 5 | namespace FluentAssertions; 6 | 7 | public static class MaybeExtensions 8 | { 9 | public static MaybeAssertions Should(this Maybe instance) => new(instance); 10 | } 11 | 12 | public class MaybeAssertions : ReferenceTypeAssertions, MaybeAssertions> 13 | { 14 | public MaybeAssertions(Maybe instance) : base(instance) { } 15 | 16 | protected override string Identifier => "Maybe{T}"; 17 | 18 | /// 19 | /// Asserts that the current has some value. 20 | /// 21 | /// 22 | /// 23 | /// 24 | public AndWhichConstraint, T> HaveSomeValue(string because = "", params object[] becauseArgs) 25 | { 26 | Execute.Assertion 27 | .BecauseOf(because, becauseArgs) 28 | .Given(() => Subject) 29 | .ForCondition(v => v.HasValue) 30 | .FailWith("Expected a value {reason}"); 31 | 32 | return new AndWhichConstraint, T>(this, Subject.Value); 33 | } 34 | 35 | /// 36 | /// Asserts that the current has a value. 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | public AndWhichConstraint, T> HaveValue(T value, string because = "", params object[] becauseArgs) 43 | { 44 | Execute.Assertion 45 | .BecauseOf(because, becauseArgs) 46 | .Given(() => Subject) 47 | .ForCondition(v => v.HasValue) 48 | .FailWith( 49 | "Expected a value {0}{reason}", 50 | _ => value) 51 | .Then 52 | .Given(s => s.Value) 53 | .ForCondition(v => v!.Equals(value)) 54 | .FailWith( 55 | "Expected {context:maybe} to have value {0}{reason}, but with value {1} it", 56 | _ => value, 57 | v => v); 58 | 59 | return new AndWhichConstraint, T>(this, Subject.Value); 60 | } 61 | 62 | /// 63 | /// Asserts that the current has no value. 64 | /// 65 | /// 66 | /// 67 | /// 68 | public AndConstraint> HaveNoValue(string because = "", params object[] becauseArgs) 69 | { 70 | Execute.Assertion 71 | .BecauseOf(because, becauseArgs) 72 | .Given(() => Subject) 73 | .ForCondition(v => v.HasNoValue) 74 | .FailWith( 75 | "Expected {context:maybe} to have no value{reason}, but with value {0} it", 76 | v => v.HasNoValue ? default : v.Value); 77 | 78 | return new AndConstraint>(this); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/ResultExtensions.cs: -------------------------------------------------------------------------------- 1 | using CSharpFunctionalExtensions; 2 | using FluentAssertions.Execution; 3 | using FluentAssertions.Primitives; 4 | 5 | namespace FluentAssertions; 6 | 7 | public static class ResultExtensions 8 | { 9 | public static ResultAssertions Should(this Result instance) => new(instance); 10 | } 11 | 12 | public class ResultAssertions : ReferenceTypeAssertions 13 | { 14 | public ResultAssertions(Result instance) : base(instance) { } 15 | 16 | protected override string Identifier => "Result"; 17 | 18 | /// 19 | /// Asserts a result is a success. 20 | /// 21 | /// 22 | /// 23 | /// 24 | public AndConstraint Succeed(string because = "", params object[] becauseArgs) 25 | { 26 | Execute.Assertion 27 | .BecauseOf(because, becauseArgs) 28 | .ForCondition(Subject.IsSuccess) 29 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")); 30 | 31 | return new AndConstraint(this); 32 | } 33 | 34 | /// 35 | /// Asserts a result is a failure. 36 | /// 37 | /// 38 | /// 39 | /// 40 | public AndWhichConstraint Fail(string because = "", params object[] becauseArgs) 41 | { 42 | Execute.Assertion 43 | .BecauseOf(because, becauseArgs) 44 | .ForCondition(Subject.IsFailure) 45 | .FailWith(() => new FailReason($"Expected {{context:result}} to fail{{reason}}, but it succeeded")); 46 | 47 | return new AndWhichConstraint(this, Subject.Error); 48 | } 49 | 50 | /// 51 | /// Asserts a result is a failure with a specified error. 52 | /// 53 | /// 54 | /// 55 | /// 56 | /// 57 | public AndWhichConstraint FailWith(string error, string because = "", params object[] becauseArgs) 58 | { 59 | Execute.Assertion 60 | .BecauseOf(because, becauseArgs) 61 | .Given(() => Subject.IsFailure) 62 | .ForCondition(b => Subject.Error!.Equals(error)) 63 | .FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error); 64 | 65 | return new AndWhichConstraint(this, Subject.Error); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/ResultTEExtensions.cs: -------------------------------------------------------------------------------- 1 | using CSharpFunctionalExtensions; 2 | using FluentAssertions.Execution; 3 | using FluentAssertions.Primitives; 4 | 5 | namespace FluentAssertions; 6 | public static class ResultTEExtensions 7 | { 8 | public static ResultTEAssertions Should(this Result instance) => new(instance); 9 | } 10 | 11 | public class ResultTEAssertions : ReferenceTypeAssertions, ResultTEAssertions> 12 | { 13 | public ResultTEAssertions(Result instance) : base(instance) { } 14 | 15 | protected override string Identifier => "Result{T}"; 16 | 17 | /// 18 | /// Asserts a result is a success. 19 | /// 20 | /// 21 | /// 22 | /// 23 | public AndWhichConstraint, T> Succeed(string because = "", params object[] becauseArgs) 24 | { 25 | Execute.Assertion 26 | .BecauseOf(because, becauseArgs) 27 | .ForCondition(Subject.IsSuccess) 28 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")); 29 | 30 | return new AndWhichConstraint, T>(this, Subject.Value); 31 | } 32 | 33 | /// 34 | /// Asserts a result is a success with a specified value. 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | public AndWhichConstraint, T> SucceedWith(T value, string because = "", params object[] becauseArgs) 41 | { 42 | Execute.Assertion 43 | .BecauseOf(because, becauseArgs) 44 | .ForCondition(Subject.IsSuccess) 45 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")) 46 | .Then 47 | .Given(() => Subject.Value) 48 | .ForCondition(v => v!.Equals(value)) 49 | .FailWith("Expected {context:result} value to be {0}, but found {1}", value, Subject.Value); 50 | 51 | return new AndWhichConstraint, T>(this, Subject.Value); 52 | } 53 | 54 | /// 55 | /// Asserts a result is a failure. 56 | /// 57 | /// 58 | /// 59 | /// 60 | public AndWhichConstraint, E> Fail(string because = "", params object[] becauseArgs) 61 | { 62 | Execute.Assertion 63 | .BecauseOf(because, becauseArgs) 64 | .ForCondition(Subject.IsFailure) 65 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to fail, but it succeeded with value ""{Subject.Value}""")); 66 | 67 | return new AndWhichConstraint, E>(this, Subject.Error); 68 | } 69 | 70 | /// 71 | /// Asserts a result is a failure with a specified error. 72 | /// 73 | /// 74 | /// 75 | /// 76 | /// 77 | public AndWhichConstraint, E> FailWith(E error, string because = "", params object[] becauseArgs) 78 | { 79 | Execute.Assertion 80 | .BecauseOf(because, becauseArgs) 81 | .ForCondition(Subject.IsFailure) 82 | .FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded")) 83 | .Then 84 | .Given(() => Subject.Error) 85 | .ForCondition(e => e!.Equals(error)) 86 | .FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error); 87 | 88 | return new AndWhichConstraint, E>(this, Subject.Error); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/ResultTExtensions.cs: -------------------------------------------------------------------------------- 1 | using CSharpFunctionalExtensions; 2 | using FluentAssertions.Execution; 3 | using FluentAssertions.Primitives; 4 | 5 | namespace FluentAssertions; 6 | 7 | public static class ResultTExtensions 8 | { 9 | public static ResultTAssertions Should(this Result instance) => new(instance); 10 | } 11 | 12 | public class ResultTAssertions : ReferenceTypeAssertions, ResultTAssertions> 13 | { 14 | public ResultTAssertions(Result instance) : base(instance) { } 15 | 16 | protected override string Identifier => "Result{T}"; 17 | 18 | /// 19 | /// Asserts a result is a success. 20 | /// 21 | /// 22 | /// 23 | /// 24 | public AndWhichConstraint, T> Succeed(string because = "", params object[] becauseArgs) 25 | { 26 | Execute.Assertion 27 | .BecauseOf(because, becauseArgs) 28 | .ForCondition(Subject.IsSuccess) 29 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")); 30 | 31 | return new AndWhichConstraint, T>(this, Subject.Value); 32 | } 33 | 34 | /// 35 | /// Asserts a result is a success with a specified value. 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | public AndWhichConstraint, T> SucceedWith(T value, string because = "", params object[] becauseArgs) 42 | { 43 | Execute.Assertion 44 | .BecauseOf(because, becauseArgs) 45 | .ForCondition(Subject.IsSuccess) 46 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")) 47 | .Then 48 | .Given(() => Subject.Value) 49 | .ForCondition(v => v!.Equals(value)) 50 | .FailWith($"Expected {{context:result}} value to be {{0}}, but found {{1}}", value, Subject.Value); 51 | 52 | return new AndWhichConstraint, T>(this, Subject.Value); 53 | } 54 | 55 | /// 56 | /// Asserts a result is a failure. 57 | /// 58 | /// 59 | /// 60 | /// 61 | public AndWhichConstraint, string> Fail(string because = "", params object[] becauseArgs) 62 | { 63 | Execute.Assertion 64 | .BecauseOf(because, becauseArgs) 65 | .ForCondition(Subject.IsFailure) 66 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to fail, but it succeeded with value ""{Subject.Value}""")); 67 | 68 | return new AndWhichConstraint, string>(this, Subject.Error); 69 | } 70 | 71 | /// 72 | /// Asserts a result is a failure with a specified error. 73 | /// 74 | /// 75 | /// 76 | /// 77 | /// 78 | public AndWhichConstraint, string> FailWith(string error, string because = "", params object[] becauseArgs) 79 | { 80 | Execute.Assertion 81 | .BecauseOf(because, becauseArgs) 82 | .Given(() => Subject.IsFailure) 83 | .ForCondition(b => Subject.Error!.Equals(error)) 84 | .FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error); 85 | 86 | return new AndWhichConstraint, string>(this, Subject.Error); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/CSharpFunctionalExtensions.FluentAssertions/UnitResultExtensions.cs: -------------------------------------------------------------------------------- 1 | using CSharpFunctionalExtensions; 2 | using FluentAssertions.Execution; 3 | using FluentAssertions.Primitives; 4 | 5 | namespace FluentAssertions; 6 | public static class UnitResultExtensions 7 | { 8 | public static UnitResultAssertions Should(this UnitResult instance) => new(instance); 9 | } 10 | 11 | public class UnitResultAssertions : ReferenceTypeAssertions, UnitResultAssertions> 12 | { 13 | public UnitResultAssertions(UnitResult instance) : base(instance) { } 14 | 15 | protected override string Identifier => "Result"; 16 | 17 | /// 18 | /// Asserts a UnitResult is a success. 19 | /// 20 | /// 21 | /// 22 | /// 23 | public AndConstraint> Succeed(string because = "", params object[] becauseArgs) 24 | { 25 | Execute.Assertion 26 | .BecauseOf(because, becauseArgs) 27 | .ForCondition(Subject.IsSuccess) 28 | .FailWith(() => new FailReason(@$"Expected {{context:result}} to succeed{{reason}}, but it failed with error ""{Subject.Error}""")); 29 | 30 | return new AndConstraint>(this); 31 | } 32 | 33 | /// 34 | /// Asserts a UnitResult is a failure. 35 | /// 36 | /// 37 | /// 38 | /// 39 | public AndWhichConstraint, E> Fail(string because = "", params object[] becauseArgs) 40 | { 41 | Execute.Assertion 42 | .BecauseOf(because, becauseArgs) 43 | .ForCondition(Subject.IsFailure) 44 | .FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded")); 45 | 46 | return new AndWhichConstraint, E>(this, Subject.Error); 47 | } 48 | 49 | /// 50 | /// Asserts a UnitResult is a failure with a specified error. 51 | /// 52 | /// 53 | /// 54 | /// 55 | /// 56 | public AndWhichConstraint, E> FailWith(E error, string because = "", params object[] becauseArgs) 57 | { 58 | Execute.Assertion 59 | .BecauseOf(because, becauseArgs) 60 | .ForCondition(Subject.IsFailure) 61 | .FailWith(() => new FailReason($"Expected {{context:result}} to fail, but it succeeded")) 62 | .Then 63 | .Given(() => Subject.Error) 64 | .ForCondition(e => e!.Equals(error)) 65 | .FailWith($"Expected {{context:result}} error to be {{0}}, but found {{1}}", error, Subject.Error); 66 | 67 | return new AndWhichConstraint, E>(this, Subject.Error); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/CSharpFunctionalExtensions.FluentAssertions.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | all 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/MaybeAssertionsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Xunit; 4 | 5 | namespace CSharpFunctionalExtensions.FluentAssertions.Tests; 6 | 7 | public class MaybeAssertionsTests 8 | { 9 | [Fact] 10 | public void WhenMaybeIsExpectedToHaveSomeValueAndItDoesShouldNotThrow() 11 | { 12 | var maybe = Maybe.From("test"); 13 | 14 | maybe.Should().HaveSomeValue(); 15 | maybe.Should().HaveSomeValue().Which.Should().Be("test"); 16 | } 17 | 18 | [Fact] 19 | public void WhenMaybeIsExpectedToHaveValueAndItDoesShouldNotThrow() 20 | { 21 | var maybe = Maybe.From("test"); 22 | 23 | maybe.Should().HaveValue("test"); 24 | maybe.Should().HaveValue("test").Which.Should().HaveLength(4); 25 | } 26 | 27 | [Fact] 28 | public void WhenMaybeIsExpectedToHaveValueAndItHasWrongValueShouldThrow() 29 | { 30 | var maybe = Maybe.From("oops"); 31 | 32 | var act = () => maybe.Should().HaveValue("test", "it is test"); 33 | 34 | act.Should().Throw().WithMessage($"*value \"test\" because it is test, but with value \"oops\" it*"); 35 | } 36 | 37 | [Fact] 38 | public void WhenMaybeIsExpectedToHaveValueAndItDoesNotShouldThrow() 39 | { 40 | Maybe maybe = null; 41 | 42 | var act = () => maybe.Should().HaveValue("test", "it is not None"); 43 | 44 | act.Should().Throw().WithMessage($"*value \"test\" because it is not None*"); 45 | } 46 | 47 | [Fact] 48 | public void WhenMaybeIsExpectedToHaveNoValueAndItHasNoneShouldNotThrow() 49 | { 50 | Maybe maybe = null; 51 | 52 | maybe.Should().HaveNoValue(); 53 | } 54 | 55 | [Fact] 56 | public void WhenMaybeIsExpectedToHaveNoValueAndItHasOneShouldThrow() 57 | { 58 | var maybe = Maybe.From("test"); 59 | 60 | var act = () => maybe.Should().HaveNoValue("it is None"); 61 | 62 | act.Should().Throw().WithMessage($"*Maybe to have no value because it is None, but with value \"test\" it*"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/ResultAssertionTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Xunit.Sdk; 3 | using FluentAssertions; 4 | 5 | namespace CSharpFunctionalExtensions.FluentAssertions.Tests; 6 | 7 | public class ResultAssertionTests 8 | { 9 | [Fact] 10 | public void WhenResultIsExpectedToHaveValueItShouldBeSuccessful() 11 | { 12 | var result = Result.Success(); 13 | 14 | result.Should().Succeed(); 15 | } 16 | 17 | [Fact] 18 | public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure() 19 | { 20 | var result = Result.Success(); 21 | 22 | var action = () => result.Should().Fail(); 23 | 24 | action.Should().Throw().WithMessage($"Expected {nameof(result)} to fail, but it succeeded"); 25 | } 26 | 27 | [Fact] 28 | public void WhenResultIsExpectedToHaveErrorFailShouldNotThrow() 29 | { 30 | string error = "error"; 31 | var result = Result.Failure(error); 32 | 33 | result.Should().Fail(); 34 | result.Should().FailWith(error); 35 | 36 | result.Should().Fail().Which.Should().Be(error); 37 | result.Should().FailWith(error).Which.Should().Be(error); 38 | } 39 | 40 | [Fact] 41 | public void WhenResultIsExpectedToHaveErrorSucceedShouldThrow() 42 | { 43 | var result = Result.Failure("error"); 44 | 45 | var action = () => result.Should().Succeed(); 46 | 47 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""error"""); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/ResultTAssertionsTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Xunit; 3 | using Xunit.Sdk; 4 | 5 | namespace CSharpFunctionalExtensions.FluentAssertions.Tests; 6 | 7 | public class ResultAssertionsTests 8 | { 9 | [Fact] 10 | public void WhenResultIsExpectedToHaveValueItShouldBeSuccessful() 11 | { 12 | var result = Result.Success("test"); 13 | 14 | result.Should().Succeed(); 15 | result.Should().Succeed().Which.Should().Be("test"); 16 | } 17 | 18 | [Fact] 19 | public void WhenResultIsExpectedToHaveValueItShouldNotBeFailure() 20 | { 21 | var result = Result.Success("test"); 22 | 23 | var action = () => result.Should().Fail(); 24 | 25 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded with value ""test"""); 26 | } 27 | 28 | [Fact] 29 | public void WhenResultIsExpectedToHaveValueItShouldBeSuccessfulWithValue() 30 | { 31 | string expected = "test"; 32 | var result = Result.Success(expected); 33 | 34 | result.Should().SucceedWith(expected); 35 | result.Should().SucceedWith(expected).Which.Should().HaveLength(4); 36 | } 37 | 38 | [Fact] 39 | public void WhenResultIsExpectedToHaveValueItShouldNotBeSuccessfulWithDifferentValue() 40 | { 41 | var result = Result.Success("foo"); 42 | 43 | var action = () => result.Should().SucceedWith("bar"); 44 | 45 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} value to be ""bar"", but found ""foo"""); 46 | } 47 | 48 | [Fact] 49 | public void WhenResultIsExpectedToHaveErrorFailShouldNotThrow() 50 | { 51 | string error = "error"; 52 | var result = Result.Failure(error); 53 | 54 | result.Should().Fail(); 55 | result.Should().FailWith(error); 56 | result.Should().Fail().Which.Should().Be(error); 57 | result.Should().FailWith(error).Which.Should().HaveLength(5); 58 | } 59 | 60 | [Fact] 61 | public void WhenResultIsExpectedToHaveErrorSucceedShouldThrow() 62 | { 63 | var result = Result.Failure("error"); 64 | 65 | var action = () => result.Should().Succeed(); 66 | 67 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""error"""); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/ResultTEAssertionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Xunit; 4 | using Xunit.Sdk; 5 | 6 | namespace CSharpFunctionalExtensions.FluentAssertions.Tests; 7 | public class ResultTEAssertionTests 8 | { 9 | [Fact] 10 | public void WhenResultIsExpectedToBeSuccessItShouldBeSuccess() 11 | { 12 | string value = "value"; 13 | var result = Result.Success(value); 14 | 15 | var action = () => result.Should().Succeed(); 16 | 17 | action.Should().NotThrow(); 18 | result.Should().Succeed().Which.Should().Be(value); 19 | } 20 | 21 | [Fact] 22 | public void WhenResultIsExpectedToBeSuccessWithValueItShouldBeSuccessWithValue() 23 | { 24 | string value = "value"; 25 | var result = Result.Success(value); 26 | 27 | result.Should().SucceedWith(value); 28 | result.Should().SucceedWith(value).Which.Should().Be(value); 29 | } 30 | 31 | [Fact] 32 | public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure() 33 | { 34 | var error = new Exception("error"); 35 | var result = Result.Failure(error); 36 | 37 | var action = () => result.Should().Succeed(); 38 | 39 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""System.Exception: error"""); 40 | } 41 | 42 | [Fact] 43 | public void WhenResultIsExpectedToBeSuccessWithValueItShouldThrowWhenSuccessWithDifferentValue() 44 | { 45 | string value = "value"; 46 | var result = Result.Success(value); 47 | 48 | var action = () => result.Should().SucceedWith("some other value"); 49 | 50 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} value to be ""some other value"", but found ""value"""); 51 | } 52 | 53 | [Fact] 54 | public void WhenResultIsExpectedToBeFailureItShouldBeFailure() 55 | { 56 | var error = new Exception("error"); 57 | var result = Result.Failure(error); 58 | 59 | var action = () => result.Should().Fail(); 60 | var actionWith = () => result.Should().FailWith(error); 61 | 62 | action.Should().NotThrow(); 63 | actionWith.Should().NotThrow(); 64 | result.Should().Fail().Which.Should().Be(error); 65 | result.Should().FailWith(error).Which.Should().Be(error); 66 | } 67 | 68 | [Fact] 69 | public void WhenResultIsExpectedToBeFailureWithValueItShouldBeFailureWithValue() 70 | { 71 | var error = new Exception("error"); 72 | var result = Result.Failure(error); 73 | 74 | result.Should().FailWith(error); 75 | } 76 | 77 | [Fact] 78 | public void WhenResultIsExpectedToBeFailureWithValueItShouldThrowWhenFailureWithDifferenceValue() 79 | { 80 | var error = new Exception("error"); 81 | var result = Result.Failure(error); 82 | 83 | var action = () => result.Should().FailWith(new Exception("Some other error")); 84 | 85 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} error to be System.Exception: Some other error, but found System.Exception: error"); 86 | } 87 | 88 | [Fact] 89 | public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess() 90 | { 91 | string value = "value"; 92 | var someError = new Exception("error"); 93 | var result = Result.Success(value); 94 | 95 | var action = () => result.Should().Fail(); 96 | var actionWith = () => result.Should().FailWith(someError); 97 | 98 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded with value ""{value}"""); 99 | actionWith.Should().Throw().WithMessage(@$"Expected {nameof(result)} to fail, but it succeeded"); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /tests/CSharpFunctionalExtensions.FluentAssertions.Tests/UnitResultAssertionTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Xunit; 3 | using Xunit.Sdk; 4 | 5 | namespace CSharpFunctionalExtensions.FluentAssertions.Tests; 6 | public class UnitResultAssertionTests 7 | { 8 | [Fact] 9 | public void WhenResultIsExpectedToBeSuccessItShouldBeSuccess() 10 | { 11 | var result = UnitResult.Success(); 12 | 13 | var action = () => result.Should().Succeed(); 14 | 15 | action.Should().NotThrow(); 16 | } 17 | 18 | [Fact] 19 | public void WhenResultIsExpectedToBeSuccessItShouldThrowWhenFailure() 20 | { 21 | string error = "error"; 22 | var result = UnitResult.Failure(error); 23 | 24 | var action = () => result.Should().Succeed(); 25 | 26 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} to succeed, but it failed with error ""{error}"""); 27 | } 28 | 29 | [Fact] 30 | public void WhenResultIsExpectedToBeFailureItShouldBeFailure() 31 | { 32 | string error = "error"; 33 | var result = UnitResult.Failure(error); 34 | 35 | var action = () => result.Should().Fail(); 36 | var actionWithError = () => result.Should().FailWith(error); 37 | 38 | action.Should().NotThrow(); 39 | actionWithError.Should().NotThrow(); 40 | result.Should().Fail().Which.Should().Be(error); 41 | result.Should().FailWith(error).Which.Should().HaveLength(5); 42 | } 43 | 44 | [Fact] 45 | public void WhenResultIsExpectedToBeFailureWithValueItShouldBeFailureWithValue() 46 | { 47 | string error = "error"; 48 | var result = UnitResult.Failure(error); 49 | 50 | result.Should().FailWith(error); 51 | } 52 | 53 | [Fact] 54 | public void WhenResultIsExpectedToBeFailureWithValueItShouldThrowWhenFailureWithDifferenceValue() 55 | { 56 | string error = "error"; 57 | var result = UnitResult.Failure(error); 58 | 59 | var action = () => result.Should().FailWith("some other error"); 60 | 61 | action.Should().Throw().WithMessage(@$"Expected {nameof(result)} error to be ""some other error"", but found ""{error}"""); 62 | } 63 | 64 | [Fact] 65 | public void WhenResultIsExpectedToBeFailureItShouldThrowWhenSuccess() 66 | { 67 | var result = UnitResult.Success(); 68 | 69 | var action = () => result.Should().Fail(); 70 | 71 | action.Should().Throw().WithMessage($"Expected {nameof(result)} to fail, but it succeeded"); 72 | } 73 | } 74 | --------------------------------------------------------------------------------