Beispiel #1
0
        public void SetMethod_GivenMethod_ReturnsTheSameMethod(HttpMethodType httpMethodType)
        {
            // Act
            var request = _requestBuilder
                          .SetMethod(httpMethodType)
                          .SetTarget(UniformResourceIdentifier.FromString("/index.html"))
                          .SetHttpVersion(HttpVersionType.Http1_1)
                          .SetHeader("Host", "example.com")
                          .SetBody("Hello World!", Encoding.Default)
                          .Build();

            // Assert
            Assert.AreEqual(httpMethodType, request.Method);
        }
Beispiel #2
0
        public void Build_ValidProperties_ReturnsIRequest()
        {
            // Act
            var request = _requestBuilder
                          .SetMethod(HttpMethodType.Get)
                          .SetTarget(UniformResourceIdentifier.FromString("/index.html"))
                          .SetHttpVersion(HttpVersionType.Http1_1)
                          .SetHeader("Host", "example.com")
                          .SetBody("Hello World!", Encoding.Default)
                          .Build();

            // Assert
            Assert.IsNotNull(request);
        }
Beispiel #3
0
        public void RequestGetHeader_GetNonExistingHeader_ReturnsNull()
        {
            // Act
            var request = _requestBuilder
                          .SetMethod(HttpMethodType.Connect)
                          .SetTarget(UniformResourceIdentifier.FromString("/index.html"))
                          .SetHttpVersion(HttpVersionType.Http1_1)
                          .SetHeader("Host", "example.com")
                          .SetBody("Hello World!", Encoding.Default)
                          .Build();

            // Arrange
            Assert.IsNull(request.GetHeader("NonExistingField"));
        }
Beispiel #4
0
        public void SetHeader_AddValidHeader_ReturnsTheSameHeader(string fieldName, string fieldValue)
        {
            // Act
            var request = _requestBuilder
                          .SetMethod(HttpMethodType.Connect)
                          .SetTarget(UniformResourceIdentifier.FromString("/index.html"))
                          .SetHttpVersion(HttpVersionType.Http1_1)
                          .SetHeader(fieldName, fieldValue)
                          .SetBody("Hello World!", Encoding.Default)
                          .Build();

            // Assert
            Assert.AreEqual(fieldValue, request.GetHeader(fieldName));
        }
Beispiel #5
0
        public void Target_SetsTarget_ReturnsTheSameTarget()
        {
            // Arrange
            var uri = UniformResourceIdentifier.FromString("/index.html");

            // Act
            var request = _requestBuilder
                          .SetMethod(HttpMethodType.Connect)
                          .SetTarget(uri)
                          .SetHttpVersion(HttpVersionType.Http1_1)
                          .SetHeader("Host", "example.com")
                          .SetBody("Hello World!", Encoding.Default)
                          .Build();

            // Assert
            Assert.AreEqual(uri, request.Target);
        }
Beispiel #6
0
        /// <summary>
        /// This method sets the target of the request.
        /// </summary>
        /// <param name="uri">
        /// The target of the request.
        /// </param>
        /// <returns>
        /// This instance.
        /// </returns>

        public RequestBuilder SetTarget(UniformResourceIdentifier uri)
        {
            _target = uri ?? throw new ArgumentNullException(nameof(uri));
            return(this);
        }
Beispiel #7
0
 public void Parse_RelativeUri_Throws() => Assert.Throws <ArgumentException>(() => UniformResourceIdentifier.Parse("example.com"));
Beispiel #8
0
        public void Parse_ResultsInCorrectType(string uri, Type expectedType)
        {
            var result = UniformResourceIdentifier.Parse(uri);

            Assert.IsType(expectedType, result);
        }