Skip to content

Commit dd37d1a

Browse files
committed
Add Core test
1 parent cb3b745 commit dd37d1a

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace UrlShortener.Api.Core.Tests;
2+
3+
public class ShortUrlGenerator
4+
{
5+
private readonly TokenProvider _tokenProvider;
6+
7+
public ShortUrlGenerator(TokenProvider tokenProvider)
8+
{
9+
_tokenProvider = tokenProvider;
10+
}
11+
12+
public string GenerateShortUrl()
13+
{
14+
return _tokenProvider
15+
.GetToken()
16+
.EncodeToBase62();
17+
}
18+
}

UrlShortener.Api.Core.Tests/ShortUrlGeneratorScenarios.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public void Should_return_short_url_for_10001()
99
tokenProvider.AssignRange(10001, 20000);
1010
var shortUrlGenerator = new ShortUrlGenerator(tokenProvider);
1111

12-
var shortUrl = shortUrlGenerator.GenerateUniqueUrl();
12+
var shortUrl = shortUrlGenerator.GenerateShortUrl();
1313

1414
shortUrl.Should().Be("2bJ");
1515
}
@@ -22,30 +22,4 @@ public void Should_return_short_url_for_zero()
2222
var shortUrl = shortUrlGenerator.GenerateShortUrl();
2323
shortUrl.Should().Be("0");
2424
}
25-
}
26-
27-
public class TokenProvider
28-
{
29-
public void AssignRange(int i, int i1)
30-
{
31-
throw new NotImplementedException();
32-
}
33-
}
34-
35-
public class ShortUrlGenerator
36-
{
37-
public ShortUrlGenerator(TokenProvider tokenProvider)
38-
{
39-
40-
}
41-
42-
public object GenerateShortUrl()
43-
{
44-
return "0";
45-
}
46-
47-
public object GenerateUniqueUrl()
48-
{
49-
throw new NotImplementedException();
50-
}
5125
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace UrlShortener.Api.Core.Tests;
2+
3+
public class TokenProvider
4+
{
5+
private int _start;
6+
public void AssignRange(int start, int end)
7+
{
8+
9+
}
10+
11+
public int GetToken()
12+
{
13+
return _start;
14+
}
15+
}

0 commit comments

Comments
 (0)