Skip to content

Commit

Permalink
Merge pull request #385 from martincostello/DotNet-6
Browse files Browse the repository at this point in the history
Update to .NET 6
  • Loading branch information
martincostello authored Nov 8, 2021
2 parents f82664a + 1869091 commit 4bf3f68
Show file tree
Hide file tree
Showing 84 changed files with 7,697 additions and 7,958 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Namespace preferences
csharp_style_namespace_declarations = file_scoped

###############################
# C# Formatting Rules #
###############################
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: codecov/codecov-action@v1
name: Upload coverage to Codecov
with:
file: ./artifacts/coverage.net5.0.cobertura.xml
file: ./artifacts/coverage.net6.0.cobertura.xml
flags: ${{ matrix.os_name }}

- name: Publish artifacts
Expand Down
2 changes: 1 addition & 1 deletion .vsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.5.0",
"Microsoft.NetCore.Component.Runtime.6.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,8 @@ Added overloads to support specifying the name of the Initial Catalog using the
* Publish symbol packages to NuGet.org.
* Use GitHub Actions for CI.
* Prepare for .NET 6.

# SqlLocalDb v3.1.0

## Added
* Add `net6.0` Target Framework Moniker.
3 changes: 1 addition & 2 deletions CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Martin Costello, 2012-2018. All rights reserved.
// Copyright (c) Martin Costello, 2012-2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System;
using System.Reflection;
using System.Runtime.InteropServices;

