Skip to content

Commit e2ab77d

Browse files
committed
Implement AddNote method an associated test.
1 parent 2f1c9d8 commit e2ab77d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Core/Domain/Models/Category.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace CompanyName.Notebook.NoteTaking.Core.Domain.Models
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using CompanyName.Notebook.NoteTaking.Core.Domain.Factories;
67

78
public class Category : ICategory
@@ -45,9 +46,13 @@ public INote AddNote(string text)
4546
return note;
4647
}
4748

48-
public void RemoveNote(Guid Id)
49+
public void RemoveNote(Guid id)
4950
{
50-
throw new NotImplementedException();
51+
if(Guid.Empty == id) return;
52+
if(null == Notes) return;
53+
if(Notes.Count < 1) return;
54+
55+
Notes.Remove(Notes.FirstOrDefault(note => note.Id == id));
5156
}
5257

5358
public INote RevealNote(Guid id)

test/Test.Unit.Core/Domain/Models/CategoryTester.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,28 @@ public void AddNoteThrowsArgumentExceptionWhenTextNull()
148148
);
149149
Assert.That(ex.Message, Is.EqualTo(expectedExceptionMessage));
150150
}
151+
152+
[Test]
153+
public void CanRemoveNote()
154+
{
155+
// ARRANGE
156+
string expectedName = "Verbose Notes";
157+
string expectedNoteText = "This is just a reminder to go to the store.";
158+
var expectedId = Guid.NewGuid();
159+
var expectedNote = Substitute.For<INote>();
160+
var subjectUnderTest = new Category(expectedName, _noteFactory, _subscriberFactory);
161+
162+
_noteFactory.Create(expectedNoteText).Returns(expectedNote);
163+
expectedNote.Id.Returns(expectedId);
164+
subjectUnderTest.AddNote(expectedNoteText);
165+
Assert.That(subjectUnderTest.Notes.Count, Is.EqualTo(1));
166+
167+
// ACT
168+
subjectUnderTest.RemoveNote(expectedId);
169+
170+
// ASSERT
171+
Assert.That(subjectUnderTest.Notes.Count, Is.EqualTo(0));
172+
_noteFactory.Received(1).Create(expectedNoteText);
173+
}
151174
}
152175
}

0 commit comments

Comments
 (0)