您还可以not be empty
对 GUID 使用检查,这样您就可以使用FluentAssertions 的空检查:
Guid.TryParse(iterTags.GUID, out var parsedIterTagsGUID)
parsedIterTagsGUID.Should().NotBeEmpty();
或作为扩展:
public static AndConstraint<FluentAssertions.Primitives.GuidAssertions> ShouldBeGuid(this object value, string because = "", params object[] becauseArgs)
{
Guid.TryParse(value?.ToString(), out var guid);
return guid.Should().NotBeEmpty(because, becauseArgs);
}
通过扩展其他类似的东西,上面可以做得更好:
public static AndConstraint<GuidAssertions> BeGuid(this StringAssertions value, string because = "", params object[] becauseArgs)
{
Guid.TryParse(value.Subject, out var guid);
return guid.Should().NotBeEmpty(because, becauseArgs);
}
public static AndConstraint<GuidAssertions> BeGuid(this ObjectAssertions value, string because = "", params object[] becauseArgs)
{
return (value.Subject as Guid?).Should().NotBeNull().And.NotBeEmpty(because, becauseArgs);
}
或者通过在以下位置提出拉取请求甚至更好:https ://github.com/fluentassertions/fluentassertions