Ejemplo n.º 1
0
 public void Shall_parse_header()
 {
     Assert.That(AcceptEncodingHeader.TryParse("gzip;foo=bar", out AcceptEncodingHeader header), Is.True);
     Assert.That(header.Element, Is.EqualTo("gzip"));
     Assert.That(header.Parameters[0].Name, Is.EqualTo("foo"));
     Assert.That(header.Parameters[0].Value, Is.EqualTo("bar"));
 }
Ejemplo n.º 2
0
        public void acceptencoding___ctor_basic_returns_type(string value, int expectedCount)
        {
            var header = new AcceptEncodingHeader($"{value}");

            header.Should().NotBeNull();
            header.Value.Should().Be(value);
            header.Values.Should().NotBeNull();
            header.Values.Should().HaveCount(expectedCount);
        }
Ejemplo n.º 3
0
        public void acceptencoding___equals_overload_not_string_or_equivelent_sccess()
        {
            AcceptEncodingHeader header1 = "en-us;";
            var other = 2;

            var equals = header1.Equals(other);

            equals.Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void acceptencoding___equals_overload_null_sccess()
        {
            AcceptEncodingHeader header1 = "en-us;";
            AcceptEncodingHeader header2 = null;

            var equals = header1.Equals(header2);

            equals.Should().BeFalse();
        }
Ejemplo n.º 5
0
        public void acceptencoding___ctor_returns_default_for_null_or_whitespace(string value)
        {
            var header = new AcceptEncodingHeader(value);

            header.Should().NotBeNull();
            header.Value.Should().Be(value);
            header.Values.Should().NotBeNull();
            header.Values.Should().BeEmpty();
        }
Ejemplo n.º 6
0
        public void acceptencoding___gethashcode_success()
        {
            AcceptEncodingHeader header = "en-us;";

            header.Should().NotBeNull();

            var hashCode = header.GetHashCode();

            hashCode.Should().NotBe(0);
        }
Ejemplo n.º 7
0
        public void Shall_clone_header()
        {
            AcceptEncodingHeader original = AcceptEncodingHeader.Parse("gzip");
            AcceptEncodingHeader cloned   = original.DeepClone();

            original.Element = "deflate";
            original.Parameters.Add(new GenericParameter("foo", "bar"));

            Assert.That(cloned.ToString(), Is.EqualTo("gzip"));
            Assert.That(original.ToString(), Is.EqualTo("deflate;foo=bar"));
        }
Ejemplo n.º 8
0
        public void acceptencoding___notequals_operator_header_success(string encoding)
        {
            var value = "gzip;q=0.1, deflate; q=ABC, compress; q=0.7, *; q=0.5, br";

            var contentType1 = new AcceptEncodingHeader(encoding);
            var contentType2 = new AcceptEncodingHeader(value);

            var equals = contentType1 != contentType2;

            equals.Should().Be(true);
        }
Ejemplo n.º 9
0
        public void acceptencoding___equals_operator_header_success(string encoding)
        {
            var value = "gzip;q=0.1, deflate; q=ABC, compress; q=0.7, *; q=0.5";

            var header1 = new AcceptEncodingHeader(encoding);
            var header2 = new AcceptEncodingHeader(value);


            var equals = header1 == header2;

            equals.Should().Be(true);
        }
Ejemplo n.º 10
0
        public void acceptencoding___equals_override_success(string encoding)
        {
            var value = "gzip;q=0.1, deflate; q=ABC, compress; q=0.7, *; q=0.5";

            var header = new AcceptEncodingHeader(encoding);

            var equals = header.Equals(value);

            equals.Should().Be(true);

            equals = header.Equals(new AcceptEncodingHeader(value));
            equals.Should().Be(true);
        }
Ejemplo n.º 11
0
        public void acceptencoding___notequals_operator_string_success(string encoding)
        {
            var value = "gzip;q=0.1, deflate; q=ABC, compress; q=0.7, *; q=0.5, br";

            var header = new AcceptEncodingHeader(encoding);

            var equals = header != value;

            equals.Should().Be(true);

            equals = value != header;
            equals.Should().Be(true);
        }
Ejemplo n.º 12
0
        public void Shall_stringify_header()
        {
            var header = new AcceptEncodingHeader
            {
                Element    = "gzip",
                Parameters =
                {
                    new GenericParameter("foo", "bar")
                }
            };

            Assert.That(header.ToString(), Is.EqualTo("gzip;foo=bar"));
        }
Ejemplo n.º 13
0
        public void acceptencoding___ctor_qualities_modified_when_outofrange()
        {
            var value  = "gzip;q=-1, deflate; q=1.1, compress; q=0.7, *; q=0.5";
            var header = new AcceptEncodingHeader(value);

            header.Should().NotBeNull();
            header.Value.Should().Be(value);
            header.Values.Should().NotBeNull();
            header.Values.Should().HaveCount(4);

            header.Values[0].Encoding.Should().Be("deflate");
            header.Values[0].Quality.Should().Be(1f);

            header.Values[1].Encoding.Should().Be("compress");
            header.Values[1].Quality.Should().Be(0.7f);

            header.Values[2].Encoding.Should().Be("*");
            header.Values[2].Quality.Should().Be(0.5f);

            header.Values[3].Encoding.Should().Be("gzip");
            header.Values[3].Quality.Should().Be(0f);
        }
Ejemplo n.º 14
0
            public void Must_parse_correctly(string headerValue)
            {
                AcceptEncodingHeader[] headers = AcceptEncodingHeader.ParseMany(headerValue).ToArray();

                Assert.That(headers, Has.Length.EqualTo(4));

                Assert.That(headers[0].ContentCoding, Is.EqualTo("compress"));
                Assert.That(headers[0].Qvalue, Is.EqualTo(1m));
                Assert.That(headers[0].EffectiveQvalue, Is.EqualTo(1m));

                Assert.That(headers[1].ContentCoding, Is.EqualTo("gzip"));
                Assert.That(headers[1].Qvalue, Is.EqualTo(0m));
                Assert.That(headers[1].EffectiveQvalue, Is.EqualTo(0m));

                Assert.That(headers[2].ContentCoding, Is.EqualTo("identity"));
                Assert.That(headers[2].Qvalue, Is.EqualTo(0.567m));
                Assert.That(headers[2].EffectiveQvalue, Is.EqualTo(0.567m));

                Assert.That(headers[3].ContentCoding, Is.EqualTo("*"));
                Assert.That(headers[3].Qvalue, Is.Null);
                Assert.That(headers[3].EffectiveQvalue, Is.EqualTo(1m));
            }
Ejemplo n.º 15
0
        public void acceptencoding___assignment_standard_orders_byquality()
        {
            var value = "gzip;q=0.1, deflate; q=1, compress; q=0.7, *; q=0.5";
            AcceptEncodingHeader header = value;

            header.Should().NotBeNull();
            header.Value.Should().Be(value);
            header.Values.Should().NotBeNull();
            header.Values.Should().HaveCount(4);

            header.Values[0].Encoding.Should().Be("deflate");
            header.Values[0].Quality.Should().Be(1f);

            header.Values[1].Encoding.Should().Be("compress");
            header.Values[1].Quality.Should().Be(0.7f);

            header.Values[2].Encoding.Should().Be("*");
            header.Values[2].Quality.Should().Be(0.5f);

            header.Values[3].Encoding.Should().Be("gzip");
            header.Values[3].Quality.Should().Be(0.1f);
        }
Ejemplo n.º 16
0
        public void acceptencoding___assignment_charsets_quality_set_to_0_when_quality_invalid()
        {
            var value = "gzip;q=0.1, deflate; q=ABC, compress; q=0.7, *; q=0.5";
            AcceptEncodingHeader header = value;

            header.Should().NotBeNull();
            header.Value.Should().Be(value);
            header.Values.Should().NotBeNull();
            header.Values.Should().HaveCount(4);

            header.Values[0].Encoding.Should().Be("compress");
            header.Values[0].Quality.Should().Be(0.7f);

            header.Values[1].Encoding.Should().Be("*");
            header.Values[1].Quality.Should().Be(0.5f);

            header.Values[2].Encoding.Should().Be("gzip");
            header.Values[2].Quality.Should().Be(0.1f);

            header.Values[3].Encoding.Should().Be("deflate");
            header.Values[3].Quality.Should().Be(0f);
        }
Ejemplo n.º 17
0
 public void Must_not_result_in_header(string headerValue)
 {
     Assert.That(AcceptEncodingHeader.ParseMany(headerValue), Is.Empty);
 }
Ejemplo n.º 18
0
            public void Must_not_match(string headerValue, string contentCoding)
            {
                AcceptEncodingHeader header = AcceptEncodingHeader.ParseMany(headerValue).Single();

                Assert.That(header.ContentCodingMatches(contentCoding), Is.False);
            }
Ejemplo n.º 19
0
        public void Shall_byteify_request()
        {
            var request = new SipRequest
            {
                Version     = "SIP/2.0",
                Method      = "INVITE",
                RequestUri  = SipUri.Parse("sip:[email protected]"),
                From        = NameAddressHeader.Parse("John Smith <sip:[email protected]>"),
                To          = NameAddressHeader.Parse("Joe Shmoe <sip:[email protected]>"),
                CallId      = CallIdHeader.Parse("*****@*****.**"),
                CSeq        = CSeqHeader.Parse("1 INVITE"),
                ContentType = ContentTypeHeader.Parse("text/plain"),
                MimeVersion = ContentLengthHeader.Parse("1.0")
            };

            request.Vias.Add(ViaHeader.Parse("SIP/2.0/UDP foo.bar.com"));
            request.RecordRoutes.Add(NameAddressHeader.Parse("Tommy Atkins <sip:[email protected]>"));
            request.Routes.Add(NameAddressHeader.Parse("John Doe <sip:[email protected]>"));
            request.Contacts.Add(NameAddressHeader.Parse("Prisoner X <sip:[email protected]>"));
            request.Authorizations.Add(AuthorizationHeader.Parse("Digest username=\"Alice\""));
            request.WwwAuthenticates.Add(WwwAuthenticateHeader.Parse("Digest realm=\"abc.com\""));
            request.ProxyAuthenticates.Add(WwwAuthenticateHeader.Parse("Digest realm=\"xyz.com\""));
            request.ProxyAuthorizations.Add(AuthorizationHeader.Parse("Digest username=\"Bob\""));
            request.CallInfos.Add(CallInfoHeader.Parse("<http://www.abc.com/photo.png>;purpose=icon"));
            request.Allows.Add(ContentLengthHeader.Parse("INVITE, ACK, BYE"));
            request.ContentEncodings.Add(ContentLengthHeader.Parse("deflate"));
            request.AlertInfos.Add(CallInfoHeader.Parse("<http://www.abc.com/sound.wav>"));
            request.ErrorInfos.Add(CallInfoHeader.Parse("<sip:[email protected]>"));
            request.Accepts.Add(ContentTypeHeader.Parse("application/sdp"));
            request.AcceptEncodings.Add(AcceptEncodingHeader.Parse("gzip"));
            request.AcceptLanguages.Add(AcceptEncodingHeader.Parse("en"));
            request.AuthenticationInfos.Add(AuthenticationInfoHeader.Parse("nextnonce=\"abc\""));
            request.ProxyAuthenticationInfos.Add(AuthenticationInfoHeader.Parse("nextnonce=\"def\""));
            request.OtherHeaders.Add(new GenericHeader("P-Asserted-Identity", "sip:[email protected]"));
            request.Bodies.Add(SipBody.Parse("Hello world!"));

            var buffer  = new byte[ushort.MaxValue];
            var success = request.TryCopyTo(buffer, 0, out int length);

            Assert.That(success, Is.True);

            var request2 = SipMessage.Parse(new ArraySegment <byte>(buffer, 0, length));

            Assert.That(request2.ToString(), Is.EqualTo(
                            "INVITE sip:[email protected] SIP/2.0\r\n" +
                            "Via: SIP/2.0/UDP foo.bar.com\r\n" +
                            "Record-Route: Tommy Atkins <sip:[email protected]>\r\n" +
                            "Route: John Doe <sip:[email protected]>\r\n" +
                            "From: John Smith <sip:[email protected]>\r\n" +
                            "To: Joe Shmoe <sip:[email protected]>\r\n" +
                            "Call-ID: [email protected]\r\n" +
                            "CSeq: 1 INVITE\r\n" +
                            "Contact: Prisoner X <sip:[email protected]>\r\n" +
                            "Authorization: Digest username=\"Alice\"\r\n" +
                            "WWW-Authenticate: Digest realm=\"abc.com\"\r\n" +
                            "Proxy-Authenticate: Digest realm=\"xyz.com\"\r\n" +
                            "Proxy-Authorization: Digest username=\"Bob\"\r\n" +
                            "Call-Info: <http://www.abc.com/photo.png>;purpose=icon\r\n" +
                            "Content-Type: text/plain\r\n" +
                            "Mime-Version: 1.0\r\n" +
                            "Allow: INVITE\r\n" +
                            "Allow: ACK\r\n" +
                            "Allow: BYE\r\n" +
                            "Content-Encoding: deflate\r\n" +
                            "Alert-Info: <http://www.abc.com/sound.wav>\r\n" +
                            "Error-Info: <sip:[email protected]>\r\n" +
                            "Accept: application/sdp\r\n" +
                            "Accept-Encoding: gzip\r\n" +
                            "Accept-Language: en\r\n" +
                            "Authentication-Info: nextnonce=\"abc\"\r\n" +
                            "Proxy-Authentication-Info: nextnonce=\"def\"\r\n" +
                            "P-asserted-identity: sip:[email protected]\r\n" +
                            "Content-Length:    12\r\n" +
                            "\r\n" +
                            "Hello world!"));
        }