1- namespace AngleSharp . Io . Tests . Network
2- {
3- using FluentAssertions ;
4- using NUnit . Framework ;
5- using System . Net ;
6-
7- [ TestFixture ]
8- public class ResponseTests
9- {
10- [ Test ]
11- public void Initialize ( )
12- {
13- // ARRANGE, ACT
14- var response = new DefaultResponse ( ) ;
15-
16- // ASSERT
17- response . Content . Should ( ) . BeNull ( ) ;
18- response . StatusCode . Should ( ) . Be ( HttpStatusCode . Accepted ) ;
19- response . Headers . Should ( ) . NotBeNull ( ) ;
20- response . Headers . Should ( ) . BeEmpty ( ) ;
21- response . Address . Should ( ) . BeNull ( ) ;
22- }
23- }
24- }
1+ namespace AngleSharp . Io . Network . Tests . Integration
2+ {
3+ using NUnit . Framework ;
4+ using System . Collections . Generic ;
5+
6+ [ TestFixture ]
7+ public class ResponseTests
8+ {
9+ [ Test ]
10+ public void ReadFileNameFromContentDisposition ( )
11+ {
12+ var response = new DefaultResponse
13+ {
14+ Address = Url . Create ( "http://example.com/foo.png" ) ,
15+ Headers = new Dictionary < string , string >
16+ {
17+ { HeaderNames . ContentDisposition , "attachment; filename=\" filename.jpg\" " } ,
18+ }
19+ } ;
20+ var file = response . GetAttachedFileName ( ) ;
21+ Assert . AreEqual ( "filename.jpg" , file ) ;
22+ }
23+
24+ [ Test ]
25+ public void ReadFileNameFromUrlDespiteContentDisposition ( )
26+ {
27+ var response = new DefaultResponse
28+ {
29+ Address = Url . Create ( "http://example.com/foo.png" ) ,
30+ Headers = new Dictionary < string , string >
31+ {
32+ { HeaderNames . ContentDisposition , "attachment" } ,
33+ }
34+ } ;
35+ var file = response . GetAttachedFileName ( ) ;
36+ Assert . AreEqual ( "foo.png" , file ) ;
37+ }
38+
39+ [ Test ]
40+ public void ReadFileNameFromUrlWithoutContentDisposition ( )
41+ {
42+ var response = new DefaultResponse
43+ {
44+ Address = Url . Create ( "http://example.com/foo.png" ) ,
45+ Headers = new Dictionary < string , string >
46+ {
47+ }
48+ } ;
49+ var file = response . GetAttachedFileName ( ) ;
50+ Assert . AreEqual ( "foo.png" , file ) ;
51+ }
52+
53+ [ Test ]
54+ public void ReadFileNameFromUrlWithoutEndingAndMimeType ( )
55+ {
56+ var response = new DefaultResponse
57+ {
58+ Address = Url . Create ( "http://example.com/foo" ) ,
59+ Headers = new Dictionary < string , string >
60+ {
61+ }
62+ } ;
63+ var file = response . GetAttachedFileName ( ) ;
64+ Assert . AreEqual ( "foo.a" , file ) ;
65+ }
66+
67+ [ Test ]
68+ public void ReadFileNameFromUrlWithoutEndingButWithMimeType ( )
69+ {
70+ var response = new DefaultResponse
71+ {
72+ Address = Url . Create ( "http://example.com/foo" ) ,
73+ Headers = new Dictionary < string , string >
74+ {
75+ { HeaderNames . ContentType , "audio/mpeg3" } ,
76+ }
77+ } ;
78+ var file = response . GetAttachedFileName ( ) ;
79+ Assert . AreEqual ( "foo.mp3" , file ) ;
80+ }
81+
82+ [ Test ]
83+ public void IsAttachmentWhenContentDispositionHasAttachmentAndFile ( )
84+ {
85+ var response = new DefaultResponse
86+ {
87+ Address = Url . Create ( "http://example.com/foo.png" ) ,
88+ Headers = new Dictionary < string , string >
89+ {
90+ { HeaderNames . ContentDisposition , "attachment; filename=\" filename.jpg\" " } ,
91+ }
92+ } ;
93+ Assert . IsTrue ( response . IsAttachment ( ) ) ;
94+ }
95+
96+ [ Test ]
97+ public void IsAttachmentWhenContentDispositionHasOnlyAttachment ( )
98+ {
99+ var response = new DefaultResponse
100+ {
101+ Address = Url . Create ( "http://example.com/foo.png" ) ,
102+ Headers = new Dictionary < string , string >
103+ {
104+ { HeaderNames . ContentDisposition , "attachment" } ,
105+ }
106+ } ;
107+ Assert . IsTrue ( response . IsAttachment ( ) ) ;
108+ }
109+
110+ [ Test ]
111+ public void IsNoAttachmentWhenDispositionIsMissing ( )
112+ {
113+ var response = new DefaultResponse
114+ {
115+ Address = Url . Create ( "http://example.com/foo.png" ) ,
116+ Headers = new Dictionary < string , string >
117+ {
118+ }
119+ } ;
120+ Assert . IsFalse ( response . IsAttachment ( ) ) ;
121+ }
122+
123+ [ Test ]
124+ public void IsNoAttachmentWhenDispositionIsInline ( )
125+ {
126+ var response = new DefaultResponse
127+ {
128+ Address = Url . Create ( "http://example.com/foo.png" ) ,
129+ Headers = new Dictionary < string , string >
130+ {
131+ { HeaderNames . ContentDisposition , "inline" } ,
132+ }
133+ } ;
134+ Assert . IsFalse ( response . IsAttachment ( ) ) ;
135+ }
136+ }
137+ }
0 commit comments