Repository: dotnet/runtime
File: src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpRequestHeadersTest.cs (C#)

Code before:
            // Remove 'chunked' value from store. Since there are no other 'Transfer-Encoding' values, remove whole
            // header.
            headers.TransferEncodingChunked = false;
            Assert.True(headers.TransferEncodingChunked == false, "TransferEncodingChunked == false");
            Assert.Equal(0, headers.TransferEncoding.Count);
            Assert.False(headers.Contains("Transfer-Encoding"));

            headers.TransferEncodingChunked = null;
            Assert.Null(headers.TransferEncodingChunked);
        }

        [Fact]
        public void TransferEncodingChunked_SetToFalse_RemovesAllChunkedValues()
        {
            // Add multiple "chunked" values
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            
            Assert.Equal(2, headers.TransferEncoding.Count);
            Assert.True(headers.TransferEncodingChunked);
            
            // Setting to false should remove all "chunked" values
            headers.TransferEncodingChunked = false;
            
            Assert.False(headers.TransferEncodingChunked, "TransferEncodingChunked should be false after setting to false");
            Assert.Equal(0, headers.TransferEncoding.Count);
        }

        [Fact]
        public void TransferEncoding_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            headers.TryAddWithoutValidation("Transfer-Encoding", " , custom1, , custom2, custom3, chunked    ,");

            // Connection collection has 3 values plus 'chunked'
            Assert.Equal(4, headers.TransferEncoding.Count);
            Assert.Equal(4, headers.GetValues("Transfer-Encoding").Count());
            Assert.True(headers.TransferEncodingChunked == true, "TransferEncodingChunked expected to be true.");

            Assert.Equal(new TransferCodingHeaderValue("custom1"), headers.TransferEncoding.ElementAt(0));
            Assert.Equal(new TransferCodingHeaderValue("custom2"), headers.TransferEncoding.ElementAt(1));
            Assert.Equal(new TransferCodingHeaderValue("custom3"), headers.TransferEncoding.ElementAt(2));

            headers.TransferEncoding.Clear();
            Assert.Null(headers.TransferEncodingChunked);
            Assert.Equal(0, headers.TransferEncoding.Count);
            Assert.False(headers.Contains("Transfer-Encoding"),
                "Transfer-Encoding header after TransferEncoding.Clear().");
        }

        [Fact]
        public void TransferEncoding_UseTryAddWithoutValidationMethodWithInvalidValue_InvalidValueNotRemoved()

Review comment (suggestion):
```suggestion
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("abc"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("def"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            
            Assert.Equal(5, headers.TransferEncoding.Count);
            Assert.True(headers.TransferEncodingChunked);
            
            // Setting to false should remove all "chunked" values
            headers.TransferEncodingChunked = false;
            
            Assert.False(headers.TransferEncodingChunked);
            Assert.Equal(2, headers.TransferEncoding.Count);
```

Code after:
            // Remove 'chunked' value from store. Since there are no other 'Transfer-Encoding' values, remove whole
            // header.
            headers.TransferEncodingChunked = false;
            Assert.True(headers.TransferEncodingChunked == false, "TransferEncodingChunked == false");
            Assert.Equal(0, headers.TransferEncoding.Count);
            Assert.False(headers.Contains("Transfer-Encoding"));

            headers.TransferEncodingChunked = null;
            Assert.Null(headers.TransferEncodingChunked);
        }

        [Fact]
        public void TransferEncodingChunked_SetToFalse_RemovesAllChunkedValues()
        {
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("abc"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("def"));
            headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
            
            Assert.Equal(5, headers.TransferEncoding.Count);
            Assert.True(headers.TransferEncodingChunked);
            
            // Setting to false should remove all "chunked" values
            headers.TransferEncodingChunked = false;
            
            Assert.False(headers.TransferEncodingChunked);
            Assert.Equal(2, headers.TransferEncoding.Count);
        }

        [Fact]
        public void TransferEncoding_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            headers.TryAddWithoutValidation("Transfer-Encoding", " , custom1, , custom2, custom3, chunked    ,");

            // Connection collection has 3 values plus 'chunked'
            Assert.Equal(4, headers.TransferEncoding.Count);
            Assert.Equal(4, headers.GetValues("Transfer-Encoding").Count());
            Assert.True(headers.TransferEncodingChunked == true, "TransferEncodingChunked expected to be true.");

            Assert.Equal(new TransferCodingHeaderValue("custom1"), headers.TransferEncoding.ElementAt(0));
            Assert.Equal(new TransferCodingHeaderValue("custom2"), headers.TransferEncoding.ElementAt(1));
            Assert.Equal(new TransferCodingHeaderValue("custom3"), headers.TransferEncoding.ElementAt(2));

            headers.TransferEncoding.Clear();
            Assert.Null(headers.TransferEncodingChunked);
            Assert.Equal(0, headers.TransferEncoding.Count);
            Assert.False(headers.Contains("Transfer-Encoding"),
                "Transfer-Encoding header after TransferEncoding.Clear().");
        }