OR 条件的流畅断言

2024-01-15

我正在尝试为以下条件设置流畅的断言。但找不到带有表达式的方法或带有 Or() 的对象断言。

我必须检查我的服务状态是否具有枚举值Pending or Active

services.Should().HaveCount(totalServices).And.BeOfType<Service>().Which.ServiceStatusKey.Should().Be(Status.Pending);

我想要类似的东西,

.Be(Status.Pending).Or().Be(Status.Active)

有人可以帮助我实现这一目标吗?

FluentAsserstions 版本:4.1.1(来自 Nuget 的最新版本) 附加 4.1 FluentAssertions.Primitive 命名空间。

 // Decompiled with JetBrains decompiler
// Type: FluentAssertions.Primitives.ObjectAssertions
// Assembly: FluentAssertions.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a
// MVID: 090116C5-E9A5-4878-B62E-DE0EBFEBBE14
// Assembly location: C:\RA\P4V\BOSS\trunk\M5Portal\packages\FluentAssertions.4.1.1\lib\net45\FluentAssertions.Core.dll

using FluentAssertions;
using FluentAssertions.Common;
using FluentAssertions.Execution;
using System;
using System.Diagnostics;

namespace FluentAssertions.Primitives
{
  /// <summary>
  /// Contains a number of methods to assert that an <see cref="T:System.Object"/> is in the expected state.
  /// 
  /// </summary>
  [DebuggerNonUserCode]
  public class ObjectAssertions : ReferenceTypeAssertions<object, ObjectAssertions>
  {
    /// <summary>
    /// Returns the type of the subject the assertion applies on.
    /// 
    /// </summary>
    protected override string Context
    {
      get
      {
        return "object";
      }
    }

    public ObjectAssertions(object value)
    {
      this.Subject = value;
    }

    /// <summary>
    /// Asserts that an object equals another object using its <see cref="M:System.Object.Equals(System.Object)"/> implementation.
    /// 
    /// </summary>
    /// <param name="expected">The expected value</param><param name="because">A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])"/> explaining why the assertion
    ///             is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
    ///             </param><param name="reasonArgs">Zero or more objects to format using the placeholders in <see cref="!:because"/>.
    ///             </param>
    public AndConstraint<ObjectAssertions> Be(object expected, string because = "", params object[] reasonArgs)
    {
      Execute.Assertion.BecauseOf(because, reasonArgs).ForCondition(ObjectExtensions.IsSameOrEqualTo(this.Subject, expected)).FailWith("Expected {context:object} to be {0}{reason}, but found {1}.", expected, this.Subject);
      return new AndConstraint<ObjectAssertions>(this);
    }

    /// <summary>
    /// Asserts that an object does not equal another object using its <see cref="M:System.Object.Equals(System.Object)"/> method.
    /// 
    /// </summary>
    /// <param name="unexpected">The unexpected value</param><param name="because">A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
    ///             start with the word <i>because</i>, it is prepended to the message.
    ///             </param><param name="reasonArgs">Zero or more values to use for filling in any <see cref="M:System.String.Format(System.String,System.Object[])"/> compatible placeholders.
    ///             </param>
    public AndConstraint<ObjectAssertions> NotBe(object unexpected, string because = "", params object[] reasonArgs)
    {
      Execute.Assertion.ForCondition(!ObjectExtensions.IsSameOrEqualTo(this.Subject, unexpected)).BecauseOf(because, reasonArgs).FailWith("Did not expect {context:object} to be equal to {0}{reason}.", unexpected);
      return new AndConstraint<ObjectAssertions>(this);
    }

    /// <summary>
    /// Asserts that an object is an enum and has a specified flag
    /// 
    /// </summary>
    /// <param name="expectedFlag">The expected flag.</param><param name="because">A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
    ///             start with the word <i>because</i>, it is prepended to the message.
    ///             </param><param name="reasonArgs">Zero or more values to use for filling in any <see cref="M:System.String.Format(System.String,System.Object[])"/> compatible placeholders.
    ///             </param>
    public AndConstraint<ObjectAssertions> HaveFlag(Enum expectedFlag, string because = "", params object[] reasonArgs)
    {
      Execute.Assertion.BecauseOf(because, reasonArgs).ForCondition(this.Subject != null).FailWith("Expected type to be {0}{reason}, but found <null>.", (object) expectedFlag.GetType()).Then.ForCondition(this.Subject.GetType() == expectedFlag.GetType()).FailWith("Expected the enum to be of type {0} type but found {1}{reason}.", (object) expectedFlag.GetType(), (object) this.Subject.GetType()).Then.Given<Enum>((Func<Enum>) (() => this.Subject as Enum)).ForCondition((Func<Enum, bool>) (@enum => @enum.HasFlag(expectedFlag))).FailWith("The enum was expected to have flag {0} but found {1}{reason}.", (Func<Enum, object>) (_ => (object) expectedFlag), (Func<Enum, object>) (@enum => (object) @enum));
      return new AndConstraint<ObjectAssertions>(this);
    }

