This repository was archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
Add strong and weak ETag comparisons #695
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,97 @@ public void Equals_UseSameAndDifferentETags_EqualOrNotEqualNoExceptions() | |
Assert.True(etag1.Equals(etag5), "tag vs. tag.."); | ||
} | ||
|
||
[Fact] | ||
public void Compare_WithNull_ReturnsFalse() | ||
{ | ||
Assert.False(EntityTagHeaderValue.Any.Compare(null, useStrongComparison: true)); | ||
Assert.False(EntityTagHeaderValue.Any.Compare(null, useStrongComparison: false)); | ||
} | ||
|
||
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> NotEquivalentUnderStrongComparison | ||
{ | ||
get | ||
{ | ||
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> | ||
{ | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"TAG\"") }, | ||
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"", true) }, | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"", true) }, | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag1\"") }, | ||
{ new EntityTagHeaderValue("\"tag\""), EntityTagHeaderValue.Any }, | ||
}; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it theory so that all the cases are tested no matter how many of them are failed. In the current form, if the first assertion filed the following assertions won't be executed. |
||
|
||
[Theory] | ||
[MemberData(nameof(NotEquivalentUnderStrongComparison))] | ||
public void CompareUsingStrongComparison_NonEquivalentPairs_ReturnFalse(EntityTagHeaderValue left, EntityTagHeaderValue right) | ||
{ | ||
Assert.False(left.Compare(right, useStrongComparison: true)); | ||
Assert.False(right.Compare(left, useStrongComparison: true)); | ||
} | ||
|
||
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> EquivalentUnderStrongComparison | ||
{ | ||
get | ||
{ | ||
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> | ||
{ | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"") }, | ||
}; | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(EquivalentUnderStrongComparison))] | ||
public void CompareUsingStrongComparison_EquivalentPairs_ReturnTrue(EntityTagHeaderValue left, EntityTagHeaderValue right) | ||
{ | ||
Assert.True(left.Compare(right, useStrongComparison: true)); | ||
Assert.True(right.Compare(left, useStrongComparison: true)); | ||
} | ||
|
||
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> NotEquivalentUnderWeakComparison | ||
{ | ||
get | ||
{ | ||
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> | ||
{ | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"TAG\"") }, | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag1\"") }, | ||
{ new EntityTagHeaderValue("\"tag\""), EntityTagHeaderValue.Any }, | ||
}; | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(NotEquivalentUnderWeakComparison))] | ||
public void CompareUsingWeakComparison_NonEquivalentPairs_ReturnFalse(EntityTagHeaderValue left, EntityTagHeaderValue right) | ||
{ | ||
Assert.False(left.Compare(right, useStrongComparison: false)); | ||
Assert.False(right.Compare(left, useStrongComparison: false)); | ||
} | ||
|
||
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> EquivalentUnderWeakComparison | ||
{ | ||
get | ||
{ | ||
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> | ||
{ | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"") }, | ||
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"", true) }, | ||
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"", true) }, | ||
}; | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(EquivalentUnderWeakComparison))] | ||
public void CompareUsingWeakComparison_EquivalentPairs_ReturnTrue(EntityTagHeaderValue left, EntityTagHeaderValue right) | ||
{ | ||
Assert.True(left.Compare(right, useStrongComparison: false)); | ||
Assert.True(right.Compare(left, useStrongComparison: false)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
[Fact] | ||
public void Parse_SetOfValidValueStrings_ParsedCorrectly() | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we were going in a roundabout way of comparing strings previously? Why
CompareOrdinal
instead ofEquals
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to use string.Equals you still need to pass in Ordinal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is an ordinal comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always specify for string operations, the defaults are not consistant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... How and when do they vary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When then stars align ...
Also MSDN recommended use overload without default option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fascinating, didn't know the defaults can vary in such ways. I guess it's always better to be on the safe side and just be explicit in what you want to do haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being explicit greatly improves readability as it removes confusions.