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

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; namespace NUnit.Framework.Constraints { public class DictionaryContainsValueConstraint : CollectionItemsEqualConstraint { public override string DisplayName => "ContainsValue"; public override string Description => "dictionary containing value " + MsgUtils.FormatValue(Expected); protected object Expected { get; set; } public DictionaryContainsValueConstraint(object expected) : base(expected) { Expected = expected; } protected override bool Matches(IEnumerable actual) { foreach (object value in ConstraintUtils.RequireActual<IDictionary>(actual, "actual", false).Values) { if (ItemsEqual(value, Expected)) return true; } return false; } public DictionaryContainsValueConstraint Using<TCollectionType, TMemberType>(Func<TCollectionType, TMemberType, bool> comparison) { Func<TMemberType, TCollectionType, bool> comparison2 = (TMemberType actual, TCollectionType expected) => comparison(expected, actual); Using(EqualityAdapter.For(comparison2)); return this; } } }