Я пытаюсь создать плавное утверждение для приведенного ниже условия. Но не смог найти метод с выражением или 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
Плавное утверждение для условия ИЛИ ⇐ C#
Место общения программистов C#
1772186533
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 [i]because[/i], 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 [i]because[/i], 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 [i]because[/i], 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 [i]because[/i], 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);
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/34654341/fluent-assertion-for-or-condition[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия