public bool IsHeaderExist(string Name, bool throwException = true)
        {
            bool exist = HeaderList.Any(x => x.Name == Name);

            if (exist && throwException)
            {
                throw new HttpHandlerExceptiosn($"Global Param: {Name} is already declared", "Encabezados", ExceptionError.Internal_InconsistencyData);
            }
            return(exist);
        }
Пример #2
0
        public void CanAddCustomerHeader()
        {
            // Arrange
            Request request = Session.Request(HeaderListUrl);

            // Act
            HeaderList headers = request.Header("X-Ramone", "123").Get <HeaderList>().Body;

            // Assert
            Assert.IsTrue(headers.Any(h => h == "X-Ramone: 123"), "Must contain customer header");
        }
Пример #3
0
        public void CanSetTypedAcceptHeaderWithQValueFromString()
        {
            // Act
            var request = AcceptSession.Bind(HeaderListUrl).Accept <HeaderList>("application/xml", 0.34);

            using (var r = request.Get())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml; q=0.34"), "Must contain Accept header with q-value");
            }
        }
Пример #4
0
        public void CanPostStringWithDefaultMediaTypeTextPlain()
        {
            // Arrange
            Request fileReq = Session.Bind(Constants.HeaderEchoPath);

            // Act
            using (Response <HeaderList> response = fileReq.Post <HeaderList>("hello"))
            {
                HeaderList headers = response.Body;

                // Assert
                Assert.IsNotNull(headers);
                Assert.IsTrue(headers.Any(h => h == "Content-Type: text/plain"), "Must contain content type text/plain");
            }
        }
Пример #5
0
        public void CanSetMultipleAcceptHeaderWithQValueFromMediaType()
        {
            // Arrange
            Request request = AcceptSession.Bind(HeaderListUrl);

            // Act
            request.Accept(MediaType.ApplicationXml, 0.89).Accept(MediaType.ApplicationXHtml, 1);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml; q=0.89, application/xhtml+xml; q=1.00"), "Must contain Accept header");
            }
        }
Пример #6
0
        public void CanSetAcceptHeaderWithQValueFromMediaType()
        {
            // Arrange
            Request request = AcceptSession.Bind(HeaderListUrl);

            // Act
            request.Accept(MediaType.ApplicationXml, 0.34);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml; q=0.34"), "Must contain Accept header with q-value");
            }
        }
Пример #7
0
        public void CanSetMultipleAcceptHeaderWithQValueFromString()
        {
            // Arrange
            Request request = AcceptSession.Bind(HeaderListUrl);

            // Act
            request.Accept("application/xml", 0.34).Accept("application/json", 0.12);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml; q=0.34, application/json; q=0.12"), "Must contain Accept header with q-value");
            }
        }
Пример #8
0
        public void CanSetMultipleAcceptHeaderFromString()
        {
            // Arrange
            Request request = AcceptSession.Bind(HeaderListUrl);

            // Act
            request.Accept("application/xml").Accept("application/json");

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml, application/json"), "Must contain Accept header");
            }
        }
Пример #9
0
        public void ItAlwaysUsesDefaultAcceptFromSession()
        {
            // Arrange
            AcceptSession.AlwaysAccept(MediaType.ApplicationXml);

            // Act
            var request = AcceptSession.Bind(HeaderListUrl);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/xml"), "Must contain Accept header with q-value");
            }
        }
Пример #10
0
        public void ItUsesMultipleDefaultAcceptFromSessionWithAdditionalAcceptFromRequest()
        {
            // Arrange
            AcceptSession.AlwaysAccept(MediaType.ApplicationXml, 0.88)
            .AlwaysAccept(MediaType.TextPlain);

            // Act
            var request = AcceptSession.Bind(HeaderListUrl).Accept(MediaType.ApplicationJson).Accept("text/csv", 0.21);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/json, text/csv; q=0.21, application/xml; q=0.88, text/plain"), "Must contain Accept header with q-value");
            }
        }
Пример #11
0
        public void CanPostByteArrayWithDefaultMediaTypeOctetStream()
        {
            // Arrange
            Request fileReq = Session.Bind(Constants.HeaderEchoPath);

            byte[] data = new byte[] { 10, 2, 30, 4 };

            // Act
            using (Response <HeaderList> response = fileReq.Post <HeaderList>(data))
            {
                HeaderList headers = response.Body;

                // Assert
                Assert.IsNotNull(headers);
                Assert.IsTrue(headers.Any(h => h == "Content-Type: application/octet-stream"), "Must contain content type octet stream");
            }
        }
Пример #12
0
        public void CanSetIfNoneMatchWithListDirectly()
        {
            // Arrange
            string  tag     = "\"ab\", \"qw\"";
            Request request = Session.Request(HeaderListUrl);

            // Act
            request.IfNoneMatch(tag);

            // Act
            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "If-None-Match: \"ab\", \"qw\""), "Must contain If-None-Match header");
            }
        }
