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

DictionaryContainsValueConstraint

DictionaryContainsValueConstraint is used to test whether a dictionary contains an expected object as a value.
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) { IDictionary obj = actual as IDictionary; if (obj == null) throw new ArgumentException("The actual value must be an IDictionary", "actual"); foreach (object value in obj.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; } } }