Skip to content

Commit

Permalink
Upgraded to newest versions of packages. Breaking changes after upgra…
Browse files Browse the repository at this point in the history
…de to MediatR 4. Now only Asynchronous handlers are available. Synchronous were removed, and asynchronous were renamed to "regular" eg. IAsyncCommandHandler to AsyncCommandHandler (#9)
  • Loading branch information
oskardudycz committed Dec 29, 2017
1 parent d9f49f3 commit fcdddce
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 336 deletions.
4 changes: 2 additions & 2 deletions CQRS.Tests/CQRS.Tests.csproj
Expand Up @@ -17,9 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="2.4.0" />
<PackageReference Include="Marten" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="MediatR" Version="4.0.1" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
Expand Down
35 changes: 20 additions & 15 deletions CQRS.Tests/Commands/Commands.cs
@@ -1,24 +1,27 @@
using CQRS.Tests.TestsInfrasructure;
using MediatR;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CQRS.Tests.TestsInfrasructure;
using MediatR;
using SharpTestsEx;
using Xunit;

namespace CQRS.Tests.Commands
{
public class Commands
{
interface ICommand : IRequest { }
private interface ICommand : IRequest
{ }

interface ICommandHandler<in T> : IRequestHandler<T> where T: ICommand { }
private interface ICommandHandler<in T> : IRequestHandler<T> where T : ICommand
{ }

interface ICommandBus
private interface ICommandBus
{
Task Send(ICommand command);
}

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

Expand All @@ -33,7 +36,7 @@ public Task Send(ICommand command)
}
}

class AddTaskCommand : ICommand
private class AddTaskCommand : ICommand
{
public string Name { get; }

Expand All @@ -43,12 +46,12 @@ internal AddTaskCommand(string name)
}
}

interface ITaskApplicationService
private interface ITaskApplicationService
{
Task AddTask(AddTaskCommand command);
}

class TaskApplicationService : ITaskApplicationService
private class TaskApplicationService : ITaskApplicationService
{
private readonly ICommandBus _commandBus;

Expand All @@ -63,12 +66,12 @@ public Task AddTask(AddTaskCommand command)
}
}

interface IAppWrtiteModel
private interface IAppWrtiteModel
{
IList<string> Tasks { get; }
}

class AppWriteModel : IAppWrtiteModel
private class AppWriteModel : IAppWrtiteModel
{
public IList<string> Tasks { get; }

Expand All @@ -78,17 +81,19 @@ public AppWriteModel(params string[] tasks)
}
}

class AddTaskCommandHandler : ICommandHandler<AddTaskCommand>
private class AddTaskCommandHandler : ICommandHandler<AddTaskCommand>
{
private readonly IAppWrtiteModel _writeModel;

internal AddTaskCommandHandler(IAppWrtiteModel writeModel)
{
_writeModel = writeModel;
}
public void Handle(AddTaskCommand message)

public Task Handle(AddTaskCommand message, CancellationToken cancellationToken = default(CancellationToken))
{
_writeModel.Tasks.Add(message.Name);
return Task.CompletedTask;
}
}

Expand Down Expand Up @@ -116,4 +121,4 @@ public void GivenCommandWithData_WhenCommandIsSendToApplicationService_ThenWrite
writeModel.Tasks.Should().Have.SameValuesAs(addedTaskName);
}
}
}
}
34 changes: 18 additions & 16 deletions CQRS.Tests/Queries/Queries.cs
@@ -1,27 +1,29 @@
using CQRS.Tests.TestsInfrasructure;
using MediatR;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CQRS.Tests.TestsInfrasructure;
using MediatR;
using SharpTestsEx;
using Xunit;
using System.Linq;

namespace CQRS.Tests.Queries
{
public class Queries
{
interface IQuery<out TResponse> : IRequest<TResponse> { }
private interface IQuery<out TResponse> : IRequest<TResponse>
{ }

interface IQueryHandler<in TQuery, TResponse> : IAsyncRequestHandler<TQuery, TResponse>
private interface IQueryHandler<in TQuery, TResponse> : IRequestHandler<TQuery, TResponse>
where TQuery : IQuery<TResponse>
{ }

interface IQueryBus
private interface IQueryBus
{
Task<TResponse> Send<TResponse>(IQuery<TResponse> command);
}

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

Expand All @@ -36,7 +38,7 @@ public Task<TResponse> Send<TResponse>(IQuery<TResponse> command)
}
}

class GetTaskNamesQuery : IQuery<List<string>>
private class GetTaskNamesQuery : IQuery<List<string>>
{
public string Filter { get; }

Expand All @@ -46,12 +48,12 @@ public GetTaskNamesQuery(string filter)
}
}

interface ITaskApplicationService
private interface ITaskApplicationService
{
Task<List<string>> GetTaskNames(GetTaskNamesQuery query);
}

class TaskApplicationService : ITaskApplicationService
private class TaskApplicationService : ITaskApplicationService
{
private readonly IQueryBus _queryBus;

Expand All @@ -66,12 +68,12 @@ public Task<List<string>> GetTaskNames(GetTaskNamesQuery query)
}
}

interface IAppReadModel
private interface IAppReadModel
{
IQueryable<string> Tasks { get; }
}

class AppReadModel : IAppReadModel
private class AppReadModel : IAppReadModel
{
private readonly IList<string> _tasks;
public IQueryable<string> Tasks => _tasks.AsQueryable();
Expand All @@ -82,7 +84,7 @@ public AppReadModel(params string[] tasks)
}
}

class AddTaskCommandHandler : IQueryHandler<GetTaskNamesQuery, List<string>>
private class AddTaskCommandHandler : IQueryHandler<GetTaskNamesQuery, List<string>>
{
private readonly IAppReadModel _readModel;

Expand All @@ -91,7 +93,7 @@ internal AddTaskCommandHandler(IAppReadModel readModel)
_readModel = readModel;
}

public Task<List<string>> Handle(GetTaskNamesQuery query)
public Task<List<string>> Handle(GetTaskNamesQuery query, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.Run(() => _readModel.Tasks
.Where(taskName => taskName.ToLower().Contains(query.Filter.ToLower()))
Expand Down Expand Up @@ -121,4 +123,4 @@ public async void GivenCommandWithData_WhenCommandIsSendToApplicationService_The
result.Should().Have.SameValuesAs("Cleaning main room", "cleaning kitchen");
}
}
}
}
21 changes: 11 additions & 10 deletions CQRS.Tests/TestsInfrasructure/ServiceLocator.cs
@@ -1,36 +1,37 @@
using MediatR;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using MediatR;

namespace CQRS.Tests.TestsInfrasructure
{
class ServiceLocator
internal class ServiceLocator
{
private readonly Dictionary<Type, List<object>> Services = new Dictionary<Type, List<object>>();

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

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

public void RegisterCommandHandler<TCommand, TCommandHandler>(TCommandHandler commandHandler)
public void RegisterCommandHandler<TCommand, TCommandHandler>(TCommandHandler commandHandler)
where TCommand : IRequest
where TCommandHandler : IRequestHandler<TCommand>
{
Register(typeof(IRequestHandler<TCommand>), commandHandler, commandHandler);
//Registration needed internally by MediatR
Register(typeof(IPipelineBehavior<TCommand, Unit>), new object[] { });
Register(typeof(IAsyncRequestHandler<TCommand>), new IAsyncRequestHandler<TCommand>[] { });
}

public void RegisterQueryHandler<TQuery, TResponse>(IAsyncRequestHandler<TQuery, TResponse> queryHandler)
public void RegisterQueryHandler<TQuery, TResponse>(IRequestHandler<TQuery, TResponse> queryHandler)
where TQuery : IRequest<TResponse>
{
Register(typeof(IAsyncRequestHandler<TQuery, TResponse>), queryHandler);
Register(typeof(IRequestHandler<TQuery, TResponse>), queryHandler);
//Registration needed internally by MediatR
Register(typeof(IPipelineBehavior<TQuery, TResponse>), new object[] { });
Register(typeof(IRequestHandler<TQuery, TResponse>), new IRequestHandler<TQuery, TResponse>[] { });
}

public IMediator GetMediator()
Expand All @@ -40,4 +41,4 @@ public IMediator GetMediator()
type => Get(type));
}
}
}
}
2 changes: 1 addition & 1 deletion Domain.Tests/Domain.Tests.csproj
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="2.4.0" />
<PackageReference Include="Marten" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
Expand Down
9 changes: 0 additions & 9 deletions Domain/Commands/IAsyncCommandHandler.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Domain/Domain.csproj
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="2.4.0" />
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="Marten" Version="2.5.0" />
<PackageReference Include="MediatR" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 0 additions & 9 deletions Domain/Events/IAsyncEventHandler.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Domain/Queries/IAsyncQueryHandler.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Domain/Queries/IQueryHandler.cs
Expand Up @@ -2,8 +2,8 @@

namespace Domain.Queries
{
public interface IQueryHandler<in TQuery, out TResponse> : IRequestHandler<TQuery, TResponse>
public interface IQueryHandler<in TQuery, TResponse> : IRequestHandler<TQuery, TResponse>
where TQuery : IQuery<TResponse>
{
}
}
}
Expand Up @@ -17,9 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="2.4.0" />
<PackageReference Include="Marten" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="MediatR" Version="4.0.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
Expand Down
@@ -1,13 +1,13 @@
using System;
using System.Linq;
using Marten.Integration.Tests.TestsInfrasructure;
using Xunit;
using Marten.Events.Projections;
using Marten.Schema;
using System.Reflection;
using Baseline;
using Marten.Events.Projections;
using Marten.Integration.Tests.TestsInfrasructure;
using Marten.Schema;
using Marten.Storage;
using Marten.Util;
using Xunit;

namespace Marten.Integration.Tests.EventStore.Projections
{
Expand Down
2 changes: 1 addition & 1 deletion Marten.Integration.Tests/Marten.Integration.Tests.csproj
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="2.4.0" />
<PackageReference Include="Marten" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion MediatR.Tests/MediatR.Tests.csproj
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="MediatR" Version="4.0.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
Expand Down

0 comments on commit fcdddce

Please sign in to comment.