    /// <summary>
    /// Asserts that an object is an enum and does not have a specified flag
    /// 
    /// </summary>
    /// <param name="unexpectedFlag">The unexpected flag.</param><param name="because">A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
    ///             start with the word <i>because</i>, it is prepended to the message.
    ///             </param><param name="reasonArgs">Zero or more values to use for filling in any <see cref="M:System.String.Format(System.String,System.Object[])"/> compatible placeholders.
    ///             </param>
    public AndConstraint<ObjectAssertions> NotHaveFlag(Enum unexpectedFlag, string because = "", params object[] reasonArgs)
    {
      Execute.Assertion.BecauseOf(because, reasonArgs).ForCondition(this.Subject != null).FailWith("Expected type to be {0}{reason}, but found <null>.", (object) unexpectedFlag.GetType()).Then.ForCondition(this.Subject.GetType() == unexpectedFlag.GetType()).FailWith("Expected the enum to be of type {0} type but found {1}{reason}.", (object) unexpectedFlag.GetType(), (object) this.Subject.GetType()).Then.Given<Enum>((Func<Enum>) (() => this.Subject as Enum)).ForCondition((Func<Enum, bool>) (@enum => [email protected] /cdn-cgi/l/email-protection(unexpectedFlag))).FailWith("Did not expect the enum to have flag {0}{reason}.", new object[1]
      {
        (object) unexpectedFlag
      });
      return new AndConstraint<ObjectAssertions>(this);
    }
  }
}

对于这种情况,您可以使用 Match。

ServiceStatusKey.Should().Match<Status>(p=>p==Status.Pending || p == Status.Active);

