async Task Save(YobaNote note, CancellationToken cancel) { if (string.IsNullOrEmpty(note.Content)) { await _dao.DeleteNote(note, cancel); } else { await _dao.AddOrUpdateNote(note, cancel); } }
public async Task Test() { //public async Task Note_ShouldBeCreated() { await _dao.AddOrUpdateNote(_note); var dst = await _dao.FindNote(_note.Name); var notes = await _dao.GetNotes(); dst.Content.Should().Be(_note.Content); dst.Name.Should().Be(_note.Name); dst.DisplayName.Should().Be(_note.DisplayName); var list = await _dao.GetNotes(); list.Count.Should().Be(1); list.Single().Name.Should().Be(_note.Name); } //public async Task Note_ShouldBeUpdated() { var src = await _dao.FindNote(_note.Name); src.Content += Environment.NewLine + "line3"; await _dao.AddOrUpdateNote(src); var dst = await _dao.FindNote(src.Name); dst.Content.Should().Be(src.Content); } //public async Task Note_ShouldBeDeleted() { await _dao.DeleteNote(_note); var dst = await _dao.FindNote(_note.Name); dst.Should().BeNull(); var list = await _dao.GetNotes(); list.Count.Should().Be(0); } }
public async Task Test() { //AddOrUpdateNote { //Create new note from line await Handle($"ёба добавь в заметку {_note.DisplayName} : {_note.Content}"); var note = await _dao.FindNote(_note.Name); note.Content.Should().Be(_note.Content); //Append line to note var line = Guid.NewGuid().ToString(); await Handle($"ёба добавь в заметку {_note.DisplayName} : {line}"); note = await _dao.FindNote(_note.Name); _note.Content.Should().ContainAll(_note.Content.Split('\r', '\n')); note.Content.Should().Contain(line); //Reset note to original content await Handle($"ёба обнови заметку {_note.DisplayName} : {_note.Content}"); note = await _dao.FindNote(_note.Name); note.Content.Should().Be(_note.Content); } //ShowNote { var result = await Handle($"ёба покажи заметку {_note.DisplayName}"); result.Response.Text.Should().ContainAll(_note.Content.Split('\r', '\n')); } var note2 = new YobaNote { Content = "aaaaa" + Environment.NewLine + "bbb", DisplayName = "baz", Created = DateTime.Now, Updated = DateTime.Now }; await _dao.AddOrUpdateNote(note2); //ListNotes { async Task checkList(string msg) { var result = await Handle(msg); result.Response.Text.Should().Contain(note2.DisplayName); } await checkList("ёба покажи список заметок"); await checkList("ёба покажи заметки"); } //DelNoteLine { await Handle($"ёба удали 1 из {note2.DisplayName}"); var tmp = await _dao.FindNote(note2.Name); tmp.Content.Should().Contain("bbb"); tmp.Content.Should().NotContain("aaaaa"); //Empty note should be deleted await Handle($"ёба удали 1 из {note2.DisplayName}"); tmp = await _dao.FindNote(note2.Name); tmp.Should().BeNull(); } }