Code Cleanup | Format Document | Insert Snippet | Surround With |
---|---|---|---|
Ctrl+K, Ctrl+E |
Ctrl+K, Ctrl+D |
Ctrl+K, Ctrl+X |
Ctrl+K, Ctrl+S |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace DddBuildingBlocks.Domain.CapturarLeadsContext | |
{ | |
public class Lead : Entity | |
{ | |
private readonly List<Segment> _segments = new List<Segment>(); |
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 Lead : Entity | |
{ | |
private readonly List<Segment> _segments = new List<Segment>(); | |
public Name Name { get; } | |
public Email Email { get; } | |
public IReadOnlyCollection<Segment> Segments => _segments.ToList(); | |
} |
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 phoneNumber = new PhoneNumber("51", "25615006"); | |
var address = new Address("79074-047", "Rua Júlio de Castilhos", 1234, "Centro"); | |
var name = new Name("Lucas Luís", "Cruz"); | |
var email = new Email("foo@domain.com"); | |
var lead = new Lead(name, email); | |
lead.CompleteInfo(phoneNumber, address, false, new DateTime(2000, 12, 20)); |
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 Lead : Entity | |
{ | |
private readonly List<Segment> _segments; | |
public Lead(Name name, Email email) | |
{ | |
Guard.Against | |
.Null(name, nameof(name)) | |
.Null(email, nameof(email)); |
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
[Trait("Category", nameof(Domain))] | |
public class AddressTest | |
{ | |
[Theory] | |
[InlineData("79074-047")] | |
[InlineData("29725-972")] | |
public void Address_ValidZipCode_Valid(string zipCode) | |
{ | |
Assert.DoesNotThrows(() => new Address(zipCode, "Rua Júlio de Castilhos", 1234, "Centro")); | |
} |
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
[Trait("Category", nameof(Domain))] | |
public class PhoneNumberTest | |
{ | |
[Theory] | |
[InlineData("11")] | |
[InlineData("51")] | |
public void PhoneNumber_ValidDdd_Valid(string ddd) | |
{ | |
Assert.DoesNotThrows(() => new PhoneNumber(ddd, "25615006")); | |
} |
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
[Trait("Category", "Domain")] | |
public class EmailTest | |
{ | |
[Fact] | |
public void ToString_Email_String() | |
{ | |
var expected = "foo@domain.com"; | |
var email = new Email(expected); | |
var actual = email.ToString(); |
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
[Trait("Category", nameof(Domain))] | |
public class NameTest | |
{ | |
[Theory] | |
[InlineData("Lucas Luís", "Cruz")] | |
[InlineData("Erick Oliveira", "")] | |
public void Name_ValidName_Valid(string firstName, string lastName) | |
{ | |
Assert.DoesNotThrows(() => new Name(firstName, lastName)); | |
} |
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 Address | |
{ | |
public Address(string zipCode, string street, int number, string neighborhood, string complement = "") | |
{ | |
Guard.Against | |
.NotMatch(zipCode, @"^\d{5}-\d{3}$", nameof(zipCode)) | |
.NullOrWhiteSpace(street, nameof(street)) | |
.ZeroOrLess(number, nameof(number)) | |
.NullOrWhiteSpace(neighborhood, nameof(neighborhood)); |
NewerOlder