1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
6- using Backtrace . Model ;
1+ using Backtrace . Model ;
72using NUnit . Framework ;
3+ using System ;
84namespace Backtrace . Tests . ClientTests
95{
106 /// <summary>
@@ -21,23 +17,7 @@ public void TestInvalidSectionName(string sectionName)
2117 {
2218 Assert . Throws < InvalidOperationException > ( ( ) => new BacktraceClient ( sectionName ) ) ;
2319 }
24- #endif
25-
26- [ TestCase ( "InvalidUrl" ) ]
27- [ Test ( Author = "Konrad Dysput" , Description = "Test invalid api url section" ) ]
28- public void TestInvalidUrlArgument ( string sectionName )
29- {
30- //if programmer pass invalid url should throw UriFormatException
31- //if programmer pass null or empty string as token should throw ArgumentNullException
32-
33- #if NET35 || NET45
34- Assert . Throws < UriFormatException > ( ( ) => new BacktraceClient ( sectionName ) ) ;
35- #endif
36- Assert . Throws < ArgumentException > ( ( ) => new BacktraceClient ( new BacktraceCredentials ( "https://test.backtrace.io" , string . Empty ) ) ) ;
37- }
3820
39-
40- #if NET35 || NET45
4121 [ TestCase ( "EmptyToken" ) ]
4222 [ Test ( Author = "Konrad Dysput" , Description = "Test invalid token section" ) ]
4323 public void TestInvalidTokenArgument ( string sectionName )
@@ -51,8 +31,78 @@ public void TestValidSectionConfiguration(string sectionName)
5131 {
5232 Assert . DoesNotThrow ( ( ) => new BacktraceClient ( sectionName ) ) ;
5333 }
54-
5534#endif
5635
36+ [ TestCase ( "https://backtrace.sp.backtrace.io" ) ]
37+ [ TestCase ( "http://backtrace.sp.backtrace.io" ) ]
38+ [ TestCase ( "http://backtrace.sp.backtrace.io:6098" ) ]
39+ [ TestCase ( "http://backtrace.sp.backtrace.io:7777" ) ]
40+ [ TestCase ( "http://backtrace.sp.backtrace.io:7777/" ) ]
41+ [ TestCase ( "http://backtrace.sp.backtrace.io/" ) ]
42+ [ Test ( Author = "Konrad Dysput" , Description = "Test valid submission url" ) ]
43+ public void GenerateSubmissionUrl_FromValidHostName_ValidSubmissionUrl ( string host )
44+ {
45+ const string token = "1234" ;
46+ var credentials = new BacktraceCredentials ( host , token ) ;
47+
48+ string expectedUrl = $ "{ credentials . BacktraceHostUri . AbsoluteUri } post?format=json&token={ credentials . Token } ";
49+ Assert . AreEqual ( credentials . GetSubmissionUrl ( ) , expectedUrl ) ;
50+ }
51+
52+ [ TestCase ( "https://www.submit.backtrace.io" ) ]
53+ [ TestCase ( "http://www.submit.backtrace.io" ) ]
54+ [ TestCase ( "https://submit.backtrace.io" ) ]
55+ [ TestCase ( "https://submit.backtrace.io/12312/312312/" ) ]
56+ [ TestCase ( "https://submit.backtrace.io/uri/" ) ]
57+ [ TestCase ( "https://submit.backtrace.io/uri?sumbissionToken=123123134&value=123123/" ) ]
58+ [ TestCase ( "http://submit.backtrace.io" ) ]
59+ [ TestCase ( "http://submit.backtrace.io/" ) ]
60+ public void GenerateBacktraceSubmitUrl_FromSubmitUrl_ValidSubmissionUrl ( string host )
61+ {
62+ var credentials = new BacktraceCredentials ( host ) ;
63+
64+ if ( ! host . StartsWith ( "https://" ) && ! host . StartsWith ( "http://" ) )
65+ {
66+ host = $ "https://{ host } ";
67+ }
68+
69+ if ( ! host . EndsWith ( "/" ) )
70+ {
71+ host += '/' ;
72+ }
73+ Assert . AreEqual ( host , credentials . GetSubmissionUrl ( ) . ToString ( ) ) ;
74+ }
75+
76+ [ TestCase ( "" ) ]
77+ [ TestCase ( "not url" ) ]
78+ [ TestCase ( "123123.." ) ]
79+ [ Test ( Author = "Konrad Dysput" , Description = "Test invalid api url" ) ]
80+ public void ThrowInvalidUrlException_FromINvalidUrl_ThrowException ( string host )
81+ {
82+ Assert . Throws < UriFormatException > ( ( ) => new BacktraceCredentials ( host ) ) ;
83+ Assert . Throws < UriFormatException > ( ( ) => new BacktraceCredentials ( host , "123" ) ) ;
84+ }
85+
86+ [ TestCase ( "https://backtrace.sp.backtrace.io" ) ]
87+ [ TestCase ( "http://backtrace.sp.backtrace.io" ) ]
88+ [ TestCase ( "https://totallynoValidSubmitUrl.submit.backtrace.io/" ) ]
89+ [ Test ( Author = "Konrad Dysput" , Description = "Test invalid api url" ) ]
90+ public void ThrowInvalidArgumentException_FromInvalidHostName_ThrowException ( string host )
91+ {
92+ Assert . Throws < ArgumentException > ( ( ) => new BacktraceCredentials ( host ) ) ;
93+ }
94+
95+ [ TestCase ( "InvalidUrl" ) ]
96+ [ Test ( Author = "Konrad Dysput" , Description = "Test invalid api url section" ) ]
97+ public void TestInvalidUrlArgument ( string sectionName )
98+ {
99+ //if programmer pass invalid url should throw UriFormatException
100+ //if programmer pass null or empty string as token should throw ArgumentNullException
101+
102+ #if NET35 || NET45
103+ Assert . Throws < UriFormatException > ( ( ) => new BacktraceClient ( sectionName ) ) ;
104+ #endif
105+ Assert . Throws < ArgumentException > ( ( ) => new BacktraceClient ( new BacktraceCredentials ( "https://test.backtrace.io" , string . Empty ) ) ) ;
106+ }
57107 }
58108}
0 commit comments