Skip to content

Commit

Permalink
Next set of Records/nullable reference types alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed May 8, 2021
1 parent 2a021ae commit 1464e1c
Show file tree
Hide file tree
Showing 284 changed files with 1,231 additions and 1,460 deletions.
4 changes: 2 additions & 2 deletions CQRS.Tests/CQRS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>CQRS.Tests</AssemblyName>
<PackageId>CQRS.Tests</PackageId>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions CQRS.Tests/Commands/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public interface ICommandBus

public class CommandBus: ICommandBus
{
private readonly IMediator _mediator;
private readonly IMediator mediator;

public CommandBus(IMediator mediator)
{
_mediator = mediator;
this.mediator = mediator;
}

public Task Send(ICommand command)
{
return _mediator.Send(command);
return mediator.Send(command);
}
}

Expand All @@ -53,16 +53,16 @@ public interface IIssueApplicationService

public class IssueApplicationService: IIssueApplicationService
{
private readonly ICommandBus _commandBus;
private readonly ICommandBus commandBus;

public IssueApplicationService(ICommandBus commandBus)
{
_commandBus = commandBus;
this.commandBus = commandBus;
}

public Task CreateIssue(CreateIssueCommand command)
{
return _commandBus.Send(command);
return commandBus.Send(command);
}
}

Expand All @@ -83,16 +83,16 @@ public AppWriteModel(params string[] issues)

public class CreateIssueCommandHandler: ICommandHandler<CreateIssueCommand>
{
private readonly IAppWrtiteModel _writeModel;
private readonly IAppWrtiteModel writeModel;

public CreateIssueCommandHandler(IAppWrtiteModel writeModel)
{
_writeModel = writeModel;
this.writeModel = writeModel;
}

public Task<Unit> Handle(CreateIssueCommand message, CancellationToken cancellationToken = default)
{
_writeModel.Issues.Add(message.Name);
writeModel.Issues.Add(message.Name);
return Unit.Task;
}
}
Expand Down
20 changes: 10 additions & 10 deletions CQRS.Tests/Queries/Queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public interface IQueryBus

public class QueryBus: IQueryBus
{
private readonly IMediator _mediator;
private readonly IMediator mediator;

public QueryBus(IMediator mediator)
{
_mediator = mediator;
this.mediator = mediator;
}

public Task<TResponse> Send<TResponse>(IQuery<TResponse> command)
{
return _mediator.Send(command);
return mediator.Send(command);
}
}

Expand All @@ -55,16 +55,16 @@ public interface IIssueApplicationService

public class IssueApplicationService: IIssueApplicationService
{
private readonly IQueryBus _queryBus;
private readonly IQueryBus queryBus;

public IssueApplicationService(IQueryBus queryBus)
{
_queryBus = queryBus;
this.queryBus = queryBus;
}

public Task<List<string>> GetIssuesNames(GetIssuesNamesQuery query)
{
return _queryBus.Send(query);
return queryBus.Send(query);
}
}

Expand All @@ -80,22 +80,22 @@ public class AppReadModel: IAppReadModel

public AppReadModel(params string[] issues)
{
this.issues = issues?.ToList();
this.issues = issues.ToList();
}
}

public class CreateIssueCommandHandler: IQueryHandler<GetIssuesNamesQuery, List<string>>
{
private readonly IAppReadModel _readModel;
private readonly IAppReadModel readModel;

public CreateIssueCommandHandler(IAppReadModel readModel)
{
_readModel = readModel;
this.readModel = readModel;
}

public Task<List<string>> Handle(GetIssuesNamesQuery query, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.Run(() => _readModel.Issues
return Task.Run(() => readModel.Issues
.Where(taskName => taskName.ToLower().Contains(query.Filter.ToLower()))
.ToList(), cancellationToken);
}
Expand Down
8 changes: 4 additions & 4 deletions CQRS.Tests/TestsInfrasructure/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace CQRS.Tests.TestsInfrasructure
{
public class ServiceLocator
{
private readonly Dictionary<Type, List<object>> Services = new Dictionary<Type, List<object>>();
private readonly Dictionary<Type, List<object>> services = new();

public void Register(Type type, params object[] implementations)
=> Services.Add(type, implementations.ToList());
=> services.Add(type, implementations.ToList());

public List<object> Get(Type type)
{
return Services[type];
return services[type];
}

public void RegisterCommandHandler<TCommand, TCommandHandler>(TCommandHandler commandHandler)
Expand All @@ -36,7 +36,7 @@ public void RegisterQueryHandler<TQuery, TResponse>(IRequestHandler<TQuery, TRes

public IMediator GetMediator()
{
return new Mediator(type => Get(type).FirstOrDefault());
return new Mediator(type => Get(type).Single());
}
}
}
1 change: 0 additions & 1 deletion Core.Marten/Aggregates/AggregateExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Core.Aggregates;
Expand Down
6 changes: 3 additions & 3 deletions Core.Marten/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Config
{
private const string DefaultSchema = "public";

public string ConnectionString { get; set; }
public string ConnectionString { get; set; } = default!;

public string WriteModelSchema { get; set; } = DefaultSchema;
public string ReadModelSchema { get; set; } = DefaultSchema;
Expand All @@ -26,7 +26,7 @@ public static class MartenConfigExtensions
private const string DefaultConfigKey = "EventStore";

public static IServiceCollection AddMarten(this IServiceCollection services, IConfiguration config,
Action<StoreOptions> configureOptions = null)
Action<StoreOptions>? configureOptions = null)
{
var martenConfig = config.GetSection(DefaultConfigKey).Get<Config>();

Expand All @@ -49,7 +49,7 @@ public static IServiceCollection AddMarten(this IServiceCollection services, ICo
}

private static void SetStoreOptions(StoreOptions options, Config config,
Action<StoreOptions> configureOptions = null)
Action<StoreOptions>? configureOptions = null)
{
options.Connection(config.ConnectionString);
options.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
Expand Down
4 changes: 3 additions & 1 deletion Core.Marten/Core.Marten.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Core.Marten/Repository/MartenRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Core.Aggregates;
Expand All @@ -23,7 +22,7 @@ IEventBus eventBus
this.eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
}

public Task<T> Find(Guid id, CancellationToken cancellationToken)
public Task<T?> Find(Guid id, CancellationToken cancellationToken)
{
return documentSession.Events.AggregateStreamAsync<T>(id, token:cancellationToken);
}
Expand Down
6 changes: 3 additions & 3 deletions Core.Streaming.Kafka/Consumers/KafkaConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ private async Task ConsumeNextEvent(IConsumer<string, string> consumer, Cancella
var message = consumer.Consume(cancellationToken);

// get event type from name storred in message.Key
var eventType = TypeProvider.GetTypeFromAnyReferencingAssembly(message.Message.Key);
var eventType = TypeProvider.GetTypeFromAnyReferencingAssembly(message.Message.Key)!;

// deserialize event
var @event = JsonConvert.DeserializeObject(message.Message.Value, eventType);
var @event = JsonConvert.DeserializeObject(message.Message.Value, eventType)!;

using (var scope = serviceProvider.CreateScope())
{
var eventBus =
scope.ServiceProvider.GetRequiredService<IEventBus>();

// publish event to internal event bus
await eventBus.Publish(@event as IEvent);
await eventBus.Publish((IEvent)@event);
}
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions Core.Streaming.Kafka/Consumers/KafkaConsumerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Core.Streaming.Kafka.Consumers
{
public class KafkaConsumerConfig
{
public ConsumerConfig ConsumerConfig { get; set; }
public string[] Topics { get; set; }
public ConsumerConfig? ConsumerConfig { get; set; }
public string[]? Topics { get; set; }
}

public static class KafkaConsumerConfigExtensions
Expand Down
2 changes: 2 additions & 0 deletions Core.Streaming.Kafka/Core.Streaming.Kafka.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Core.Streaming.Kafka/Producers/KafkaProducerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Core.Streaming.Kafka.Producers
{
public class KafkaProducerConfig
{
public ProducerConfig ProducerConfig { get; set; }
public string Topic { get; set; }
public ProducerConfig? ProducerConfig { get; set; }
public string? Topic { get; set; }
}

public static class KafkaProducerConfigExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Core.Streaming.Consumers
//See more: https://www.stevejgordon.co.uk/asp-net-core-2-ihostedservice
public class ExternalEventConsumerBackgroundWorker: IHostedService
{
private Task executingTask;
private CancellationTokenSource cts;
private Task? executingTask;
private CancellationTokenSource? cts;
private readonly IExternalEventConsumer externalEventConsumer;
private readonly ILogger<ExternalEventConsumerBackgroundWorker> logger;

Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
}

// Signal cancellation to the executing method
cts.Cancel();
cts?.Cancel();

// Wait until the issue completes or the stop token triggers
await Task.WhenAny(executingTask, Task.Delay(-1, cancellationToken));
Expand Down
2 changes: 2 additions & 0 deletions Core.Streaming/Core.Streaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Core.Testing/AggregateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Core.Testing
{
public static class AggregateExtensions
{
public static T PublishedEvent<T>(this IAggregate aggregate) where T : class, IEvent
public static T? PublishedEvent<T>(this IAggregate aggregate) where T : class, IEvent
{
return aggregate.DequeueUncommittedEvents().LastOrDefault() as T;
}
Expand Down
1 change: 1 addition & 0 deletions Core.Testing/Core.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Core.Testing/FakeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public FakeRepository(params T[] aggregates)
Aggregates = aggregates.ToDictionary(ks=> ks.Id, vs => vs);
}

public Task<T> Find(Guid id, CancellationToken cancellationToken)
public Task<T?> Find(Guid id, CancellationToken cancellationToken)
{
return Task.FromResult(Aggregates.GetValueOrDefault(id));
}
Expand Down
2 changes: 1 addition & 1 deletion Core.Testing/ResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Shipments.Api.Tests.Core
{
public static class ResponseExtensions
{
public static async Task<T> GetResultFromJSON<T>(this HttpResponseMessage response)
public static async Task<T> GetResultFromJson<T>(this HttpResponseMessage response)
{
var result = await response.Content.ReadAsStringAsync();

Expand Down
23 changes: 9 additions & 14 deletions Core.Testing/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@ namespace Core.Testing
public class TestContext<TStartup>: IDisposable
where TStartup : class
{
public HttpClient Client { get; private set; }
public HttpClient Client { get; }

private TestServer server;
private readonly TestServer server;

private readonly EventsLog eventsLog = new EventsLog();
private readonly DummyExternalEventProducer externalEventProducer = new DummyExternalEventProducer();
private readonly DummyExternalCommandBus externalCommandBus = new DummyExternalCommandBus();
private readonly EventsLog eventsLog = new();
private readonly DummyExternalEventProducer externalEventProducer = new();
private readonly DummyExternalCommandBus externalCommandBus = new();

private readonly Func<string, Dictionary<string, string>> getConfiguration = fixtureName => new Dictionary<string, string>();
private readonly Func<string, Dictionary<string, string>> getConfiguration = _ => new Dictionary<string, string>();

public TestContext(Func<string, Dictionary<string, string>> getConfiguration = null)
public TestContext(Func<string, Dictionary<string, string>>? getConfiguration = null)
{
if (getConfiguration != null)
{
this.getConfiguration = getConfiguration;
}
SetUpClient();
}

private void SetUpClient()
{
var fixtureName = new StackTrace().GetFrame(3).GetMethod().DeclaringType.Name;
var fixtureName = new StackTrace().GetFrame(3)!.GetMethod()!.DeclaringType!.Name;

var configuration = getConfiguration(fixtureName);
var configuration = this.getConfiguration(fixtureName);
var projectDir = Directory.GetCurrentDirectory();

server = new TestServer(new WebHostBuilder()
Expand Down
6 changes: 3 additions & 3 deletions Core.Tests/AggregateWithWhenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public enum InvoiceStatus
public class Invoice: Aggregate<string>
{
public double Amount { get; private set; }
public string Number { get; private set; }
public string Number { get; private set; } = default!;

public InvoiceStatus Status { get; private set; }

public Person IssuedTo { get; private set; }
public Person IssuedTo { get; private set; } = default!;
public DateTime InitiatedAt { get; private set; }

public string IssuedBy { get; private set; }
public string? IssuedBy { get; private set; }
public DateTime IssuedAt { get; private set; }

public InvoiceSendMethod SentVia { get; private set; }
Expand Down
Loading

0 comments on commit 1464e1c

Please sign in to comment.