FluentAssertions 不支持 Or() 语句。使用 Match() 进行通用断言。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OR 条件的流畅断言 的相关文章

  • 数据模板绑定垃圾邮件输出窗口出现错误:找不到管理 FrameworkElemen

    我有问题 System Windows Data 错误 2 找不到目标元素的管理 FrameworkElement 或 FrameworkContentElement BindingExpression 无路径 数据项 空 目标元素是 So
  • 使用 mono/nunit-console/4 在 Mac OS X 控制台上运行测试

    我安装了 Max OS X 10 11 1 上面装有 Xamarin 我编写了简单的测试类 只是为了测试在 Mac OS X 和 Ubuntu 上运行 Nunit 测试 该类实际上有一个返回字符串的方法 using System names
  • 有没有快速创建集合的方法?

    目前我正在创建一个像这样的新集 std set a s s insert a1 s insert a2 s insert a3 s insert a10 有没有办法创建s在一行 int myints 10 20 30 40 50 std s
  • QCombobox 向下箭头图像

    如何更改Qcombobox向下箭头图像 现在我正在使用这个 QSS 代码 但这不起作用 我无法删除向下箭头边框 QComboBox border 0px QComboBox down arrow border 0px background
  • 在 C# 中按元素相乘数组具有意想不到的性能

    我想找到按元素相乘两个数组的最佳方法 这是更广泛项目的一部分 其中性能而不是唯一的考虑因素 我今天开始用 C Linqpad 编写一些函数 因此它还没有以任何方式进行优化 下面代码的输出如下 Environment ProcessorCou
  • 更改 Qt OpenGL 窗口示例以使用 OpenGL 3.3

    我正在尝试更改 Qt OpenGL 示例以使用更现代的 opengl 版本 330 似乎合适 所以我做了 在 main cpp 上设置版本和配置文件 设置着色器版本 更改着色器以使用统一 它现在构建没有任何错误 但我只看到一个空白窗口 我错
  • ASP.NET Web API 客户端 ProgressMessageHandler Post 任务卡在 WinForm 应用程序中

    我在用着HttpClient and ProgressMessageHandler来自MS ASP NET Web API 客户端库 http nuget org packages Microsoft AspNet WebApi Clien
  • 与 Qt 项目的静态链接

    我有一个在 Visual Studio 2010 Professional 中构建的 Qt 项目 但是 当我运行它 在调试或发布模式下 时 它会要求一些 Qt dll 如果我提供 dll 并将它们放入 System32 中 它就可以工作 但
  • 时间:2019-03-17 标签:c#ThreadSafeDeepCopy

    我一直在阅读很多其他问题以及大量谷歌搜索 但我一直无法找到明确的解决方案 根据我读过的一些最佳实践 类的静态方法应该创建线程安全的 并且实例成员应该将线程安全留给消费者 我想为该类实现深度复制方法 该类本身还有其他引用类型成员 有没有什么方
  • vs2008 c#:Facebook.rest.api如何使用它来获取好友列表?

    如何在此基础上取得进一步的进步 获取好友列表的下一步是什么 string APIKey ConfigurationManager AppSettings API Key string APISecret ConfigurationManag
  • 单例模式和 std::unique_ptr

    std unique ptr唯一地控制它指向的对象 因此不使用引用计数 单例确保利用引用计数只能创建一个对象 那么会std unique ptr与单例执行相同 单例确保只有一个实例属于一种类型 A unique ptr确保只有一个智能指针到
  • AES 输出是否小于输入?

    我想加密一个字符串并将其嵌入到 URL 中 因此我想确保加密的输出不大于输入 AES 是可行的方法吗 不可能创建任何始终会创建比输入更小的输出的算法 但可以将任何输出反转回输入 如果您允许 不大于输入 那么基本上您只是在谈论同构算法alwa
  • 如何在标准 WPF ListView 中启用 UI 虚拟化

    我正在使用 NET 4 5 VS2012 并且我有一个 ListView 看起来像这样
  • 每个租户的唯一用户名和电子邮件

    我正在使用以下代码编写多租户应用程序ASP NET Core 2 1 我想覆盖默认的与用户创建相关的验证机制 目前我无法创建多个具有相同的用户UserName My ApplicationUser模型有一个名为TenantID 我想要实现的
  • 如何在c的case语句中使用省略号?

    CASE expr no commas ELLIPSIS expr no commas 我在c的语法规则中看到了这样的规则 但是当我尝试重现它时 int test float i switch i case 1 3 printf hi 它失
  • 新任务中使用的依赖注入服务

    我在需要时使用依赖项注入来访问我的服务 但我现在想要创建一个并发任务 但这会由于依赖项注入对象及其生命周期而导致问题 我读过这篇文章 标题 防止多线程 Link http mehdi me ambient dbcontext in ef6
  • cout 和字符串连接

    我刚刚复习了我的 C 我尝试这样做 include
  • 您是否将信息添加到每个 .hpp/.cpp 文件的顶部? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 创建新的 C 头文件 源文件时 您会在顶部添加哪些信息 例如 您是否添加日期 您的姓名 文件描述等 您是否使用结构化格式来存储此信息 e g F
  • 将 char[][] 转换为 char** 会导致段错误吗?

    好吧 我的 C 有点生疏了 但我想我应该用 C 来做我的下一个 小 项目 这样我就可以对其进行抛光 并且我已经有不到 20 行的段错误了 这是我的完整代码 define ROWS 4 define COLS 4 char main map
  • 使用 QtWebEngine 将 C++ 对象暴露给 Qt 中的 Javascript

    使用 QtWebkit 可以通过以下方式将 C 对象公开给 JavascriptQWebFrame addToJavaScriptWindowObject如中所述https stackoverflow com a 20685002 5959

