Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY ./publish ./
ENTRYPOINT ["dotnet", "Linker.dll"]
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: Visual Studio 2019
image: Visual Studio 2022
environment:
DeploymentUser: linker-deployer
DeploymentPassword:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.100",
"version": "6.0.100",
"rollForward": "latestFeature"
}
}
22 changes: 0 additions & 22 deletions src/Linker/Host/Program.cs

This file was deleted.

9 changes: 3 additions & 6 deletions src/Linker/Linker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<LangVersion>8.0</LangVersion>
<LangVersion>10</LangVersion>
<DebugType>portable</DebugType>
<NoWarn>1701;NU1603</NoWarn>
<OutputType>Exe</OutputType>
Expand All @@ -27,10 +27,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Linker/Model/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public Link(object id, Uri href)
Href = href;
}

public object Id { get; }
public object Id { get; set; }

public Uri Href { get; }
public Uri Href { get; set; }
}
}
86 changes: 86 additions & 0 deletions src/Linker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.IO;
using Linker.Model;
using Linker.Web.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

var webApplicationOptions = new WebApplicationOptions
{
Args = args,
ContentRootPath = Directory.GetCurrentDirectory(),
};
var builder = WebApplication.CreateBuilder(webApplicationOptions);

builder.Services.AddRouting();
builder.Services.AddControllers();
builder.Services.AddLinkInMemoryStore();

builder.Host
.ConfigureLogging(log => log.AddConsole());

builder.WebHost
.UseKestrel()
.UseIISIntegration();

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

app.MapGet("/{id}", (string id, IRetrieveLinks getLink) =>
{
var link = getLink.WithId(id);

return link.HasValue
? Results.Redirect(link.Value.Href.AbsoluteUri, true)
: Results.NotFound();
}).WithName("Follow");

app.MapGet("/link/{id}", (string id, IRetrieveLinks getLink) =>
{
var link = getLink.WithId(id);

return link.HasValue
? Results.Ok(link)
: Results.NotFound();
}).WithName("Metadata");

app.MapPut("/link/{id}", (string id, HttpContext ctx, ISaveLinks saveLink)
=> Create(id, ctx.Request.Form["url"], saveLink));

app.MapPost("/link", (HttpContext ctx, ISaveLinks saveLink) =>
{
var url = ctx.Request.Form["url"];

return Create(UniqueId(), url, saveLink);

string UniqueId() => Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
});

static IResult Create(string id, string url, ISaveLinks saveLink)
{
if (IsNotAbsoluteUri(url))
{
return Results.BadRequest("Invalid or missing URL");
}

saveLink.WithIdAndUrl(id, new Uri(url));

return Results.CreatedAtRoute("Follow", new { id }, url);

bool IsNotAbsoluteUri(string uri) => !Uri.IsWellFormedUriString(uri, UriKind.Absolute);
}

app.Run();

public partial class Program { }
73 changes: 0 additions & 73 deletions src/Linker/Web/Controllers/LinkController.cs

This file was deleted.

27 changes: 0 additions & 27 deletions src/Linker/Web/Startup.cs

This file was deleted.

30 changes: 30 additions & 0 deletions test/Linker.Tests/CustomWebApplicationFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Linker.Model;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;

namespace Linker.Tests;

public class CustomWebApplicationFactory : WebApplicationFactory<Program>
{
public readonly ISaveLinks SaveLinks = Substitute.For<ISaveLinks>();
public readonly IRetrieveLinks GetLinks = Substitute.For<IRetrieveLinks>();

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices(services =>
{
var saveLinks = services.Single(d => d.ServiceType == typeof(ISaveLinks));
var retrieveLinks = services.Single(d => d.ServiceType == typeof(IRetrieveLinks));

services.Remove(saveLinks);
services.Remove(retrieveLinks);

services.AddScoped(_ => SaveLinks);
services.AddScoped(_ => GetLinks);
});
}
}
30 changes: 0 additions & 30 deletions test/Linker.Tests/Extensions/ActionResultExtensions.cs

This file was deleted.

This file was deleted.

16 changes: 10 additions & 6 deletions test/Linker.Tests/Linker.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<DebugType>portable</DebugType>
<NoWarn>1701;NU1603</NoWarn>
<AssemblyName>Linker.Tests</AssemblyName>
Expand All @@ -16,13 +16,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.6.0">
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="FluentAssertions" Version="4.14.0" />
<PackageReference Include="NSubstitute" Version="2.0.2" />
</ItemGroup>
Expand Down
Loading