This file contains hidden or 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 hidden or 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 CustomerName Name { get; private set; } | |
public Email Email { get; private set; } | |
public Customer(CustomerName name, Email email) | |
{ | |
if (name == null) | |
throw new ArgumentNullException("name"); | |
if (email == null) |
This file contains hidden or 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
[HttpPost] | |
public HttpResponseMessage CreateCustomer(string name, string billingInfo) | |
{ | |
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo); | |
Result<CustomerName> customerNameResult = CustomerName.Create(name); | |
return Result.Combine(billingInfoResult, customerNameResult) | |
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value)) | |
.OnSuccess(() => new Customer(customerNameResult.Value)) | |
.OnSuccess( |
This file contains hidden or 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 void Create(string name, string email, string billingInfo) | |
{ | |
Result<CustomerName> nameResult = CustomerName.Create(name); | |
Result<Email> emailResult = Email.Create(email); | |
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo); | |
return Result.Combine(nameResult, emailResult, billingInfoResult) | |
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value)); | |
/* Other OnSuccess, OnFailure, OnBoth methods */ | |
} |
This file contains hidden or 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; } | |
This file contains hidden or 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 Order | |
{ | |
private readonly List<OrderLine> _lines; | |
public Order() | |
{ | |
_lines = new List<OrderLine>(); | |
} | |
public decimal Amount |
This file contains hidden or 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
[Fact] | |
public void Amount_shows_order_amount() | |
{ | |
// Arrange | |
var order = new Order(); | |
order.AddLine(10, new Product()); | |
order.AddLine(20, new Product()); | |
// Act | |
decimal amount = order.Amount; |
This file contains hidden or 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
[Fact] | |
public void Parser_parses_xml_in_correct_order() | |
{ | |
// Arrange : input values | |
string xml = "<outer><inner /></outer>"; | |
var parser = new Parser(); | |
// Arrange : record expectations | |
var mocks = new MockRepository(); | |
IHandler handler = mocks.CreateMock<IHandler>(); |
This file contains hidden or 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 UserTests | |
{ | |
[Fact] | |
public void Should_fire_event_after_provisioning() | |
{ | |
// Arrange | |
Organization organization = CreateOrganization(); | |
User user = CreateUser(organization); | |
Subscription subscription = CreateSubscription(Package.Streamer, organization); |
This file contains hidden or 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 UserBuilder | |
{ | |
private readonly string _firstName; | |
private readonly string _lastName; | |
public UserBuilder() | |
: this(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) | |
{ | |
} |
OlderNewer