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
public class Customer | |
{ | |
public string Name { get; private set; } | |
public string Email { get; private set; } | |
public Customer(string name, string email) | |
{ | |
// Validate name | |
if (string.IsNullOrWhiteSpace(name) || name.Length > 50) | |
throw new ArgumentException("Name is invalid"); |
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
public abstract class Entity | |
{ | |
public virtual long Id { get; protected set; } | |
protected virtual object Actual => this; | |
public override bool Equals(object obj) | |
{ | |
var other = obj as Entity; | |
if (other is null) |
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
[MethodUnderTest]_[Scenario]_[ExpectedResult] |
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
public sealed class DatabaseCommandRetryDecorator<TCommand> : DatabaseRetryDecorator, ICommandHandler<TCommand> | |
where TCommand : ICommand | |
{ | |
private readonly ICommandHandler<TCommand> _handler; | |
public DatabaseCommandRetryDecorator(ICommandHandler<TCommand> handler, Config config) | |
: base(config) | |
{ | |
_handler = handler; | |
} |
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
public sealed class Messages | |
{ | |
private readonly IServiceProvider _provider; | |
public Messages(IServiceProvider provider) | |
{ | |
_provider = provider; | |
} | |
public void Dispatch(IDomainEvent domainEvent) |
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
public class EditPersonalInfoCommandHandler : ICommandHandler<EditPersonalInfoCommand> | |
{ | |
public Result Handle(EditPersonalInfoCommand command) | |
{ | |
for (int i = 0; ; i++) | |
{ | |
try | |
{ | |
var unitOfWork = new UnitOfWork(_sessionFactory); | |
Student student = unitOfWork.GetStudentById(command.Id); |
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
public sealed class EnrollCommand : ICommand | |
{ | |
public long StudentId { get; } | |
public string Course { get; } | |
public string Grade { get; } | |
public EnrollCommand(long studentId, string course, string grade) | |
{ | |
if (course == null || grade == null) // Precondition checks | |
throw ArgumentException(); |
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
public IActionResult EditPersonalInfo([FromBody] EditPersonalInfoCommand command) | |
{ | |
var handler = new EditPersonalInfoCommandHandler(_unitOfWork); | |
Result result = handler.Handle(command); | |
return result.IsSuccess ? Ok() : Error(result.Error); | |
} |
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
public class Person : Entity | |
{ | |
public virtual string Name { get; set; } | |
public virtual Document Document { get; set; } | |
} | |
public class Document : Entity | |
{ | |
} |
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
public abstract class Error | |
{ | |
public abstract ErrorType Type { get; } | |
} | |
public class SimpleError : Error | |
{ | |
public override ErrorType Type { get { return ErrorType.Simple; } } | |
public string Message { get; private set; } | |