I am attempting to assert that a collection of Claim
s contains an expected set of claims. The problem that I seem to be running into is that there's no way to check for a subset and supply my own equivalency options.
var expected = new[] {
new Claim(ClaimTypes.Name, "joshdev"),
new Claim(ClaimTypes.Email, "test@test.com"),
new Claim(ClaimTypes.GivenName, "Josh"),
new Claim(ClaimTypes.Surname, "Perry"),
};
var identity = GetIdentity();
What I've tried...
identity.Claims.ShouldAllBeEquivalentTo(expected, options => options.Including(x => x.Type).Including(x => x.Value));
This fails if the identity's claims are not exactly the expected set, e.g. there are more than just those claims.
identity.Claims.Should().Contain(expected);
This fails because Contain
simply uses the object::Equals
method which the Claim
type does not implement.
What I need is some way to do Contain
but with the same equivalency options as ShouldAllBeEquivalentTo
exposes. I thought perhaps ShouldBeEquivalentTo
would be what I wanted, but that provides for asserting the collection object itself, not the items in the collection.