예제 #1
0
    public void CopyFromReadOnly_NameAndValue_CopiedAsNonReadOnly()
    {
        var pair0 = new NameValueHeaderValue("name", "value");
        var pair1 = pair0.CopyAsReadOnly();
        var pair2 = pair1.Copy();

        Assert.NotSame(pair0, pair1);
        Assert.Same(pair0.Name.Value, pair1.Name.Value);
        Assert.Same(pair0.Value.Value, pair1.Value.Value);

        // Change one value and verify the other is unchanged.
        pair2.Value = "othervalue";
        Assert.Equal("othervalue", pair2.Value);
        Assert.Equal("value", pair1.Value);
    }
예제 #2
0
    public void CopyAsReadOnly_NameAndValue_CopiedAndReadOnly()
    {
        var pair0 = new NameValueHeaderValue("name", "value");
        var pair1 = pair0.CopyAsReadOnly();

        Assert.NotSame(pair0, pair1);
        Assert.Same(pair0.Name.Value, pair1.Name.Value);
        Assert.Same(pair0.Value.Value, pair1.Value.Value);
        Assert.False(pair0.IsReadOnly);
        Assert.True(pair1.IsReadOnly);

        // Change one value and verify the other is unchanged.
        pair0.Value = "othervalue";
        Assert.Equal("othervalue", pair0.Value);
        Assert.Equal("value", pair1.Value);
        Assert.Throws <InvalidOperationException>(() => { pair1.Value = "othervalue"; });
    }