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 void Publish() | |
{ | |
// Code | |
DomainEvents.Publish(new PostPublishedEvent(postId, authorId)); | |
} |
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 void Publish(AuthorService authorService, TwitterService twitterService) | |
{ | |
// Code | |
} |
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
class Post | |
{ | |
public void Publish(AuthorService authorService) | |
{ | |
// Code | |
} | |
} |
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
// Bad example | |
blogPost.Publish("Example", "2016-10-26", "Shaun Finglas"); | |
// Better example | |
blogPost.Publish(title: "Example", date: "2016-10-26", author: "Shaun Finglas"); |
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
// Bad example, uses dependency directly | |
public void Publish() | |
{ | |
this.twitterFeed.SendTweet(...); | |
} | |
// Better example | |
public void Publish() | |
{ | |
this.PostPublished(); |
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
// Bad use of constant if this was separated. | |
File.Open(FilePath); | |
// Local constant. More clarity. | |
const string FilePath = "..."; | |
File.Open(FilePath); | |
// Inline, named argument for cases where you want | |
// readability but also the ability to change at runtime | |
// or on deployment. |
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
class Constants | |
{ | |
public const int DaysInWeek = 7; | |
public const string DefaultDrive = "D"; | |
public const string WelcomeText = "Hello"; | |
... | |
} |
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
[TestFixture] | |
public class Given_A_Blog_Post_With_No_Comments | |
{ | |
[SetUp] | |
public void When_Adding_A_New_Comment() | |
{ | |
} | |
[Test] | |
public void Then_A_New_Comment_Notification_Is_Issued() |
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
[TestFixture] | |
public class BlogPostRetrievalTests | |
{ | |
[Test] | |
public void Retrieving_No_Posts() | |
{ | |
} | |
[Test] | |
public void Retrieving_A_Single_Post() |
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 BlogPostNotFoundException : Exception | |
{ | |
public BlogPostNotFoundException(string message) | |
: base(message) | |
{ | |
} | |
// Note some suggested overloads have been omitted. | |
} |
NewerOlder