Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Implement ICollection<Cookie> on CookieCollection - #30080

Merged
ViktorHofer merged 4 commits into
dotnet:masterfrom
yevgeniyredko:CookieCollectionUpdate
Jun 2, 2018
Merged

ViktorHofer merged 4 commits into
dotnet:masterfrom
yevgeniyredko:CookieCollectionUpdate

Conversation

@yevgeniyredko

Copy link
Copy Markdown
Member

Closes #26975

@dnfclas

dnfclas commented Jun 2, 2018 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.


public bool Remove(Cookie cookie)
{
var idx = IndexOf(cookie);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: var => int

{
ICollection<Cookie> cc = CreateCookieCollection1();
cc.Clear();
Assert.Equal(0, cc.Count);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, otherwise LGTM.

@stephentoub

Copy link
Copy Markdown
Member

cc: @davidsh

Assert.Throws<ArgumentNullException>(() => cc.Add((CookieCollection)null));
}

[Fact]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-generic GetEnumerator needs to be left as public.

public bool Contains(Cookie cookie)
{
var idx = IndexOf(cookie);
return idx >= 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: IndexOf(cookie) >= 0;

ViktorHofer
ViktorHofer previously approved these changes Jun 2, 2018

@ViktorHofer ViktorHofer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments from Stephen and the necessary factor of the tests into a separate file but other LGTM.

@ViktorHofer
ViktorHofer dismissed their stale review June 2, 2018 13:17

didn't see the API diff.

<ItemGroup>
<Compile Include="CookieTest.cs" />
<Compile Include="CookieCollectionTest.cs" />
<Compile Include="CookieCollectionTest.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do it

@ViktorHofer
ViktorHofer requested a review from davidsh June 2, 2018 15:11
@karelz karelz added the Hackathon Issues picked for Hackathon label Jun 2, 2018
}

private readonly ArrayList m_list = new ArrayList();
private readonly List<Cookie> m_list = new List<Cookie>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer, This type is [Serializable]. Is it OK to change this field's type from ArrayList to List<Cookie>?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer, are we missing a test then that would have caught that? Or did a test fail?

@ViktorHofer ViktorHofer Jun 2, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer ViktorHofer Jun 2, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serialization tests did fail, everything's good :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

@stephentoub
stephentoub dismissed their stale review June 2, 2018 22:11

Addressed

@davidsh davidsh removed their assignment Jun 2, 2018
@ViktorHofer
ViktorHofer merged commit 2c309c2 into dotnet:master Jun 2, 2018
@karelz karelz added this to the 3.0 milestone Jul 8, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net Hackathon Issues picked for Hackathon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants