public void the_filename_parameter_is_parsed()
        {
            var header = new ContentDispositionHeader("form-data;filename=\"test\"");

            header.FileName.
            ShouldBe("test");
        }
        public void the_toString_method_normalize_the_header()
        {
            var header = new ContentDispositionHeader("form-data ; name= \"hi\";");

            header.ToString().
            ShouldBe("form-data; name=\"hi\"");
        }
        public void whitespace_in_parameters_is_ignored()
        {
            var header = new ContentDispositionHeader("form-data ; name = \"hi \";");

            header.Name
            .ShouldBe("hi ");
        }
        public void the_name_parameter_is_parsed()
        {
            var header = new ContentDispositionHeader("form-data;name=\"hi\"");

            header.Name.
            ShouldBe("hi");
        }
        public void the_first_value_is_the_disposition()
        {
            var header = new ContentDispositionHeader("form-data");

            header.Disposition.
            ShouldBe("form-data");
        }
        public void fields_can_contain_semi_colons()
        {
            var header = new ContentDispositionHeader("form-data;filename=\"test;name\"");

            header.FileName.
            ShouldBe("test;name");
        }
Ejemplo n.º 7
0
        public void contentdisposition___equals_overload_null_sccess()
        {
            ContentDispositionHeader header1 = "form-data; name=\"Test\"";
            ContentDispositionHeader header2 = null;

            var equals = header1.Equals(header2);

            equals.Should().BeFalse();
        }
Ejemplo n.º 8
0
        public void contentdisposition___equals_overload_not_string_or_equivelent_sccess()
        {
            ContentDispositionHeader header1 = "form-data; name=\"Test\"";
            var other = 2;

            var equals = header1.Equals(other);

            equals.Should().BeFalse();
        }
Ejemplo n.º 9
0
        public void contentdisposition___gethashcode_success()
        {
            ContentDispositionHeader header = "form-data; name=\"Test\"";

            header.Should().NotBeNull();

            var hashCode = header.GetHashCode();

            hashCode.Should().NotBe(0);
        }
Ejemplo n.º 10
0
        public void contentdisposition___notequals_operator_header_success(string contentDisposition)
        {
            string value = $"form-data; name=\"test\"; filename*=\"MyFileName.jpg\"; filename=\"MyFile.jpg\"; size=10; creation-date=\"2020-02-04\"; modification-date=\"2020-02-02\"; read-date=\"2020-02-03\"";

            var contentType1 = new ContentDispositionHeader(contentDisposition);
            var contentType2 = new ContentDispositionHeader(value);

            var equals = contentType1 != contentType2;

            equals.Should().Be(true);
        }
Ejemplo n.º 11
0
        public void contentdisposition___equals_override_success(string contentDisposition)
        {
            string value = $"form-data; name=\"test\"; filename*=\"MyFileName.jpg\"; filename=\"MyFile.jpg\"; size=10; creation-date=\"2020-02-04\"; modification-date=\"2020-02-02\"; read-date=\"2020-02-03\"";

            var header = new ContentDispositionHeader(contentDisposition);

            var equals = header.Equals(value);

            equals.Should().Be(true);

            equals = header.Equals(new ContentDispositionHeader(value));
            equals.Should().Be(true);
        }
Ejemplo n.º 12
0
        public void contentdisposition___ctor_basic_returns_type(string type, ContentDispositionType expected)
        {
            var header = new ContentDispositionHeader($"{type}");

            header.Should().NotBeNull();
            header.Type.Should().Be(expected);
            header.FileName.Should().BeEmpty();
            header.FileNameStar.Should().BeEmpty();
            header.Name.Should().BeEmpty();
            header.Size.Should().BeNull();
            header.CreationDate.Should().BeNull();
            header.ModificationDate.Should().BeNull();
            header.ReadDate.Should().BeNull();
            header.Value.Should().Be($"{type}");
        }
Ejemplo n.º 13
0
        public void contentdisposition___ctor_returns_default_for_null_or_whitespace(string value)
        {
            var header = new ContentDispositionHeader(value);

            header.Should().NotBeNull();
            header.Type.Should().Be(ContentDispositionType.None);
            header.FileName.Should().BeEmpty();
            header.FileNameStar.Should().BeEmpty();
            header.Name.Should().BeEmpty();
            header.Size.Should().BeNull();
            header.CreationDate.Should().BeNull();
            header.ModificationDate.Should().BeNull();
            header.ReadDate.Should().BeNull();
            header.Value.Should().Be(value);
        }
Ejemplo n.º 14
0
        public void contentdisposition___ctor_standard_noquotes_returns_values()
        {
            string value = "form-data; name=test; filename=MyFile.jpg; filename*=MyFileName.jpg; size=10";

            var header = new ContentDispositionHeader(value);

            header.Should().NotBeNull();
            header.Type.Should().Be(ContentDispositionType.form_data);
            header.FileName.Should().Be("MyFile.jpg");
            header.FileNameStar.Should().Be("MyFileName.jpg");
            header.Name.Should().Be("test");
            header.Size.Should().Be(10);
            header.CreationDate.Should().BeNull();
            header.ModificationDate.Should().BeNull();
            header.ReadDate.Should().BeNull();
            header.Value.Should().Be(value);
        }
Ejemplo n.º 15
0
        public void contentdisposition___assignment_standard_returns_values()
        {
            string value = "form-data; name=\"test\"; filename=\"MyFile.jpg\"; filename*=\"MyFileName.jpg\"; size=10";

            ContentDispositionHeader header = value;

            header.Should().NotBeNull();
            header.Type.Should().Be(ContentDispositionType.form_data);
            header.FileName.Should().Be("MyFile.jpg");
            header.FileNameStar.Should().Be("MyFileName.jpg");
            header.Name.Should().Be("test");
            header.Size.Should().Be(10);
            header.CreationDate.Should().BeNull();
            header.ModificationDate.Should().BeNull();
            header.ReadDate.Should().BeNull();
            header.Value.Should().Be(value);
        }
        private void SetContentDispositionHeader(ApiResponse response, IRestResponse <TResponse> restResponse)
        {
            var header = response.Headers.GetHeader(HttpResponseHeaderConstants.ContentDisposition);

            if (header != null && header.HasValue == true)
            {
                var contentDisposition = new ContentDispositionHeader(header.Value);

                response.Headers.ContentDisposition = contentDisposition;

                if (response.DownloadFile != null)
                {
                    string fileName    = contentDisposition.FileName;
                    string contentType = _mimeMapper.GetMimeMapping(fileName);

                    response.DownloadFile.ContentType = contentType;
                    response.DownloadFile.FileName    = fileName;
                    response.DownloadFile.Size        = restResponse.ContentLength;
                }
            }
        }
Ejemplo n.º 17
0
        public void contentdisposition___assignment_full_returns_values()
        {
            var now       = DateTimeOffset.Now;
            var nowString = now.ToString(CultureInfo.InvariantCulture);

            string value = $"form-data; name=\"test\"; filename=\"MyFile.jpg\"; filename*=\"MyFileName.jpg\"; size=10; creation-date=\"{now}\"; modification-date=\"{now}\"; read-date=\"{now}\"; ";

            ContentDispositionHeader header = value;

            header.Should().NotBeNull();
            header.Type.Should().Be(ContentDispositionType.form_data);
            header.FileName.Should().Be("MyFile.jpg");
            header.FileNameStar.Should().Be("MyFileName.jpg");
            header.Name.Should().Be("test");
            header.Size.Should().Be(10);
            header.CreationDate.Should().NotBeNull();
            header.CreationDate.Value.ToString(CultureInfo.InvariantCulture).Should().Be(nowString);
            header.ModificationDate.Should().NotBeNull();
            header.ModificationDate.Value.ToString(CultureInfo.InvariantCulture).Should().Be(nowString);
            header.ReadDate.Should().NotBeNull();
            header.ReadDate.Value.ToString(CultureInfo.InvariantCulture).Should().Be(nowString);
            header.Value.Should().Be(value);
        }
 public void whitespace_in_parameters_is_ignored()
 {
     var header = new ContentDispositionHeader("form-data ; name = \"hi \";");
     header.Name
         .ShouldBe("hi ");
 }
 public void the_toString_method_normalize_the_header()
 {
     var header = new ContentDispositionHeader("form-data ; name= \"hi\";");
     header.ToString().
         ShouldBe("form-data; name=\"hi\"");
 }
 public void the_name_parameter_is_parsed()
 {
     var header = new ContentDispositionHeader("form-data;name=\"hi\"");
     header.Name.
         ShouldBe("hi");
 }
 public void the_first_value_is_the_disposition()
 {
     var header = new ContentDispositionHeader("form-data");
     header.Disposition.
         ShouldBe("form-data");
 }
 public void the_filename_parameter_is_parsed()
 {
     var header = new ContentDispositionHeader("form-data;filename=\"test\"");
     header.FileName.
         ShouldBe("test");
 }
 public void fields_can_contain_semi_colons()
 {
     var header = new ContentDispositionHeader("form-data;filename=\"test;name\"");
     header.FileName.
         ShouldBe("test;name");
 }