public void it_can_be_identified_by_an_id_as_a_guid(Guid accountId) { var sut = new Account(new AccountId(accountId), CustomerId.Create(), Money.PoundSterling(100)); ((Guid)sut.Id).Should().Be(accountId); sut.Id.Value.Should().Be(accountId); }
public IActionResult Get(int customerId) { var custId = CustomerId.Create(customerId); var cust = _dao.GetById(custId); var dto = DtoConverter.CustomerToDto(cust); return(Ok(dto)); }
/// <summary> /// Convert a DbCustomer into a domain Customer /// </summary> public static Customer FromDbCustomer(DbCustomer sqlCustomer) { if (sqlCustomer == null) { return(null); } var id = CustomerId.Create(sqlCustomer.Id); var name = PersonalName.Create(sqlCustomer.FirstName, sqlCustomer.LastName); var email = EmailAddress.Create(sqlCustomer.Email); var cust = Customer.Create(id, name, email); return(cust); }
/// <summary> /// Create a domain customer from a DTO or null if not valid. /// </summary> public static Customer DtoToCustomer(CustomerDto dto) { if (dto == null) { // dto can be null if deserialization fails return(null); } var id = CustomerId.Create(dto.Id); var name = PersonalName.Create(dto.FirstName, dto.LastName); var email = EmailAddress.Create(dto.Email); var cust = Customer.Create(id, name, email); return(cust); }
public IActionResult GetWithErrorHandling(int customerId) { Log("GetWithErrorHandling {0}", customerId); // first create the customer id // it might be null, so handle that case var custId = CustomerId.Create(customerId); if (custId == null) { Log("CustomerId is not valid"); return(BadRequest("CustomerId is not valid")); } try { // look up the customer in the database // it might be null, so handle that case var cust = _dao.GetById(custId); if (cust == null) { Log("Customer not found"); return(NotFound()); } // this should always succeed var dto = DtoConverter.CustomerToDto(cust); // return return(Ok(dto)); } catch (Exception ex) { // handle database errors var errMsg = $"Exception: {ex.Message}"; Log("Exception: {0}", ex.Message); return(new ContentResult { Content = errMsg, StatusCode = 500 }); } }
public void it_raises_a_validation_error_when_the_initial_balance_is_negative() { Action openAccount = () => Account.Open(CustomerId.Create(), Money.PoundSterling(-100)); openAccount.Should().Throw <BusinessRuleValidationException>().WithMessage("Account Balance can't be negative"); }
public void it_can_return_the_balance(Guid accountId, decimal balance) { var sut = new Account(new AccountId(accountId), CustomerId.Create(), Money.PoundSterling(balance)); sut.Balance.Should().Be(balance); }