Skip to content

Commit a5e5715

Browse files
committed
Add NoteFactory implementation and the corresponding test harness.
1 parent bc7c157 commit a5e5715

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 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+
}
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 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.\nParameter 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+
}

0 commit comments

Comments
 (0)