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
// We also want to encapsulate the way this class is instantiated. | |
private Order() { } | |
public string OrderId { get; private set; } | |
public string CustomerId { get; private set; } | |
public decimal Discount { get; private set; } | |
public bool Paid { get; private set; } | |
public DateTime? PaymentTime { get; private set; } | |
public DateTime CreationTime { get; private set; } | |
public List<OrderItem> Items { get; private set; } |
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 Order | |
{ | |
public string OrderId { get; set; } | |
public string CustomerId { get; set; } | |
public decimal Discount { get; set; } | |
public bool Paid { get; set; } | |
public DateTime? PaymentTime { get; set; } | |
public DateTime CreationTime { get; set; } | |
public List<OrderItem> Items { get; set; } |
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 OrderService | |
{ | |
private readonly IOrderRepository _repository; | |
public void AddItem(string orderId, OrderItem item) | |
{ | |
var order = _repository.GetById(orderId); | |
// Validate | |
if (order.Paid) throw new InvalidOperationException("The order is paid already."); | |
if (order.Items.Count > 5) throw new InvalidOperationException("Cannot add more than 5 items in an order."); |
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 Order | |
{ | |
public string OrderId { get; set; } | |
public string CustomerId { get; set; } | |
public decimal Discount { get; set; } | |
public bool Paid { get; set; } | |
public DateTime? PaymentTime { get; set; } | |
public DateTime CreationTime { get; set; } | |
public List<OrderItem> Items { get; set; } |
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
var builder = new EmployeeTestBuilder(); | |
var employee = builder | |
.WithName("Samuel") | |
.HasAge(35) | |
.HasGrossSalaryOf(1000) | |
.Build(); | |
employee.CalculateNetSalary().Should().Be(850); |
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 EmployeeTestBuilder | |
{ | |
private Employee _employee; | |
public EmployeeTestBuilder() | |
{ | |
_employee = new Employee(); | |
} | |
public EmployeeTestBuilder Default() | |
{ |
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 Employee | |
{ | |
public string Name { get; set; } | |
public DateTime BirthDate { get; set; } | |
public double GrossSalary { get; set; } | |
public double CalculateNetSalary() | |
{ | |
var age = DateTime.Now.Year - BirthDate.Year; |
NewerOlder