Expand Down
13 changes: 11 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GenerateGitMetadata Condition=" '$(CI)' != '' and '$(GenerateGitMetadata)' == '' ">true</GenerateGitMetadata>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);CA1054;CA2234</NoWarn>
<NoWarn>$(NoWarn);CA1054;CA1848;CA2234</NoWarn>
<NoWarn Condition=" '$(GenerateDocumentationFile)' != 'true' ">$(NoWarn);SA0001</NoWarn>
<Nullable>enable</Nullable>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -37,7 +38,7 @@
<SignAssembly>true</SignAssembly>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<VersionPrefix>3.0.2</VersionPrefix>
<VersionPrefix>3.1.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>
Expand All @@ -53,4 +54,12 @@
<Threshold Condition=" '$(OS)' == 'Windows_NT' ">80</Threshold>
<Threshold Condition=" '$(OS)' != 'Windows_NT' ">40</Threshold>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Globalization" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<Using Include="Shouldly" />
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
</ItemGroup>
</Project>
17 changes: 8 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<PackageVersion Include="Humanizer" Version="2.11.10" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
<PackageVersion Include="Moq" Version="4.16.1" />
<PackageVersion Include="NodaTime" Version="$(NodaTimeVersion)" />
<PackageVersion Include="NodaTime.Testing" Version="$(NodaTimeVersion)" />
<PackageVersion Include="ReportGenerator" Version="4.8.13" />
<PackageVersion Include="Shouldly" Version="4.0.3" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.354" />
<PackageVersion Include="xunit" Version="2.4.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
Expand All @@ -26,17 +26,16 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' == 'MartinCostello.SqlLocalDb' and '$(TargetFramework)' == 'net5.0' ">
<ItemGroup Condition=" '$(AssemblyName)' == 'MartinCostello.SqlLocalDb' and '$(TargetFramework)' == 'net6.0' ">
<PackageVersion Include="Microsoft.Data.SqlClient" Version="2.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' != 'MartinCostello.SqlLocalDb' ">
<PackageVersion Include="Microsoft.Data.SqlClient" Version="3.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
Expand Down
4 changes: 2 additions & 2 deletions SqlLocalDb.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28922.388
# Visual Studio Version 17
VisualStudioVersion = 17.0.31612.314
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E207A447-68A1-4D72-B24F-89FB7890AE12}"
ProjectSection(SolutionItems) = preProject
Expand Down
6 changes: 4 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ function DotNetBuild {
function DotNetPack {
param([string]$Project)

$PackageOutputPath = (Join-Path $OutputPath "packages")

if ($VersionSuffix) {
& $dotnet pack $Project --output (Join-Path $OutputPath "packages") --configuration $Configuration --version-suffix "$VersionSuffix" --include-symbols --include-source
& $dotnet pack $Project --output $PackageOutputPath --configuration $Configuration --version-suffix "$VersionSuffix" --include-symbols --include-source
}
else {
& $dotnet pack $Project --output (Join-Path $OutputPath "packages") --configuration $Configuration --include-symbols --include-source
& $dotnet pack $Project --output $PackageOutputPath --configuration $Configuration --include-symbols --include-source
}
if ($LASTEXITCODE -ne 0) {
throw "dotnet pack failed with exit code $LASTEXITCODE"
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": "5.0.402",
"version": "6.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ This project is licensed under the [Apache 2.0](http://www.apache.org/licenses/L

## Building and Testing

Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version `5.0.100` or later).
Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version `6.0.100` or later).

For all of the tests to be functional you must also have at least one version of SQL LocalDB installed.

Expand Down
3 changes: 2 additions & 1 deletion samples/TodoApp.Tests/TodoApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CA1303;CA1707;CA2007;SA1600</NoWarn>
<RootNamespace>TodoApp</RootNamespace>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="MartinCostello.Logging.XUnit" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NodaTime.Testing" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Xunit.SkippableFact" />
Expand Down
148 changes: 71 additions & 77 deletions samples/TodoApp.Tests/TodoRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,108 @@
// Copyright (c) Martin Costello, 2012-2018. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MartinCostello.SqlLocalDb;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NodaTime;
using NodaTime.Testing;
using TodoApp.Data;
using Xunit;
using Xunit.Abstractions;

namespace TodoApp.Tests
namespace TodoApp.Tests;

public class TodoRepositoryTests
{
public class TodoRepositoryTests
public TodoRepositoryTests(ITestOutputHelper outputHelper)
{
public TodoRepositoryTests(ITestOutputHelper outputHelper)
{
LoggerFactory = outputHelper.ToLoggerFactory();
}
LoggerFactory = outputHelper.ToLoggerFactory();
}

private ILoggerFactory LoggerFactory { get; }
private ILoggerFactory LoggerFactory { get; }

[SkippableFact]
public async Task Can_Create_Update_And_Delete_Todo_Items()
{
// Arrange
Skip.IfNot(
OperatingSystem.IsWindows(),
"This test can only be run on Windows.");
[SkippableFact]
public async Task Can_Create_Update_And_Delete_Todo_Items()
{
// Arrange
Skip.IfNot(
OperatingSystem.IsWindows(),
"This test can only be run on Windows.");

var now = new DateTimeOffset(2018, 08, 12, 10, 41, 0, TimeSpan.Zero);
var clock = new FakeClock(Instant.FromDateTimeOffset(now));
var now = new DateTimeOffset(2018, 08, 12, 10, 41, 0, TimeSpan.Zero);
var clock = new FakeClock(Instant.FromDateTimeOffset(now));

var options = new SqlLocalDbOptions()
{
AutomaticallyDeleteInstanceFiles = true,
StopOptions = StopInstanceOptions.NoWait,
StopTimeout = TimeSpan.FromSeconds(1),
};
var options = new SqlLocalDbOptions()
{
AutomaticallyDeleteInstanceFiles = true,
StopOptions = StopInstanceOptions.NoWait,
StopTimeout = TimeSpan.FromSeconds(1),
};

using var localDB = new SqlLocalDbApi(options, LoggerFactory);
using TemporarySqlLocalDbInstance instance = localDB.CreateTemporaryInstance(deleteFiles: true);
using var localDB = new SqlLocalDbApi(options, LoggerFactory);
using TemporarySqlLocalDbInstance instance = localDB.CreateTemporaryInstance(deleteFiles: true);

var builder = new DbContextOptionsBuilder<TodoContext>()
.UseSqlServer(instance.ConnectionString);
var builder = new DbContextOptionsBuilder<TodoContext>()
.UseSqlServer(instance.ConnectionString);

using var context = new TodoContext(builder.Options);
await context.Database.MigrateAsync();
using var context = new TodoContext(builder.Options);
await context.Database.MigrateAsync();

var target = new TodoRepository(clock, context);
var target = new TodoRepository(clock, context);

// Act - Verify the repository is empty
IList<TodoItem> items = await target.GetItemsAsync();
// Act - Verify the repository is empty
IList<TodoItem> items = await target.GetItemsAsync();

// Assert
Assert.NotNull(items);
Assert.Empty(items);
// Assert
Assert.NotNull(items);
Assert.Empty(items);

// Arrange - Add a new item
string text = "Buy cheese";
// Arrange - Add a new item
string text = "Buy cheese";

// Act
TodoItem item = await target.AddItemAsync(text);
// Act
TodoItem item = await target.AddItemAsync(text);

// Assert
Assert.NotNull(item);
Assert.NotEqual(Guid.Empty, item.Id);
Assert.Equal(text, item.Text);
Assert.Equal(now, item.CreatedAt);
Assert.Null(item.CompletedAt);
// Assert
Assert.NotNull(item);
Assert.NotEqual(Guid.Empty, item.Id);
Assert.Equal(text, item.Text);
Assert.Equal(now, item.CreatedAt);
Assert.Null(item.CompletedAt);

// Arrange - Mark the item as completed
Guid id = item.Id;
// Arrange - Mark the item as completed
Guid id = item.Id;

// Act
bool? completeResult = await target.CompleteItemAsync(id);
// Act
bool? completeResult = await target.CompleteItemAsync(id);

// Assert
Assert.True(completeResult);
// Assert
Assert.True(completeResult);

// Act - Verify the repository has one item that is completed
items = await target.GetItemsAsync();
// Act - Verify the repository has one item that is completed
items = await target.GetItemsAsync();

// Assert
Assert.NotNull(items);
Assert.NotEmpty(items);
Assert.Equal(1, items.Count);
// Assert
Assert.NotNull(items);
Assert.NotEmpty(items);
Assert.Equal(1, items.Count);

item = items[0];
Assert.NotNull(item);
Assert.NotEqual(Guid.Empty, item.Id);
Assert.Equal(text, item.Text);
Assert.Equal(now, item.CreatedAt);
Assert.Equal(now, item.CompletedAt);
item = items[0];
Assert.NotNull(item);
Assert.NotEqual(Guid.Empty, item.Id);
Assert.Equal(text, item.Text);
Assert.Equal(now, item.CreatedAt);
Assert.Equal(now, item.CompletedAt);

// Act - Delete the item
bool deleteResult = await target.DeleteItemAsync(id);
// Act - Delete the item
bool deleteResult = await target.DeleteItemAsync(id);

// Assert
Assert.True(deleteResult);
// Assert
Assert.True(deleteResult);

// Act - Verify the repository is empty again
items = await target.GetItemsAsync();
// Act - Verify the repository is empty again
items = await target.GetItemsAsync();

// Assert
Assert.NotNull(items);
Assert.Empty(items);
}
// Assert
Assert.NotNull(items);
Assert.Empty(items);
}
}
Loading

0 comments on commit 4bf3f68

Please sign in to comment.