Skip to content

Commit

Permalink
Upgrade to .NET 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 11, 2021
1 parent b4644f4 commit 822815f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 111 deletions.
2 changes: 1 addition & 1 deletion MyApp.ServiceInterface/MyApp.ServiceInterface.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MyApp.ServiceModel/MyApp.ServiceModel.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
51 changes: 25 additions & 26 deletions MyApp.Tests/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@
using MyApp.ServiceInterface;
using MyApp.ServiceModel;

namespace MyApp.Tests
namespace MyApp.Tests;

public class IntegrationTest
{
public class IntegrationTest
const string BaseUri = "http://localhost:2000/";
private readonly ServiceStackHost appHost;

class AppHost : AppSelfHostBase
{
const string BaseUri = "http://localhost:2000/";
private readonly ServiceStackHost appHost;
public AppHost() : base(nameof(IntegrationTest), typeof(MyServices).Assembly) { }

class AppHost : AppSelfHostBase
public override void Configure(Container container)
{
public AppHost() : base(nameof(IntegrationTest), typeof(MyServices).Assembly) { }

public override void Configure(Container container)
{
}
}
}

public IntegrationTest()
{
appHost = new AppHost()
.Init()
.Start(BaseUri);
}
public IntegrationTest()
{
appHost = new AppHost()
.Init()
.Start(BaseUri);
}

[OneTimeTearDown]
public void OneTimeTearDown() => appHost.Dispose();
[OneTimeTearDown]
public void OneTimeTearDown() => appHost.Dispose();

public IServiceClient CreateClient() => new JsonServiceClient(BaseUri);
public IServiceClient CreateClient() => new JsonServiceClient(BaseUri);

[Test]
public void Can_call_Hello_Service()
{
var client = CreateClient();
[Test]
public void Can_call_Hello_Service()
{
var client = CreateClient();

var response = client.Get(new Hello { Name = "World" });
var response = client.Get(new Hello { Name = "World" });

Assert.That(response.Result, Is.EqualTo("Hello, World!"));
}
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
}
}
8 changes: 4 additions & 4 deletions MyApp.Tests/MyApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
</PropertyGroup>
Expand All @@ -10,9 +10,9 @@
<ProjectReference Include="..\MyApp.ServiceInterface\MyApp.ServiceInterface.csproj" />
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />

<PackageReference Include="NUnit" Version="3.12.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.*" />
<PackageReference Include="NUnit" Version="3.13.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="ServiceStack" Version="5.*" />
<PackageReference Include="ServiceStack.Kestrel" Version="5.*" />
</ItemGroup>
Expand Down
37 changes: 18 additions & 19 deletions MyApp.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
using MyApp.ServiceInterface;
using MyApp.ServiceModel;

namespace MyApp.Tests
namespace MyApp.Tests;

public class UnitTest
{
public class UnitTest
{
private readonly ServiceStackHost appHost;
private readonly ServiceStackHost appHost;

public UnitTest()
{
appHost = new BasicAppHost().Init();
appHost.Container.AddTransient<MyServices>();
}
public UnitTest()
{
appHost = new BasicAppHost().Init();
appHost.Container.AddTransient<MyServices>();
}

[OneTimeTearDown]
public void OneTimeTearDown() => appHost.Dispose();
[OneTimeTearDown]
public void OneTimeTearDown() => appHost.Dispose();

[Test]
public void Can_call_MyServices()
{
var service = appHost.Container.Resolve<MyServices>();
[Test]
public void Can_call_MyServices()
{
var service = appHost.Container.Resolve<MyServices>();

var response = (HelloResponse)service.Any(new Hello { Name = "World" });
var response = (HelloResponse)service.Any(new Hello { Name = "World" });

Assert.That(response.Result, Is.EqualTo("Hello, World!"));
}
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
}
}
}
36 changes: 36 additions & 0 deletions MyApp/Configure.AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Funq;
using ServiceStack;
using MyApp.ServiceInterface;

[assembly: HostingStartup(typeof(MyApp.AppHost))]

namespace MyApp;

public class AppHost : AppHostBase, IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
// Configure ASP.NET Core IOC Dependencies
})
.Configure(app => {
// Configure ASP.NET Core App
if (!HasInit)
app.UseServiceStack(new AppHost());
app.Run(context =>
{
context.Response.Redirect("/metadata");
return Task.FromResult(0);
});
});

public AppHost() : base("MyApp", typeof(MyServices).Assembly) {}

public override void Configure(Container container)
{
// Configure ServiceStack only IOC, Config & Plugins
SetConfig(new HostConfig {
UseSameSiteCookies = true,
});
}
}
9 changes: 7 additions & 2 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>MyApp</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>MyApp</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.*" />
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ServiceStack" Version="5.*" />
</ItemGroup>

Expand Down
69 changes: 11 additions & 58 deletions MyApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,15 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Funq;
using Microsoft.Extensions.Configuration;
using ServiceStack;
using MyApp.ServiceInterface;
using MyApp.ServiceModel;
var builder = WebApplication.CreateBuilder(args);

namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseModularStartup<Startup>()
.UseUrls(Environment.GetEnvironmentVariable("ASPNETCORE_URLS") ?? "http://localhost:5000/")
.Build();

host.Run();
}
}

public class Startup : ModularStartup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public new void ConfigureServices(IServiceCollection services)
{
}
var app = builder.Build();

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseServiceStack(new AppHost());

app.Run(context =>
{
context.Response.Redirect("/metadata");
return Task.FromResult(0);
});
}
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
}

public class AppHost : AppHostBase
{
public AppHost()
: base("MyApp", typeof(MyServices).Assembly) { }
app.Run();

public override void Configure(Container container)
{
}
}
}

0 comments on commit 822815f

Please sign in to comment.