Skip to content

Commit

Permalink
Enable nullable reference types, closes #239
Browse files Browse the repository at this point in the history
PR #242
  • Loading branch information
cd21h committed May 31, 2021
1 parent a039299 commit 48fbcef
Show file tree
Hide file tree
Showing 89 changed files with 479 additions and 421 deletions.
10 changes: 8 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
<Product>Sharp Architecture</Product>
<Authors>Sharp Architecture Dev Team</Authors>

<TargetFrameworks>netstandard2.0;netstandard2.1;net5</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>

<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<PropertyGroup Label="Custom targets">
<!-- target frameworks for unit-tests and applications -->
<AppTargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5</AppTargetFrameworks>
<AppTargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</AppTargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand All @@ -27,6 +28,11 @@
<Optimize>True</Optimize>
</PropertyGroup>

<!-- nullable checks -->
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net5.0' ">
<DefineConstants>$(DefineConstants);NULLABLE_REFERENCE_TYPES</DefineConstants>
</PropertyGroup>

<PropertyGroup Label="Package" Condition="'$(MSBuildProjectName.Contains(Tests))' == false">
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression>
<IsPackable>True</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Docker/start-mssql.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker.exe run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 2433:1433 -d -v./mssql-data:/var/opt/mssql/data mcr.microsoft.com/mssql/server:2017-latest-ubuntu
docker.exe run --name sharparch-sql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 2433:1433 -d -v./mssql-data:/var/opt/mssql/data mcr.microsoft.com/mssql/server:2017-latest-ubuntu
1 change: 1 addition & 0 deletions GitReleaseManager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ issue-labels-exclude:
- question
- ready
- wontfix
- pull-request

issue-labels-alias:
- name: breaking-change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AnnouncementSummary

[Required]
[JsonProperty("title")]
public string Title { get; set; }
public string Title { get; set; } = null!;
}


Expand All @@ -30,6 +30,6 @@ public class AnnouncementModel : AnnouncementSummary
{
[JsonProperty("content")]
[Required]
public string Content { get; set; }
public string Content { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class NewAnnouncement

[Required]
[JsonProperty("title")]
public string Title { get; set; }
public string Title { get; set; } = null!;

[JsonProperty("content")]
[Required]
public string Content { get; set; }
public string Content { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Samples/TardisBank/Src/Suteki.TardisBank.Domain/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public virtual decimal Balance

public virtual IList<PaymentSchedule> PaymentSchedules { get; protected set; }

public virtual void AddTransaction(string description, decimal amount)
public virtual void AddTransaction(string? description, decimal amount)
{
this.Transactions.Add(new Transaction(description, amount, this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class Announcement: Entity<int>
public virtual DateTime Date { get; set; }

[MaxLength(120)]
public virtual string Title { get; set; }
public virtual string Title { get; set; } = null!;

[MaxLength(2000)]
public virtual string Content { get; set; }
public virtual string? Content { get; set; }

public virtual DateTime LastModifiedUtc { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions Samples/TardisBank/Src/Suteki.TardisBank.Domain/Child.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected Child()
}

public virtual int ParentId { get; set; }
public virtual Account Account { get; set; }
public virtual Account Account { get; set; } = null!;

public virtual void ReceivePayment(decimal amount, string description)
{
Expand Down Expand Up @@ -75,4 +75,4 @@ public override string[] GetRoles()
return new[] { UserRoles.Child };
}
}
}
}
4 changes: 2 additions & 2 deletions Samples/TardisBank/Src/Suteki.TardisBank.Domain/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public virtual void Read()
}

public virtual DateTime Date { get; protected set; }
public virtual string Text { get; protected set; }
public virtual string? Text { get; protected set; }

public virtual User User { get; set; }
public virtual User User { get; set; } = null!;

public virtual bool HasBeenRead { get; protected set; }
}
Expand Down
8 changes: 5 additions & 3 deletions Samples/TardisBank/Src/Suteki.TardisBank.Domain/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ protected Parent()
{
}

public virtual IList<Child> Children { get; protected set; }
public virtual string ActivationKey { get; protected set; }
public virtual IList<Child> Children { get; protected set; } = null!;

public virtual string ActivationKey { get; protected set; } = null!;

// should be called when parent is first created.
public virtual Parent Initialise(IMediator mediator)
{
Expand Down Expand Up @@ -69,7 +71,7 @@ public virtual bool HasChild(int childId)

public virtual void RemoveChild(int childId)
{
Child childToRemove = this.Children.SingleOrDefault(x => x.Id == childId);
Child? childToRemove = this.Children.SingleOrDefault(x => x.Id == childId);
if (childToRemove != null)
{
this.Children.Remove(childToRemove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ protected PaymentSchedule()
public virtual DateTime NextRun { get; protected set; }
public virtual Interval Interval { get; protected set; }
public virtual decimal Amount { get; protected set; }
public virtual string Description { get; protected set; }
public virtual string? Description { get; protected set; }

public virtual Account Account { get; protected set; }
public virtual Account Account { get; protected set; } = null!;

public virtual void CalculateNextRunDate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Suteki.TardisBank.Domain

public class Transaction : Entity<int>
{
public Transaction(string description, decimal amount, Account account)
public Transaction(string? description, decimal amount, Account account)
{
this.Description = description;
this.Amount = amount;
Expand All @@ -18,10 +18,10 @@ protected Transaction()
{
}

public virtual string Description { get; protected set; }
public virtual string? Description { get; protected set; }
public virtual decimal Amount { get; protected set; }

public virtual Account Account { get; protected set; }
public virtual Account Account { get; protected set; } = null!;

public virtual DateTime Date { get; protected set; }
}
Expand Down
8 changes: 4 additions & 4 deletions Samples/TardisBank/Src/Suteki.TardisBank.Domain/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected User()
{
}

public virtual string Name { get; protected set; }
public virtual string UserName { get; protected set; }
public virtual string Password { get; protected set; }
public virtual string Name { get; protected set; } = null!;
public virtual string UserName { get; protected set; } = null!;
public virtual string Password { get; protected set; } = null!;
public virtual bool IsActive { get; protected set; }
public virtual IList<Message> Messages { get; protected set; }
public virtual IList<Message> Messages { get; protected set; } = null!;

protected User(string name, string userName, string password)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="FluentNHibernate" Version="3.1.0" />
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
<PackageReference Include="Iesi.Collections" Version="4.0.4" />
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="NHibernate" Version="5.3.5" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
<PackageReference Include="NHibernate" Version="5.3.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Suteki.TardisBank.Tasks

public interface IUserService
{
Task<User> GetCurrentUser(CancellationToken cancellationToken = default);
Task<User?> GetCurrentUser(CancellationToken cancellationToken = default);
Task<User> GetUser(int userId, CancellationToken cancellationToken = default);
Task<User> GetUserByUserName(string userName, CancellationToken cancellationToken = default);
Task<User> GetUserByActivationKey(string activationKey, CancellationToken cancellationToken = default);
Task<User?> GetUserByUserName(string userName, CancellationToken cancellationToken = default);
Task<User?> GetUserByActivationKey(string activationKey, CancellationToken cancellationToken = default);
Task SaveUser(User user, CancellationToken cancellationToken = default);
Task DeleteUser(int userId, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Iesi.Collections" Version="4.0.4" />
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="NHibernate" Version="5.3.5" />
<PackageReference Include="NHibernate" Version="5.3.8" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Samples/TardisBank/Src/Suteki.TardisBank.Tasks/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public UserService(IHttpContextService context, ILinqRepository<Parent, int> par
_userRepository = userRepository;
}

public Task<User> GetCurrentUser(CancellationToken cancellationToken)
public Task<User?> GetCurrentUser(CancellationToken cancellationToken)
{
if (!_context.UserIsAuthenticated) return Task.FromResult<User>(null);
if (!_context.UserIsAuthenticated) return Task.FromResult<User?>(null);

return GetUserByUserName(_context.UserName, cancellationToken);
}
Expand All @@ -37,17 +37,17 @@ public Task<User> GetUser(int userId, CancellationToken cancellationToken)
return _userRepository.FindOneAsync(userId, cancellationToken);
}

public Task<User> GetUserByUserName(string userName, CancellationToken cancellationToken)
public Task<User?> GetUserByUserName(string userName, CancellationToken cancellationToken)
{
if (userName == null)
{
throw new ArgumentNullException(nameof(userName));
}

return _userRepository.FindAll().Where(u => u.UserName == userName).FirstOrDefaultAsync(cancellationToken);
return _userRepository.FindAll().Where(u => u.UserName == userName).FirstOrDefaultAsync(cancellationToken)!;
}

public async Task<User> GetUserByActivationKey(string activationKey, CancellationToken cancellationToken)
public async Task<User?> GetUserByActivationKey(string activationKey, CancellationToken cancellationToken)
{
if (activationKey == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public class AnnouncementControllerTests : IClassFixture<TestServerSetup>, IDisposable
{
readonly TestServerSetup _setup;
Uri _newAnnouncementUri;
Uri? _newAnnouncementUri;

public AnnouncementControllerTests([NotNull] TestServerSetup setup)
public AnnouncementControllerTests(TestServerSetup setup)
{
_setup = setup ?? throw new ArgumentNullException(nameof(setup));
}
Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task CanSaveAnnouncement()
var response = await _setup.Client.PostAsJsonAsync("announcements", newAnnouncement);
response.EnsureSuccessStatusCode();

_newAnnouncementUri = response.Headers.Location;
_newAnnouncementUri = response.Headers.Location!;

var announcementResponse = await _setup.Client.GetAsync(_newAnnouncementUri);
announcementResponse.EnsureSuccessStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Suteki.TardisBank.Tests.Model

public class PaymentSchedulingQueryTests : TransientDatabaseTests<TransientDatabaseSetup>
{
Parent _parent;
Parent _parent = null!;

DateTime _someDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NHibernate" Version="5.3.5" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NHibernate" Version="5.3.8" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.113.7" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -28,8 +28,8 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.5" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.1" />
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.0" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Suteki.TardisBank.WebApi.Controllers
#pragma warning disable 1573
namespace Suteki.TardisBank.WebApi.Controllers
{
using System;
using System.Collections.Generic;
Expand All @@ -24,19 +25,20 @@ public class AnnouncementsController : ControllerBase
{
readonly ILinqRepository<Announcement, int> _announcementRepository;
#if NETCOREAPP3_1 || NET5_0
[NotNull] readonly LinkGenerator _linkGenerator;
readonly LinkGenerator _linkGenerator;
#endif
[NotNull] readonly IMapper _mapper;
readonly IMapper _mapper;

/// <summary>
/// Creates AnnouncementController.
/// </summary>
/// <param name="announcementRepository">Announcements repository.</param>
public AnnouncementsController([NotNull] ILinqRepository<Announcement, int> announcementRepository,
/// <param name="mapper">Mapper</param>
public AnnouncementsController(ILinqRepository<Announcement, int> announcementRepository,
#if NETCOREAPP3_1 || NET5_0
LinkGenerator linkGenerator,
#endif
[NotNull] IMapper mapper)
IMapper mapper)
{
_announcementRepository = announcementRepository ?? throw new ArgumentNullException(nameof(announcementRepository));
#if NETCOREAPP3_1 || NET5_0
Expand Down Expand Up @@ -70,7 +72,8 @@ public async Task<ActionResult<IEnumerable<AnnouncementSummary>>> Get()
public async Task<ActionResult<AnnouncementModel>> Get(int id)
{
var announcement = await _announcementRepository.GetAsync(id).ConfigureAwait(false);
return announcement != null ? _mapper.Map<AnnouncementModel>(announcement) : null;
if (announcement != null) return _mapper.Map<AnnouncementModel>(announcement);
return NotFound(new {id});
}

[HttpPost]
Expand Down
Loading

0 comments on commit 48fbcef

Please sign in to comment.