Repository navigation
Implement ICollection<Cookie> on CookieCollection - #30080
Conversation
|
|
||
| public bool Remove(Cookie cookie) | ||
| { | ||
| var idx = IndexOf(cookie); |
| { | ||
| ICollection<Cookie> cc = CreateCookieCollection1(); | ||
| cc.Clear(); | ||
| Assert.Equal(0, cc.Count); |
There was a problem hiding this comment.
Nit: to make this a bit more meaningful, I'd suggest adding another assert above the clear that validates the collection isn't already empty prior to calling Clear, e.g.
Assert.InRange(cc.Count, 1, int.MaxValue);
cc.Clear();
Assert.Equal(0, cc.Count);| { | ||
| ICollection<Cookie> cc = CreateCookieCollection1(); | ||
| Assert.True(cc.Remove(c1)); | ||
| Assert.False(cc.Contains(c1)); |
There was a problem hiding this comment.
Nit: it'd be good to validate other impacted members as well, e.g. that the count has appropriately decreased by 1.
| ICollection<Cookie> cc = CreateCookieCollection1(); | ||
| Assert.True(cc.Remove(c1)); | ||
| Assert.False(cc.Contains(c1)); | ||
| } |
There was a problem hiding this comment.
We should also validate that calling Remove on c1 again returns false, and that calling it on c2 also returns false. And that after both false returns, the count remains unchanged.
stephentoub
left a comment
There was a problem hiding this comment.
Some minor comments, otherwise LGTM.
|
cc: @davidsh |
| Assert.Throws<ArgumentNullException>(() => cc.Add((CookieCollection)null)); | ||
| } | ||
|
|
||
| [Fact] |
There was a problem hiding this comment.
It looks like the tests have a configuration that builds against netstandard. As such, these tests won't compile in that configuration because these new members don't exist in that configuration. To add the tests, you'll need to move them into a separate file, e.g. CookieCollectionTest.netcoreapp.cs, and then change the .csproj to conditionally include that file only when building for netcoreapp. If you search the repo, you'll find lots of other examples of that you can copy from.
| public bool Contains(System.Net.Cookie cookie) { throw null; } | ||
| public bool Remove(System.Net.Cookie cookie) { throw null; } | ||
| public System.Collections.Generic.IEnumerator<System.Net.Cookie> GetEnumerator() { throw null; } | ||
| System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } |
There was a problem hiding this comment.
This is a breaking change: you can't take the public IEnumerator GetEnumerator method and replace it with IEnumerator<Cookie> GetEnumerator. You will need to make the new generic implementation the explicit implementation and leave the current one public / implicit.
stephentoub
left a comment
There was a problem hiding this comment.
The non-generic GetEnumerator needs to be left as public.
| public bool Contains(Cookie cookie) | ||
| { | ||
| var idx = IndexOf(cookie); | ||
| return idx >= 0; |
ViktorHofer
left a comment
There was a problem hiding this comment.
Comments from Stephen and the necessary factor of the tests into a separate file but other LGTM.
| <ItemGroup> | ||
| <Compile Include="CookieTest.cs" /> | ||
| <Compile Include="CookieCollectionTest.cs" /> | ||
| <Compile Include="CookieCollectionTest.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'"/> |
There was a problem hiding this comment.
could you please move all Compile directives that have a netcoreapp condition into a combined ItemGroup with the condition on it? We usually do it that way.
| } | ||
|
|
||
| private readonly ArrayList m_list = new ArrayList(); | ||
| private readonly List<Cookie> m_list = new List<Cookie>(); |
There was a problem hiding this comment.
@ViktorHofer, This type is [Serializable]. Is it OK to change this field's type from ArrayList to List<Cookie>?
There was a problem hiding this comment.
@ViktorHofer, are we missing a test then that would have caught that? Or did a test fail?
There was a problem hiding this comment.
Sorry, I didn't check the CI before the change but a test must have failed. I just checked the BinaryFormatterTestData to make sure, there isn't a test hole.
There was a problem hiding this comment.
There was a problem hiding this comment.
Serialization tests did fail, everything's good :)
* Implement ICollection<Cookie> on CookieCollection * Remove breaking change and improve tests * Move netcoreapp Compile directives into separate ItemGroup in tests * Revert m_list from List<Cookie> to ArrayList Commit migrated from dotnet/corefx@2c309c2
Closes #26975