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 SubscriberFactory : ISubscriberFactory
7+ {
8+ public ISubscriber Create ( string emailAddress )
9+ {
10+ if ( string . IsNullOrEmpty ( emailAddress ) ) throw new ArgumentException ( "Must have email address to create subscriber." , nameof ( emailAddress ) ) ;
11+ return new Subscriber ( emailAddress ) ;
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 SubscriberFactoryTester
11+ {
12+ [ Test ]
13+ public void CanConstructSubscriberFactory ( )
14+ {
15+ // ARRANGE
16+
17+ // ACT
18+ var subjectUnderTest = new SubscriberFactory ( ) ;
19+
20+ // ASSERT
21+ Assert . That ( subjectUnderTest , Is . TypeOf ( typeof ( SubscriberFactory ) ) ) ;
22+ Assert . That ( subjectUnderTest , Is . InstanceOf ( typeof ( ISubscriberFactory ) ) ) ;
23+ }
24+
25+ [ Test ]
26+ public void CanCreateSubscriber ( )
27+ {
28+ // ARRANGE
29+ var expectedEmailAddress = "mickey.mouse@disney.com" ;
30+ var subjectUnderTest = new SubscriberFactory ( ) ;
31+
32+ // ACT
33+ var result = subjectUnderTest . Create ( expectedEmailAddress ) ;
34+
35+ // ASSERT
36+ Assert . That ( result , Is . Not . Null ) ;
37+ Assert . That ( result , Is . InstanceOf ( typeof ( ISubscriber ) ) ) ;
38+ Assert . That ( result . EmailAddress , Is . EqualTo ( expectedEmailAddress ) ) ;
39+ }
40+
41+ [ Test ]
42+ public void CreateThrowsArgumentExceptionWhenEmailNull ( )
43+ {
44+ // ARRANGE
45+ var expectedExceptionMessage = "Must have email address to create subscriber.\n Parameter name: emailAddress" ;
46+ var subjectUnderTest = new SubscriberFactory ( ) ;
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