Ejemplo n.º 1
0
        public void RemoveKeyAndValue()
        {
            var headers = new NameValueCollection()
            {
                { "Header#1", "Value #1-A" },
                { "Header#2", "Value #2" },
                { "Header#1", "Value #1-B" },
                { "Header#3", "Value #3" },
            };

            var response = new Mock <HttpResponseBase>(MockBehavior.Strict);

            response.SetupGet(r => r.Headers)
            .Returns(headers);

            var responseFeature = new HttpResponseHeaderDictionary(response.Object);

            responseFeature.Remove(new KeyValuePair <string, StringValues>("Header#1", "Value #1-A,Value #1-B")).Should().BeTrue();
            responseFeature["Header#1"].Should().BeEmpty();
            responseFeature.Should().HaveCount(2);
            headers["Header#1"].Should().BeNull();
            headers.Should().HaveCount(2);

            responseFeature.Remove(new KeyValuePair <string, StringValues>("Header#2", "Value #2")).Should().BeTrue();
            responseFeature["Header#2"].Should().BeEmpty();
            responseFeature.Should().HaveCount(1);
            headers["Header#2"].Should().BeNull();
            headers.Should().HaveCount(1);

            responseFeature.Remove(new KeyValuePair <string, StringValues>("Header#NotExists", "Value #1-A")).Should().BeFalse();
            responseFeature.Remove(new KeyValuePair <string, StringValues>("Header#3", "Other value")).Should().BeFalse();

            responseFeature.Should().HaveCount(1);
            headers.Should().HaveCount(1);
        }
Ejemplo n.º 2
0
        public void Remove()
        {
            var headers = new NameValueCollection()
            {
                { "Header#1", "Value #1-A" },
                { "Header#2", "Value #2" },
                { "Header#1", "Value #1-B" },
            };

            var response = new Mock <HttpResponseBase>(MockBehavior.Strict);

            response.SetupGet(r => r.Headers)
            .Returns(headers);

            var responseFeature = new HttpResponseHeaderDictionary(response.Object);

            responseFeature.Remove("Header#1").Should().BeTrue();
            responseFeature["Header#1"].Should().BeEmpty();
            responseFeature.Should().HaveCount(1);
            headers["Header#1"].Should().BeNull();
            headers.Should().HaveCount(1);

            responseFeature.Remove("Not exists").Should().BeFalse();
            responseFeature.Should().HaveCount(1);
            headers.Should().HaveCount(1);
        }