<PackageReference Include="NUnit" Version="4.3.2" />

DictionaryContainsValueConstraint

DictionaryContainsValueConstraint is used to test whether a dictionary contains an expected object as a value.
using NUnit.Framework.Internal; using System; using System.Collections; using System.Runtime.CompilerServices; namespace NUnit.Framework.Constraints { [NullableContext(1)] [Nullable(0)] public class DictionaryContainsValueConstraint : CollectionItemsEqualConstraint { public override string DisplayName => "ContainsValue"; public override string Description => "dictionary containing value " + MsgUtils.FormatValue(Expected); [Nullable(2)] [field: Nullable(2)] protected object Expected { [NullableContext(2)] get; } [NullableContext(2)] public DictionaryContainsValueConstraint(object expected) : base(expected) { Expected = expected; } protected override bool Matches(IEnumerable actual) { IDictionary dictionary = ConstraintUtils.RequireActual<IDictionary>(actual, "actual", false); foreach (object value in dictionary.Values) { if (ItemsEqual(value, Expected)) return true; } return false; } public DictionaryContainsValueConstraint Using<[Nullable(2)] TActualValueElement, [Nullable(2)] TExpected>(Func<TActualValueElement, TExpected, bool> comparison) { Func<TExpected, TActualValueElement, bool> comparison2 = (TExpected actual, TActualValueElement expected) => comparison(expected, actual); Using(EqualityAdapter.For(comparison2)); return this; } } }