Skip to content

Commit 4b72af2

Browse files
committed
Remove obsolete test files and add new API implementation with weather forecast endpoint
1 parent d2442e7 commit 4b72af2

File tree

12 files changed

+162
-0
lines changed

12 files changed

+162
-0
lines changed

Api/src/UrlShortener.Api/Api.http

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@Api_HostAddress = http://localhost:5003
2+
3+
GET {{Api_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Azure.Identity;
2+
3+
var builder = WebApplication.CreateBuilder(args);
4+
5+
var keyVaultName = builder.Configuration["KeyVaultName"];
6+
if(!string.IsNullOrEmpty(keyVaultName))
7+
{
8+
builder.Configuration.AddAzureKeyVault(
9+
new Uri($"https://{keyVaultName}.vault.azure.net/"),
10+
new DefaultAzureCredential());
11+
}
12+
13+
builder.Services.AddOpenApi();
14+
15+
var app = builder.Build();
16+
17+
if (app.Environment.IsDevelopment())
18+
{
19+
app.MapOpenApi();
20+
}
21+
22+
app.UseHttpsRedirection();
23+
24+
var summaries = new[]
25+
{
26+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
27+
};
28+
29+
app.MapGet("/weatherforecast", () =>
30+
{
31+
var forecast = Enumerable.Range(1, 5).Select(index =>
32+
new WeatherForecast
33+
(
34+
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
35+
Random.Shared.Next(-20, 55),
36+
summaries[Random.Shared.Next(summaries.Length)]
37+
))
38+
.ToArray();
39+
return forecast;
40+
})
41+
.WithName("GetWeatherForecast");
42+
43+
app.Run();
44+
45+
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
46+
{
47+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
48+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": false,
8+
"applicationUrl": "http://localhost:5003",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": false,
17+
"applicationUrl": "https://localhost:7125;http://localhost:5003",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
11+
<PackageReference Include="Azure.Identity" Version="1.13.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Text;
2+
3+
namespace UrlShortener.Api.Core.Tests;
4+
5+
public class Base62EncodingScenarios
6+
{
7+
[Theory]
8+
[InlineData(0,"0")]
9+
[InlineData(1,"1")]
10+
[InlineData(20,"k")]
11+
[InlineData(62,"10")]
12+
public void Should_encode_number_to_base62(long number,string expected)
13+
{
14+
number.EncodeToBase62()
15+
.Should()
16+
.Be(expected);
17+
}
18+
}

0 commit comments

Comments
 (0)