11using System ;
22using System . Linq ;
33using LinkDotNet . Blog . TestUtilities ;
4+ using LinkDotNet . Blog . Web ;
45using LinkDotNet . Blog . Web . Features . Bookmarks ;
56using LinkDotNet . Blog . Web . Features . Components ;
67using Microsoft . Extensions . DependencyInjection ;
8+ using Microsoft . Extensions . Options ;
9+ using static Microsoft . IO . RecyclableMemoryStreamManager ;
710
811namespace LinkDotNet . Blog . UnitTests . Web . Features . Components ;
912
@@ -13,6 +16,17 @@ public class ShortBlogPostTests : BunitContext
1316 public void ShouldOpenBlogPost ( )
1417 {
1518 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
19+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
20+
21+ options . Value . Returns ( new ApplicationConfiguration ( )
22+ {
23+ UseMultiAuthorMode = true ,
24+ BlogName = "Test" ,
25+ ConnectionString = "Test" ,
26+ DatabaseName = "Test"
27+ } ) ;
28+
29+ Services . AddScoped ( _ => options ) ;
1630 var blogPost = new BlogPostBuilder ( ) . Build ( ) ;
1731 blogPost . Id = "SomeId" ;
1832 var cut = Render < ShortBlogPost > (
@@ -27,6 +41,17 @@ public void ShouldOpenBlogPost()
2741 public void ShouldNavigateToEscapedTagSiteWhenClickingOnTag ( )
2842 {
2943 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
44+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
45+
46+ options . Value . Returns ( new ApplicationConfiguration ( )
47+ {
48+ UseMultiAuthorMode = true ,
49+ BlogName = "Test" ,
50+ ConnectionString = "Test" ,
51+ DatabaseName = "Test"
52+ } ) ;
53+
54+ Services . AddScoped ( _ => options ) ;
3055 var blogPost = new BlogPostBuilder ( ) . WithTags ( "Tag 1" ) . Build ( ) ;
3156 var cut = Render < ShortBlogPost > (
3257 p => p . Add ( c => c . BlogPost , blogPost ) ) ;
@@ -40,6 +65,17 @@ public void ShouldNavigateToEscapedTagSiteWhenClickingOnTag()
4065 public void WhenNoTagsAreGivenThenTagsAreNotShown ( )
4166 {
4267 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
68+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
69+
70+ options . Value . Returns ( new ApplicationConfiguration ( )
71+ {
72+ UseMultiAuthorMode = true ,
73+ BlogName = "Test" ,
74+ ConnectionString = "Test" ,
75+ DatabaseName = "Test"
76+ } ) ;
77+
78+ Services . AddScoped ( _ => options ) ;
4379 var blogPost = new BlogPostBuilder ( ) . Build ( ) ;
4480
4581 var cut = Render < ShortBlogPost > (
@@ -52,6 +88,17 @@ public void WhenNoTagsAreGivenThenTagsAreNotShown()
5288 public void GivenBlogPostThatIsScheduled_ThenIndicating ( )
5389 {
5490 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
91+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
92+
93+ options . Value . Returns ( new ApplicationConfiguration ( )
94+ {
95+ UseMultiAuthorMode = true ,
96+ BlogName = "Test" ,
97+ ConnectionString = "Test" ,
98+ DatabaseName = "Test"
99+ } ) ;
100+
101+ Services . AddScoped ( _ => options ) ;
55102 var blogPost = new BlogPostBuilder ( ) . IsPublished ( false ) . WithScheduledPublishDate ( new DateTime ( 2099 , 1 , 1 ) )
56103 . Build ( ) ;
57104
@@ -65,6 +112,17 @@ public void GivenBlogPostThatIsScheduled_ThenIndicating()
65112 public void GivenBlogPostThatIsNotPublishedAndNotScheduled_ThenIndicating ( )
66113 {
67114 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
115+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
116+
117+ options . Value . Returns ( new ApplicationConfiguration ( )
118+ {
119+ UseMultiAuthorMode = true ,
120+ BlogName = "Test" ,
121+ ConnectionString = "Test" ,
122+ DatabaseName = "Test"
123+ } ) ;
124+
125+ Services . AddScoped ( _ => options ) ;
68126 var blogPost = new BlogPostBuilder ( ) . IsPublished ( false ) . Build ( ) ;
69127
70128 var cut = Render < ShortBlogPost > (
@@ -77,6 +135,17 @@ public void GivenBlogPostThatIsNotPublishedAndNotScheduled_ThenIndicating()
77135 public void GivenBlogPostThatIsPublished_ThenNoDraft ( )
78136 {
79137 Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
138+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
139+
140+ options . Value . Returns ( new ApplicationConfiguration ( )
141+ {
142+ UseMultiAuthorMode = true ,
143+ BlogName = "Test" ,
144+ ConnectionString = "Test" ,
145+ DatabaseName = "Test"
146+ } ) ;
147+
148+ Services . AddScoped ( _ => options ) ;
80149 var blogPost = new BlogPostBuilder ( ) . IsPublished ( true ) . Build ( ) ;
81150
82151 var cut = Render < ShortBlogPost > (
@@ -85,4 +154,56 @@ public void GivenBlogPostThatIsPublished_ThenNoDraft()
85154 cut . FindAll ( ".draft" ) . ShouldBeEmpty ( ) ;
86155 cut . FindAll ( ".scheduled" ) . ShouldBeEmpty ( ) ;
87156 }
157+
158+ [ Fact ]
159+ public void ShouldShowAuthorNameWhenUseMultiAuthorModeIsTrue ( )
160+ {
161+ Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
162+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
163+
164+ options . Value . Returns ( new ApplicationConfiguration ( )
165+ {
166+ UseMultiAuthorMode = true ,
167+ BlogName = "Test" ,
168+ ConnectionString = "Test" ,
169+ DatabaseName = "Test"
170+ } ) ;
171+
172+ Services . AddScoped ( _ => options ) ;
173+
174+ var blogPost = new BlogPostBuilder ( )
175+ . WithAuthorName ( "Test Author" )
176+ . IsPublished ( true )
177+ . Build ( ) ;
178+
179+ var cut = Render < ShortBlogPost > ( p => p . Add ( c => c . BlogPost , blogPost ) ) ;
180+
181+ cut . FindAll ( "li:contains('Test Author')" ) . ShouldHaveSingleItem ( ) ;
182+ }
183+
184+ [ Fact ]
185+ public void ShouldNotShowAuthorNameWhenUseMultiAuthorModeIsFalse ( )
186+ {
187+ Services . AddScoped ( _ => Substitute . For < IBookmarkService > ( ) ) ;
188+ var options = Substitute . For < IOptions < ApplicationConfiguration > > ( ) ;
189+
190+ options . Value . Returns ( new ApplicationConfiguration ( )
191+ {
192+ UseMultiAuthorMode = false ,
193+ BlogName = "Test" ,
194+ ConnectionString = "Test" ,
195+ DatabaseName = "Test"
196+ } ) ;
197+
198+ Services . AddScoped ( _ => options ) ;
199+
200+ var blogPost = new BlogPostBuilder ( )
201+ . WithAuthorName ( "Test Author" )
202+ . IsPublished ( true )
203+ . Build ( ) ;
204+
205+ var cut = Render < ShortBlogPost > ( p => p . Add ( c => c . BlogPost , blogPost ) ) ;
206+
207+ cut . FindAll ( "li:contains('Test Author')" ) . ShouldBeEmpty ( ) ;
208+ }
88209}
0 commit comments