Skip to content

Commit

Permalink
net6.0, #nullable enable
Browse files Browse the repository at this point in the history
  • Loading branch information
hwndmaster committed Nov 14, 2021
1 parent f30e465 commit 90376cd
Show file tree
Hide file tree
Showing 85 changed files with 2,919 additions and 3,014 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.cs]
# RCS1090: Add call to 'ConfigureAwait' (or vice versa)
dotnet_diagnostic.RCS1090.severity = suggestion
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore --runtime "win-x64"
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: |
dotnet nuget add source https://nuget.pkg.github.com/hwndmaster/index.json -n github -u hwndmaster -p ${{ secrets.PRIVATE_PKG_TOKEN }} --store-password-in-clear-text
Expand Down
2 changes: 2 additions & 0 deletions .vscode/project-words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Xunit
Hardcodet
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
"lcov.info"
],
"dotnet-test-explorer.autoWatch": true,
"editor.tabSize": 4
"editor.tabSize": 4,
"cSpell.customDictionaries": {
"project-words": {
"name": "project-words",
"path": "${workspaceRoot}/.vscode/project-words.txt",
"addWords": true
}
}
}
28 changes: 16 additions & 12 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<!-- Microsoft common dependencies -->
<PackageReference Update="System.Reactive" Version="5.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0"/>
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0"/>
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />

<!-- Atom Framework -->
<PackageReference Update="Genius.Atom.Infrastructure" Version="0.0.5" />
<PackageReference Update="Genius.Atom.UI.Forms" Version="0.0.5" />
<PackageReference Update="Genius.Atom.UI.Forms.TestingUtil" Version="0.0.5" />
<PackageReference Update="Genius.Atom.Infrastructure" Version="0.0.6" />
<PackageReference Update="Genius.Atom.UI.Forms" Version="0.0.6" />
<PackageReference Update="Genius.Atom.UI.Forms.TestingUtil" Version="0.0.6" />

<!-- Misc -->
<PackageReference Update="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Update="Humanizer.Core" Version="2.11.10" />
<PackageReference Update="MahApps.Metro" Version="2.4.7" />
<PackageReference Update="ReactiveUI" Version="14.3.1" />
<PackageReference Update="ReactiveUI.WPF" Version="14.3.1" />
<PackageReference Update="MahApps.Metro" Version="2.4.9" />
<PackageReference Update="ReactiveUI" Version="16.3.10" />
<PackageReference Update="ReactiveUI.WPF" Version="16.3.10" />
</ItemGroup>

<!-- Automated Testing components -->
<ItemGroup Condition="$(ProjectName.EndsWith('.Tests'))">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions PriceChecker.Core.Tests/PriceChecker.Core.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>
<RootNamespace>Genius.PriceChecker.Core.Tests</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@

<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<Reference Include="Genius.Atom.Infrastructure">
<HintPath>..\..\atom\Atom.Infrastructure\bin\Debug\net5.0\Genius.Atom.Infrastructure.dll</HintPath>
<HintPath>..\..\atom\Atom.Infrastructure\bin\Debug\net6.0\Genius.Atom.Infrastructure.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
Expand Down
155 changes: 77 additions & 78 deletions PriceChecker.Core.Tests/Repositories/AgentRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,84 @@
using Moq;
using Xunit;

namespace Genius.PriceChecker.Core.Tests.Repositories
namespace Genius.PriceChecker.Core.Tests.Repositories;

public class AgentRepositoryTests
{
public class AgentRepositoryTests
private readonly AgentRepository _sut;
private readonly Fixture _fixture = new();
private readonly Mock<IEventBus> _eventBusMock = new();
private readonly Mock<IJsonPersister> _persisterMock = new();

private readonly List<Agent> _agents = new();

public AgentRepositoryTests()
{
_agents = _fixture.CreateMany<Agent>().ToList();

_persisterMock.Setup(x => x.LoadCollection<Agent>(It.IsAny<string>()))
.Returns(_agents.ToArray());

_sut = new AgentRepository(_eventBusMock.Object, _persisterMock.Object,
Mock.Of<ILogger<AgentRepository>>());

_sut.GetAll(); // To trigger the initializer
}

[Fact]
public void FindById__Returns_appropriate_agent()
{
// Arrange
var agentToFind = _agents[1];

// Act
var result = _sut.FindById(agentToFind.Id);

// Verify
Assert.Equal(agentToFind, result);
}

[Fact]
public void Delete__Removes_appripriate_agent()
{
// Arrange
var agentToDelete = _agents[1];

// Act
_sut.Delete(agentToDelete.Id);

// Verify
Assert.Null(_sut.FindById(agentToDelete.Id));
}

[Fact]
public void Delete__When_no_agent_found__Breaks_operation()
{
// Arrange
var agentCount = _sut.GetAll().Count();

// Act
_sut.Delete(Guid.NewGuid());

// Verify
Assert.Equal(agentCount, _sut.GetAll().Count());
}

[Fact]
public void Store__Replaces_all_existing_agents_and_updates_cache_and_fires_event()
{
private readonly AgentRepository _sut;
private readonly Fixture _fixture = new();
private readonly Mock<IEventBus> _eventBusMock = new();
private readonly Mock<IJsonPersister> _persisterMock = new();

private readonly List<Agent> _agents = new();

public AgentRepositoryTests()
{
_agents = _fixture.CreateMany<Agent>().ToList();

_persisterMock.Setup(x => x.LoadCollection<Agent>(It.IsAny<string>()))
.Returns(_agents.ToArray());

_sut = new AgentRepository(_eventBusMock.Object, _persisterMock.Object,
Mock.Of<ILogger<AgentRepository>>());

_sut.GetAll(); // To trigger the initializer
}

[Fact]
public void FindById__Returns_appropriate_agent()
{
// Arrange
var agentToFind = _agents[1];

// Act
var result = _sut.FindById(agentToFind.Id);

// Verify
Assert.Equal(agentToFind, result);
}

[Fact]
public void Delete__Removes_appripriate_agent()
{
// Arrange
var agentToDelete = _agents[1];

// Act
_sut.Delete(agentToDelete.Id);

// Verify
Assert.Null(_sut.FindById(agentToDelete.Id));
}

[Fact]
public void Delete__When_no_agent_found__Breaks_operation()
{
// Arrange
var agentCount = _sut.GetAll().Count();

// Act
_sut.Delete(Guid.NewGuid());

// Verify
Assert.Equal(agentCount, _sut.GetAll().Count());
}

[Fact]
public void Store__Replaces_all_existing_agents_and_updates_cache_and_fires_event()
{
// Arrange
var newAgents = _fixture.CreateMany<Agent>().ToArray();
var previousAgents = _sut.GetAll().ToArray();

// Act
_sut.Overwrite(newAgents);

// Verify
Assert.False(_sut.GetAll().Except(newAgents).Any());
_persisterMock.Verify(x => x.Store(It.IsAny<string>(),
It.Is((List<Agent> p) => p.SequenceEqual(newAgents))));
_eventBusMock.Verify(x => x.Publish(It.Is<EntitiesAddedEvent>(e => e.Entities.Count == newAgents.Length)), Times.Once);
_eventBusMock.Verify(x => x.Publish(It.Is<EntitiesDeletedEvent>(e => e.Entities.Count == previousAgents.Length)), Times.Once);
}
// Arrange
var newAgents = _fixture.CreateMany<Agent>().ToArray();
var previousAgents = _sut.GetAll().ToArray();

// Act
_sut.Overwrite(newAgents);

// Verify
Assert.False(_sut.GetAll().Except(newAgents).Any());
_persisterMock.Verify(x => x.Store(It.IsAny<string>(),
It.Is((List<Agent> p) => p.SequenceEqual(newAgents))));
_eventBusMock.Verify(x => x.Publish(It.Is<EntitiesAddedEvent>(e => e.Entities.Count == newAgents.Length)), Times.Once);
_eventBusMock.Verify(x => x.Publish(It.Is<EntitiesDeletedEvent>(e => e.Entities.Count == previousAgents.Length)), Times.Once);
}
}
Loading

0 comments on commit 90376cd

Please sign in to comment.