|
|
|
@ -16,7 +16,8 @@ namespace UnitTests_Model
|
|
|
|
|
{
|
|
|
|
|
user = new User("John", "john@example.com", "password123");
|
|
|
|
|
user.CreateTag("tag1","#FF0000");
|
|
|
|
|
user.CreateNote("note1", "default.png");
|
|
|
|
|
user.CreateTag("tag2", "#00FF00");
|
|
|
|
|
user.CreateNote("note1", "default.png");
|
|
|
|
|
user.AddTagFromNoteList(user.NoteList[0], user.TagList[0]);
|
|
|
|
|
user.CreateNote("note2", "default.png");
|
|
|
|
|
}
|
|
|
|
@ -47,6 +48,34 @@ namespace UnitTests_Model
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.SearchNoteByTag(user.NoteList, "tag3"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test SearchNoteByDate
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SearchNoteByDate_ValidData_ReturnsNote()
|
|
|
|
|
{
|
|
|
|
|
Note note = user.SearchNoteByDate(user.NoteList, "note1", DateOnly.FromDateTime(DateTime.Now), DateOnly.FromDateTime(DateTime.Now)).First();
|
|
|
|
|
Assert.That(note.Name, Is.EqualTo("note1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SearchNoteByDate_InvalidData_ReturnsNull()
|
|
|
|
|
{
|
|
|
|
|
Assert.That(user.SearchNoteByDate(user.NoteList, "note3", DateOnly.FromDateTime(DateTime.Now), DateOnly.FromDateTime(DateTime.Now)), Is.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test GetNoteByName
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_GetNoteByName_ValidData_ReturnsNote()
|
|
|
|
|
{
|
|
|
|
|
Note note = user.GetNoteByName("note1");
|
|
|
|
|
Assert.That(note.Name, Is.EqualTo("note1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_GetNoteByName_InvalidData_ReturnsNull()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.GetNoteByName("note3"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test searchTagByName
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SearchTagByName_ValidData_ReturnsTag()
|
|
|
|
@ -90,6 +119,165 @@ namespace UnitTests_Model
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test createNote
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_CreateNote_ValidData_AddNote()
|
|
|
|
|
{
|
|
|
|
|
user.CreateNote("note3", "default.png");
|
|
|
|
|
Assert.That(user.NoteList.Count, Is.EqualTo(3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_CreateNote_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
user.CreateNote("note3", "default.png");
|
|
|
|
|
Assert.Throws<AlreadyExistException>(() => user.CreateNote("note3", "default.png"));
|
|
|
|
|
}
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_CreateNote_ValidData_secondNote_AddNote()
|
|
|
|
|
{
|
|
|
|
|
User user2 = new User("John", "rien", "choco");
|
|
|
|
|
user2.CreateNote("note3", "default.png");
|
|
|
|
|
user2.CreateNote("note4", "default.png");
|
|
|
|
|
Assert.That(user2.NoteList.Count, Is.EqualTo(2));
|
|
|
|
|
Assert.That(user2.NoteList[1].id, Is.EqualTo(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test DeleteNote
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_DeleteNote_ValidData_RemoveNote()
|
|
|
|
|
{
|
|
|
|
|
Note note = user.NoteList[0];
|
|
|
|
|
user.DeleteNote(note);
|
|
|
|
|
Assert.That(user.NoteList.Count, Is.EqualTo(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_DeleteNote_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Note note = user.NoteList[0];
|
|
|
|
|
user.DeleteNote(note);
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.DeleteNote(note));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test CreateTag
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_CreateTag_ValidData_AddTag()
|
|
|
|
|
{
|
|
|
|
|
user.CreateTag("tag3", "#FF0000");
|
|
|
|
|
Assert.That(user.TagList.Count, Is.EqualTo(3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_CreateTag_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
user.CreateTag("tag3", "#FF0000");
|
|
|
|
|
Assert.Throws<AlreadyExistException>(() => user.CreateTag("tag2", "#FF0000"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test EditTagName
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_EditTagName_ValidData_EditTag()
|
|
|
|
|
{
|
|
|
|
|
user.EditTagName(user.TagList[0], "tag3");
|
|
|
|
|
Assert.That(user.TagList[0].Name, Is.EqualTo("tag3"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_EditTagName_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Tags tags = new Tags("tag2", "#FF0000");
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.EditTagName(tags, "tag1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_EditTagName_InvalidData2_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<AlreadyExistException>(() => user.EditTagName(user.TagList[0], "tag1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test EditTagColor
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_EditTagColor_ValidData_EditTag()
|
|
|
|
|
{
|
|
|
|
|
user.EditTagColor(user.TagList[0], "#FF0000");
|
|
|
|
|
Assert.That(user.TagList[0].Color, Is.EqualTo("#FF0000"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_EditTagColor_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Tags tags = new Tags("tag2", "#FF0000");
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.EditTagColor(tags, "#000000"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test AddTagFromNoteList
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_AddTagFromNoteList_ValidData_AddTag()
|
|
|
|
|
{
|
|
|
|
|
user.AddTagFromNoteList(user.NoteList[0], user.TagList[1]);
|
|
|
|
|
Assert.That(user.NoteTagged[user.NoteList[0]].Count, Is.EqualTo(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_AddTagFromNoteList_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Tags tags = new Tags("tag2", "#FF0000");
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.AddTagFromNoteList(user.NoteList[0], tags));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_AddTagFromNoteList_InvalidData2_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
User uvide = new User("", "", "");
|
|
|
|
|
Note note = new Note(4,"rien", "default.png", uvide);
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.AddTagFromNoteList(note, user.TagList[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test RemoveTagFromNoteList
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_RemoveTagFromNoteList_ValidData_RemoveTag()
|
|
|
|
|
{
|
|
|
|
|
user.RemoveTagFromNoteList(user.NoteList[0], user.TagList[0]);
|
|
|
|
|
Assert.That(user.NoteTagged[user.NoteList[0]], Is.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_RemoveTagFromNoteList_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Tags tags = new Tags("tag2", "#FF0000");
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.RemoveTagFromNoteList(user.NoteList[0], tags));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_RemoveTagFromNoteList_InvalidData2_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
User uvide = new User("", "", "");
|
|
|
|
|
Note note = new Note(4, "rien", "default.png", uvide);
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.RemoveTagFromNoteList(note, user.TagList[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test SetNoteName
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SetNoteName_ValidData_EditNote()
|
|
|
|
|
{
|
|
|
|
|
user.SetNoteName(user.NoteList[0], "note3");
|
|
|
|
|
Assert.That(user.NoteList[0].Name, Is.EqualTo("note3"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SetNoteName_InvalidData_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
User uvide = new User("", "", "");
|
|
|
|
|
Note note = new Note(4, "rien", "default.png", uvide);
|
|
|
|
|
Assert.Throws<NotFoundException>(() => user.SetNoteName(note, "note2"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void User_SetNoteName_InvalidData2_ThrowException()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<AlreadyUsedException>(() => user.SetNoteName(user.NoteList[0], "note1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|