随机推荐

  • 如何将 WordPress 模板与 CodeIgniter 集成

    CodeIgniter 和 WordPress 如何集成 使得外观和感觉 模板 WordPress 博客是否会转移到 CodeIgniter 创建的页面 第一步是将 CodeIgniter 和 WordPress 文件移动到它们自己的目录中
  • fclose() 函数运行缓慢

    我尝试在 Linux 机器上使用 c fopen fwrite 和 fflush 和 fclose 函数创建大约 4 GB 的文件 但我观察到 fclose 函数需要很长时间才能关闭文件 大约需要 40 50 秒 我检查了不同的论坛以找到这
  • Sqlite3 的 Rails 测试失败

    当我在 Rails 中运行测试时 我似乎遇到了一个奇怪的错误 它们都因相同的原因而失败 并且没有一个在线文档对于这个特定的错误似乎特别有帮助 SQLite3 SQLException cannot rollback no transacti
  • 从 Kafka 获取最新值

    我有一个卡夫卡主题叫做A 主题中的数据格式A is id 1 name stackoverflow created at 2017 09 28 22 30 00 000 id 2 name confluent created at 2017
  • Control-C 和 C 中的信号处理

    我有 2 个进程通过套接字相互通信发送者和接收者 我想捕获信号 Control C 并且不退出 显示一些输出 发送者和接收者工作正常 所以我将信号 SIGINT 处理程序 添加到发送者的身体 handler 只是输出一些文本 所以当我运行它
  • Rails:没有复数的路由给出了奇怪的助手

    通过此设置 我得到了一个奇怪的命名助手 在 config routes rb 中我有 Qtl Application routes draw do resources qtl table do collection do get searc
  • 使用 Visual Studio 的 link.exe 的链接文件限制是多少?

    我知道一些链接器对命令行上允许的目标文件数量有限制 Visual Studio 是什么 此外 如果超过此数字 某些链接器允许您指定一个包含所有目标文件名称的文件 并且您只能将其作为参数传递 这是一个例子来向您展示我的意思 some link
  • 全文搜索仅返回精确匹配

    我有以下脚本 select c id from TBL COUPONS as c inner join TBL BUSINESS as b on c business id b business id inner join TBL BLOC
  • Android:API级别VS。安卓版本

    我是Android开发新手 我想知道版本和API级别之间有什么联系或区别 每一项指的是什么 当我决定为 API 14 或 Android 4 0 开发一些应用程序时 这意味着什么 或者一个是另一个的子集 我根本没明白其中的区别 为什么有两个
  • Android - EditText 与软键盘重叠

    我正在开发一个有一些 EditText 的 Activity 当我单击 触摸 EditText 时 会出现软键盘 但是屏幕底部的 EditText 与软键盘重叠 显示 EditText 的上半部分 下半部分位于键盘下方 我设置了androi
  • Julia Dataframes 与 Python pandas

    我目前正在使用 pythonpandas并想知道是否有办法将 pandas 中的数据输出到 Julia 中Dataframes反之亦然 我认为你可以从 Julia 调用 pythonPycall但我不确定它是否适用于数据帧 有没有办法从 p
  • javascript 获取子域上的 iframe url 当前页面

    我需要获取页面上 iframe 所在的页面 url 因为我们使用 iframe 来处理订购产品 然而 在我的一生中 我似乎无法让它显示 iframe 的 URL 显示是一个测试 因为当我看到它有效时它会自动发送电子邮件 代码
  • Magento:获取商店联系电话

    看起来应该很简单 但在任何地方都找不到解决方案 我需要输出商店联系电话号码 该号码位于管理员的商店信息中 我需要将其输出到模板文件和 CMS 页面中 每个文件的代码是什么 谢谢 那是一个核心配置 所以它被保存在core config dat
  • 多数据库 Grails 应用程序的 Spring 或 Hibernate 多租户

    Grails 有一个用于单个数据库的多租户插件和一个用于多数据库的多租户插件 但不再支持 维护用于多数据库的插件 有没有什么方法可以让我将 Spring 或 Hibernate 本身用于多租户多数据库 Grails 应用程序 您可以使用此处
  • 如何从 JavaScript 中隐藏时间标准

    我只想显示天 日期 时间 现在显示 其实我想显示如下 如何删除 印度标准时间 使用的代码如下
  • Vue:等待渲染,直到安装所有组件

    我有一个 Vue Nuxt Web 应用程序 其中页面是从许多具有子组件的组件动态生成的 问题是页眉和页脚首先渲染 然后是具有实际内容的子组件 第一次加载时这看起来很糟糕 而且 Lighthouse 不喜欢它 这是一个Avoid large
  • 使用自动布局将堆栈视图垂直定向为纵向,水平定向为横向

    获得纵向垂直堆栈视图以横向水平对齐的最佳方法是什么 我尝试过代码和自动布局解决方案 但它们不起作用 有没有简单的方法可以在故事板中做到这一点 您需要以编程方式更新axis的财产UIStackView https developer appl
  • web.py 和 Gunicorn

    我的问题基本上是标题中的内容 如何设置gunicorn来运行web py应用程序 另外 如果有任何差异 我将如何在heroku上做到这一点 我已经使用内置的cherrypy在heroku上运行了我的应用程序 但我无法让gunicorn与we
  • SQL正则表达式获取电话号码

    我想获取满足特定条件的文本字符串的电话号码 9个字符 数字 只能从9 8 7 6开始 我尝试使用以下表达式 9 8 7 6 0 9 8 在以下函数中 DECLARE str VARCHAR MAX DECLARE validchars VA
  • OR 条件的流畅断言

    我正在尝试为以下条件设置流畅的断言 但找不到带有表达式的方法或带有 Or 的对象断言 我必须检查我的服务状态是否具有枚举值Pending or Active services Should HaveCount totalServices A