Пример #13
0
        public void CanSetIfNoneMatchViaHeader()
        {
            // Arrange
            string  tag     = "ab12";
            Request request = Session.Request(HeaderListUrl);

            // Act
            request.Header("If-None-Match", tag);

            // Act
            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "If-None-Match: ab12"), "Must contain If-None-Match header");
            }
        }
Пример #14
0
        public void CanSetIfUnmodifiedViaHeader()
        {
            // Arrange
            DateTime since   = new DateTime(2013, 5, 1, 10, 22, 11);
            Request  request = Session.Request(HeaderListUrl);

            // Act
            request.Header("If-Unmodified-Since", since.ToUniversalTime().ToString("r"));

            // Act
            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "If-Unmodified-Since: Wed, 01 May 2013 08:22:11 GMT"), "Must contain If-Unmodified-Since header");
            }
        }
Пример #15
0
        public void CanSetIfModifiedDirectly()
        {
            // Arrange
            DateTime since   = new DateTime(2013, 5, 1, 10, 22, 11);
            Request  request = Session.Request(HeaderListUrl);

            // Act
            request.IfModifiedSince(since);

            // Act
            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "If-Modified-Since: Wed, 01 May 2013 08:22:11 GMT"), "Must contain If-Modified-Since header");
            }
        }
Пример #16
0
        public void CanAddCustomerHeader_AsyncEvent()
        {
            // Arrange
            Request request = Session.Request(HeaderListUrl);

            // Act
            TestAsyncEvent(wh =>
            {
                request.Header("X-Ramone", "123").AsyncEvent().Get <HeaderList>(response =>
                {
                    HeaderList headers = response.Body;

                    // Assert
                    Assert.IsTrue(headers.Any(h => h == "X-Ramone: 123"), "Must contain customer header");

                    wh.Set();
                });
            });
        }
Пример #17
0
        public void ItUsesMultipleDefaultAcceptFromServiceWithAdditionalAcceptFromRequest()
        {
            // Arrange
            IService service = RamoneConfiguration.NewService(BaseUrl)
                               .AlwaysAccept(MediaType.ApplicationXml, 0.88)
                               .AlwaysAccept(MediaType.TextPlain);

            ISession session = service.NewSession().AlwaysAccept(MediaType.TextHtml);

            // Act
            var request = session.Bind(HeaderListUrl).Accept(MediaType.ApplicationJson).Accept("text/csv", 0.21);

            using (var r = request.Get <HeaderList>())
            {
                HeaderList headers = r.Body;

                // Assert
                Assert.IsTrue(headers.Any(h => h == "Accept: application/json, text/csv; q=0.21, application/xml; q=0.88, text/plain, text/html"), "Must contain Accept header with q-value");
            }
        }
Пример #18
0
        public void CanSetIfUnmodifiedDirectly_AsyncEvent()
        {
            // Arrange
            DateTime since   = new DateTime(2013, 5, 1, 10, 22, 11);
            Request  request = Session.Request(HeaderListUrl);

            // Act
            request.IfUnmodifiedSince(since);

            // Act
            TestAsyncEvent(wh =>
            {
                request.AsyncEvent()
                .Get <HeaderList>(r =>
                {
                    HeaderList headers = r.Body;

                    // Assert
                    Assert.IsTrue(headers.Any(h => h == "If-Unmodified-Since: Wed, 01 May 2013 08:22:11 GMT"), "Must contain If-Unmodified-Since header");
                    wh.Set();
                });
            });
        }
Пример #19
0
        public void CanSetIfModifiedViaHeader_AsyncEvent()
        {
            // Arrange
            DateTime since   = new DateTime(2013, 5, 1, 10, 22, 11);
            Request  request = Session.Request(HeaderListUrl);

            // Act
            request.Header("If-Modified-Since", since.ToUniversalTime().ToString("r"));

            // Act
            TestAsyncEvent(wh =>
            {
                request.AsyncEvent()
                .Get <HeaderList>(r =>
                {
                    HeaderList headers = r.Body;

                    // Assert
                    Assert.IsTrue(headers.Any(h => h == "If-Modified-Since: Wed, 01 May 2013 08:22:11 GMT"), "Must contain If-Modified-Since header");
                    wh.Set();
                });
            });
        }
Пример #20
0
        public void CanSetIfNoneMatchDirectly_AsyncEvent()
        {
            // Arrange
            string  tag     = "ab12";
            Request request = Session.Request(HeaderListUrl);

            // Act
            request.IfNoneMatch(tag);

            // Act
            TestAsyncEvent(wh =>
            {
                request.AsyncEvent()
                .Get <HeaderList>(r =>
                {
                    HeaderList headers = r.Body;

                    // Assert
                    Assert.IsTrue(headers.Any(h => h == "If-None-Match: ab12"), "Must contain If-None-Match header");
                    wh.Set();
                });
            });
        }