File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
src/Core/Domain/Factories
test/Test.Unit.Core/Domain/Factories Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ namespace CompanyName . Notebook . NoteTaking . Core . Domain . Factories
2+ {
3+ using System ;
4+ using CompanyName . Notebook . NoteTaking . Core . Domain . Models ;
5+
6+ public class NoteFactory : INoteFactory
7+ {
8+ public INote Create ( string text )
9+ {
10+ if ( string . IsNullOrEmpty ( text ) ) throw new ArgumentException ( "Must have text to create note." , nameof ( text ) ) ;
11+ return new Note ( text ) ;
12+ }
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ namespace Test . Unit . Core . Domain . Factories
2+ {
3+ using System ;
4+ using CompanyName . Notebook . NoteTaking . Core . Domain . Factories ;
5+ using CompanyName . Notebook . NoteTaking . Core . Domain . Models ;
6+ using NSubstitute ;
7+ using NUnit . Framework ;
8+
9+ [ TestFixture ]
10+ public class NoteFactoryTester
11+ {
12+ [ Test ]
13+ public void CanConstructNoteFactory ( )
14+ {
15+ // ARRANGE
16+
17+ // ACT
18+ var subjectUnderTest = new NoteFactory ( ) ;
19+
20+ // ASSERT
21+ Assert . That ( subjectUnderTest , Is . TypeOf ( typeof ( NoteFactory ) ) ) ;
22+ Assert . That ( subjectUnderTest , Is . InstanceOf ( typeof ( INoteFactory ) ) ) ;
23+ }
24+
25+ [ Test ]
26+ public void CanCreateNote ( )
27+ {
28+ // ARRANGE
29+ var expectedNoteText = "This is just a reminder to go to the store." ;
30+ var subjectUnderTest = new NoteFactory ( ) ;
31+
32+ // ACT
33+ var result = subjectUnderTest . Create ( expectedNoteText ) ;
34+
35+ // ASSERT
36+ Assert . That ( result , Is . Not . Null ) ;
37+ Assert . That ( result , Is . InstanceOf ( typeof ( INote ) ) ) ;
38+ Assert . That ( result . Text , Is . EqualTo ( expectedNoteText ) ) ;
39+ }
40+
41+ [ Test ]
42+ public void CreateThrowsArgumentExceptionWhenTextNull ( )
43+ {
44+ // ARRANGE
45+ var expectedExceptionMessage = "Must have text to create note.\n Parameter name: text" ;
46+ var subjectUnderTest = new NoteFactory ( ) ;
47+
48+ // ACT
49+ // ASSERT
50+ var ex = Assert . Throws < ArgumentException > (
51+ ( ) => subjectUnderTest . Create ( null )
52+ ) ;
53+ Assert . That ( ex . Message , Is . EqualTo ( expectedExceptionMessage ) ) ;
54+ }
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments