-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artur Gawlik
authored and
Artur Gawlik
committed
Jul 8, 2017
1 parent
9b9a16a
commit a448ae1
Showing
11 changed files
with
121 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Autofac; | ||
using Passenger.Infrastructure.Commands.Users; | ||
|
||
namespace Passenger.Infrastructure.Commands | ||
{ | ||
public class CommandDispatcher : ICommandDispatcher | ||
{ | ||
private readonly IComponentContext _context; | ||
|
||
public CommandDispatcher(IComponentContext context) | ||
{ | ||
_context = context; | ||
} | ||
public async Task DispatchAsync<T>(T command) where T : ICommand | ||
{ | ||
if(command == null) | ||
throw new ArgumentNullException(nameof(command), $"Command '{typeof(T).Name}' can not be null."); | ||
|
||
var handler = _context.Resolve<ICommandHandler<T>>(); | ||
await handler.HandleAsync(command); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using Passenger.Infrastructure.Commands.Users; | ||
|
||
namespace Passenger.Infrastructure.Commands | ||
{ | ||
public interface ICommandDispatcher | ||
{ | ||
Task DispatchAsync<T>(T command) where T : ICommand; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using Passenger.Infrastructure.Commands.Users; | ||
|
||
namespace Passenger.Infrastructure.Commands | ||
{ | ||
public interface ICommandHandler<T> where T : ICommand | ||
{ | ||
Task HandleAsync(T command); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Passenger.Infrastructure/Handlers/Users/CreateUserHandler.cs
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Passenger.Infrastructure.Commands; | ||
using Passenger.Infrastructure.Commands.Users; | ||
using Passenger.Infrastructure.Services; | ||
|
||
namespace Passenger.Infrastructure.Handlers.Users | ||
{ | ||
public class CreateUserHandler : ICommandHandler<CreateUser> | ||
{ | ||
private readonly IUserService _userService; | ||
public CreateUserHandler(IUserService userService) | ||
{ | ||
_userService = userService; | ||
} | ||
public async Task HandleAsync(CreateUser command) | ||
{ | ||
await _userService.RegisterAsync(command.Email, command.UserName, command.Password); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Reflection; | ||
using Autofac; | ||
using Passenger.Infrastructure.Commands; | ||
|
||
namespace Passenger.Infrastructure.IoC.Modules | ||
{ | ||
public class CommandModule : Autofac.Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
var assembly = typeof(CommandModule) | ||
.GetTypeInfo() | ||
.Assembly; | ||
|
||
builder.RegisterAssemblyTypes(assembly) | ||
.AsClosedTypesOf(typeof(ICommandHandler<>)) | ||
.InstancePerLifetimeScope(); | ||
|
||
builder.RegisterType<CommandDispatcher>() | ||
.As<ICommandDispatcher>() | ||
.InstancePerLifetimeScope(); | ||
} | ||
} | ||
} |
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,13 +1,10 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using FluentAssertions; | ||
using Moq; | ||
using Passenger.Core.Domain; | ||
using Passenger.Core.Repositories; | ||
using Passenger.Infrastructure.Services; | ||
using Xunit; | ||
using System.Collections.Generic; | ||
|
||
namespace Passenger.Tests.Services | ||
{ | ||
|
@@ -25,18 +22,5 @@ public async Task register_async_should_invoke_add_async_on_repository() | |
userRepositoryMock.Verify(x => x.AddAsync(It.IsAny<User>()), Times.Once); | ||
|
||
} | ||
|
||
[Fact] | ||
public async Task trying_to_register_user_that_have_email_witch_is_already_in_use_should_trow_exeption() | ||
{ | ||
var userRepositoryMock = new Mock<IUserRepository>(); | ||
var mapperMock = new Mock<IMapper>(); | ||
|
||
var userService = new UserService(userRepositoryMock.Object, mapperMock.Object); | ||
await userService.RegisterAsync("[email protected]", "test", "password"); | ||
var a = await userService.GetAsync("[email protected]"); | ||
|
||
//await Assert.ThrowsAnyAsync<Exception>(() => userService.RegisterAsync("[email protected]", "test", "password")); | ||
} | ||
} | ||
} |