-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
api-approvedAPI was approved, it can be implementedAPI was approved, it can be implementedenhancement
Description
Background and motivation
Currently, there is an implementation to check whenever an Attribute or Element is within the Document: https://fluentassertions.com/xml/
However, sometimes it is necessary to check if those attributes are absent. Currently, there is no possibility to do this. Maybe it would be possible to use the HaveElement() Method and catch the Exception, but this feels dirty.
I think it could also be a good idea, to add a constraint if the attribute/element does not have a specific value
API Proposal
public class XElementAssertions
{
public AndConstraint<XElementAssertions> NotHaveAttribute(string unexpectedAttribute, string because = "", params object[] becauseArgs);
public AndConstraint<XElementAssertions> NotHaveAttribute(string unexpectedAttribute, string unexpectedValue, string because = "", params object[] becauseArgs);
public AndWhichConstraint<XElementAssertions, XElement> NotHaveElement(string unexpectedElement, string because = "", params object[] becauseArgs);
public AndWhichConstraint<XElementAssertions, XElement> NotHaveElement(string unexpectedElement, object unexpectedValue, string because = "", params object[] becauseArgs);
}API Usage
var element = XElement.Parse("<user><forename>john</forename></user>");
element.Should().NotHaveElement("surname");
var element = XElement.Parse("<user><forename>john</forename><surname>doe</surname></user>");
element.Should().NotHaveElement("surname", "smith");
var element = XElement.Parse("<user forename='john' />");
element.Should().NotHaveAttribute("surname");
var element = XElement.Parse("<user forename='john' surname='doe' />");
element.Should().NotHaveAttribute("surname", "smith");Alternative Designs
No response
Risks
No response
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
Yes, please assign this issue to me.
cbersch
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved, it can be implementedAPI was approved, it can be implementedenhancement