snapshooter
snapshooter copied to clipboard
Matching some elements
It would be interesting if we could match a data structure to just some elements of the snapshot.
For example, I want to check that just the first 6 elements of a snapshot containing a list are there.
The business case would be a permission list where some of them are key, fundamental and are the ones in the original snapshot. But the list will naturally grow with more custom permissions... so the tests will fail over and over, becoming a very brittle test.
I would like that I could check the current collection of permissions against this initial snapshot and determine that they exist.
For this I would like two things:
- That I can cut the elements in the initial snapshot to a limit (ex: element 0 until element 6).
- That I can check the current list contains the elements in the snapshot.
For example, I have a snapshot of 10 permissions.
{
element: "permission 1",
.....
},
{
element: "permission 2",
.....
},
...
And a List<permissions> PermList which contains the current and always changing persons... could contain 100 or more..
I'd like something as PermissionList.MatchSnapshot( matchOptions => matchOptions.MatchUntilElement(2));
So only the two first permissions in the snapshot are "matched".
And the test would work forever and ever ;)
Why would you like to have everything in snapshot if you only want to match a certain number of items?
PermissionList.Take(x).MatchSnapshot();
You could reduce your list to what you need and then MatchSnapshot
Good question! I only want those "key" elements that I want to check are contained... so maybe a "Match only these elements" matchOptions would do...