Плавное утверждение для условия ИЛИC#

Место общения программистов C#
Ответить
Anonymous
 Плавное утверждение для условия ИЛИ

Сообщение Anonymous »

Я пытаюсь создать плавное утверждение для приведенного ниже условия. Но не смог найти метод с выражением или ObjectAssertion с Or().

Мне нужно проверить, имеет ли статус моей службы перечислимое значение «Ожидание» или «Активность»

services.Should().HaveCount(totalServices).And.BeOfType().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
{
///
/// Contains a number of methods to assert that an is in the expected state.
///
///
[DebuggerNonUserCode]
public class ObjectAssertions : ReferenceTypeAssertions
{
///
/// Returns the type of the subject the assertion applies on.
///
///
protected override string Context
{
get
{
return "object";
}
}

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

///
/// Asserts that an object equals another object using its implementation.
///
///
/// The expected valueA formatted phrase as is supported by explaining why the assertion
/// is needed. If the phrase does not start with the word because, it is prepended automatically.
/// Zero or more objects to format using the placeholders in .
///
public AndConstraint 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(this);
}

///
/// Asserts that an object does not equal another object using its method.
///
///
/// The unexpected valueA formatted phrase explaining why the assertion should be satisfied. If the phrase does not
/// start with the word because, it is prepended to the message.
/// Zero or more values to use for filling in any compatible placeholders.
///
public AndConstraint 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(this);
}

///
/// Asserts that an object is an enum and has a specified flag
///
///
/// The expected flag.A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
/// start with the word because, it is prepended to the message.
/// Zero or more values to use for filling in any compatible placeholders.
///
public AndConstraint 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 .", (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((Func) (() => this.Subject as Enum)).ForCondition((Func) (@enum => @enum.HasFlag(expectedFlag))).FailWith("The enum was expected to have flag {0} but found {1}{reason}.", (Func) (_ => (object) expectedFlag), (Func) (@enum => (object) @enum));
return new AndConstraint(this);
}

///
/// Asserts that an object is an enum and does not have a specified flag
///
///
/// The unexpected flag.A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
/// start with the word because, it is prepended to the message.
/// Zero or more values to use for filling in any compatible placeholders.
///
public AndConstraint 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 .", (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((Func) (() => this.Subject as Enum)).ForCondition((Func) (@enum => !@enum.HasFlag(unexpectedFlag))).FailWith("Did not expect the enum to have flag {0}{reason}.", new object[1]
{
(object) unexpectedFlag
});
return new AndConstraint(this);
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/346 ... -condition
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»