-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from martincostello/DotNet-6
Update to .NET 6
- Loading branch information
Showing
84 changed files
with
7,697 additions
and
7,958 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.