Skip to content

Commit 35cd1e4

Browse files
committed
Add ISubscriberFactory implementation and test harness.
1 parent f754902 commit 35cd1e4

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.\nParameter 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+
}

0 commit comments

Comments
 (0)