File tree Expand file tree Collapse file tree 4 files changed +34
-5
lines changed
Api/src/UrlShortener.Core
UrlShortener.Api.Core.Tests Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,15 @@ public static class Base62EncodingExtensions
55 private const string Alphanumeric = "0123456789" +
66 "abcdefghijklmnopqrstuvwxyz" +
77 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
8- public static string EncodeToBase62 ( this int number )
8+ public static string EncodeToBase62 ( this long number )
99 {
1010 if ( number is 0 ) return Alphanumeric [ 0 ] . ToString ( ) ;
1111
1212 var result = new Stack < char > ( ) ;
1313
1414 while ( number > 0 )
1515 {
16- result . Push ( Alphanumeric [ number % 62 ] ) ;
16+ result . Push ( Alphanumeric [ ( int ) ( number % 62 ) ] ) ;
1717 number /= 62 ;
1818 }
1919
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ public void AssignRange(TokenRange tokenRange)
1111 {
1212 _tokenRange = tokenRange ;
1313 }
14- public int GetToken ( )
14+ public long GetToken ( )
1515 {
16- return _tokenRange ! . Start ;
16+ return _tokenRange . Start ;
1717 }
1818}
Original file line number Diff line number Diff line change 11namespace UrlShortener . Core ;
22
3- public record TokenRange ( int Start , int End ) ;
3+ public record TokenRange
4+ {
5+ public long Start { get ; }
6+ public long End { get ; }
7+
8+ public TokenRange ( long start , long end )
9+ {
10+ if ( end < start )
11+ throw new ArgumentException ( "End must be greater than or equal to start" ) ;
12+
13+ Start = start ;
14+ End = end ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ using UrlShortener . Core ;
2+
3+ namespace UrlShortener . Api . Core . Tests ;
4+
5+ public class TokenRangeScenarios
6+ {
7+ [ Fact ]
8+ public void When_start_token_is_greater_than_end_token_then_throws_exception ( )
9+ {
10+ var act = ( ) => new TokenRange ( 10 , 5 ) ;
11+
12+ act . Should ( )
13+ . Throw < ArgumentException > ( )
14+ . WithMessage ( "End must be greater than or equal to start" ) ;
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments