public void AddNoteShouldSuccess() { Note note = new Note { NoteId = 1, NoteTitle = "Technology", NoteContent = "ASP.NET Core", NoteStatus = "Completed" }; noteRepository.AddNote(note); Assert.True(noteRepository.Exists(note.NoteId)); }
public void DeleteNoteTest_When_DeleteElementFromListWithElements_Then_Delete() { var repository = new NoteRepository(mock.Object); repository.AddNote("test", "test"); repository.AddNote("test1", "test1"); repository.AddNote(newTitle, newText); repository.AddNote("test3", "test3"); repository.AddNote("test4", "test4"); repository.DeleteNote(3); Assert.False(repository.GetNotes().Exists(x => x.Title == newTitle && x.Text == newText)); }
public void AddNoteTest_When_AddAfterDelete_Then_CorrectId() { var repository = new NoteRepository(mock.Object); for (var i = 1; i <= 5; i++) { repository.AddNote($"title{i}", $"text{i}"); } repository.DeleteNote(4); repository.AddNote($"title{6}", $"text{6}"); var notes = repository.GetNotes(); Assert.True(notes.FindAll(x => x.Id == 5).Count == 1); }
public HttpResponseMessage AddNote(Note note) { var repository = new NoteRepository(); var result = repository.AddNote(note); return(Request.CreateAddRecordResponse(result)); }
public void ShowNoteTest_When_HasElements_Then_ShowList() { var noteProviderMock = new Mock <INoteProvider>(); noteProviderMock.Setup(x => x.CreateNoteList()).Returns(new List <Note>()); var title = "title"; var text = "text"; var id = 1; var repository = new NoteRepository(noteProviderMock.Object); repository.AddNote(title, text); var fakeConsoleProvider = new FakeConsoleProvider(null); var service = new NoteConsoleService( repository, fakeConsoleProvider, new Mock <ICommandHelper>().Object); service.Handle(nameof(Command.List)); var expected = $"Here are list of all notes:{Environment.NewLine}" + $"id: {id} || title: '{title}' || text: '{text}'{Environment.NewLine}" + $"Press any key to return to the main window...{Environment.NewLine}"; Assert.Equal(expected, fakeConsoleProvider.Output); }
public void EditNoteTest_When_IdNotCorrectAndNotExist_Then_NotEdit() { var noteProviderMock = new Mock <INoteProvider>(); noteProviderMock.Setup(x => x.CreateNoteList()).Returns(new List <Note>()); var id = "44"; var repository = new NoteRepository(noteProviderMock.Object); repository.AddNote("title", "text"); var linesToRead = new List <string>() { id, "n" }; var fakeConsoleProvider = new FakeConsoleProvider(linesToRead); var service = new NoteConsoleService( repository, fakeConsoleProvider, new Mock <ICommandHelper>().Object); service.Handle(nameof(Command.Edit)); var expected = $"Please enter id of note to edit:{Environment.NewLine}" + $"The note with id [{id}] is not exist in the list of notes.{Environment.NewLine}" + $"Do you want to edit another note? (y/n){Environment.NewLine}"; Assert.Equal(expected, fakeConsoleProvider.Output); }
public void DeleteNoteTest_When_CorrectIdAndNoteExists_Then_Delete() { var noteProviderMock = new Mock <INoteProvider>(); noteProviderMock.Setup(x => x.CreateNoteList()).Returns(new List <Note>()); var id = "1"; var repository = new NoteRepository(noteProviderMock.Object); repository.AddNote("title", "text"); var linesToRead = new List <string>() { id, "n" }; var fakeConsoleProvider = new FakeConsoleProvider(linesToRead); var service = new NoteConsoleService( repository, fakeConsoleProvider, new Mock <ICommandHelper>().Object); service.Handle(nameof(Command.Delete)); var expected = $"Please enter id of note to delete:{Environment.NewLine}" + $"The note with id [{id}] was successfully deleted.{Environment.NewLine}" + $"Do you want to delete another note? (y/n){Environment.NewLine}"; Assert.Equal(expected, fakeConsoleProvider.Output); }
public void DeleteNoteTest_When_IdLessOrEqualZeroOrNull_Then_Error(int number) { var repository = new NoteRepository(mock.Object); repository.AddNote("test", "test"); Assert.Throws <InvalidOperationException>(() => repository.DeleteNote(number)); }
public void IsNoteExistTest_When_ElementNotExistInList_Then_False(int number) { var repository = new NoteRepository(mock.Object); repository.AddNote(newTitle, newText); Assert.False(repository.IsNoteExist(number)); }
public void GetNoteTest_When_ElementMoreThenListCount_Then_Error(int number) { var repository = new NoteRepository(mock.Object);; repository.AddNote(newTitle, newText); Assert.Throws <InvalidOperationException>(() => repository.GetNote(number + 5)); }
public void EditNoteTest_When_IdLessThenZero_Then_Error(int number) { var repository = new NoteRepository(mock.Object); repository.AddNote(newTitle, newText); Assert.Throws <InvalidOperationException>(() => repository.EditNote(number, newTitle, newText)); }
public void GetNoteTest_When_ElementIdIsLessOrEquelZero_Then_Error(int number) { var repository = new NoteRepository(mock.Object); repository.AddNote(newTitle, newText); Assert.Throws <InvalidOperationException>(() => repository.GetNote(number)); }
public void DeleteNoteTest_When_IdMoreThenListCount_Then_Error(int number) { var repository = new NoteRepository(mock.Object); repository.AddNote("test", "test"); Assert.Throws <InvalidOperationException>(() => repository.DeleteNote(number)); }
public void AddNoteTest_When_Add_Then_TextAndTitleHasSetValue(string title, string text) { var repository = new NoteRepository(mock.Object); repository.AddNote(title, text); var notes = repository.GetNotes(); Assert.True(notes.Exists(x => x.Title == title && x.Text == text)); }
public void AddNote_Should_add_note_on_valid_input() { // Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; landmarkService = new Mock <ILandmarkService>(); landmarkService.Setup(x => x.IsNoteExistsForThisLocation(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>())).Returns(0); using (var context = new ApplicationDbContext(options)) { context.Notes.Add(new Note { Remark = "this is first Note", Latitude = 523.987, Longitude = 908.786, Email = "*****@*****.**" }); context.Notes.Add(new Note { Remark = "second one", Latitude = 423.987, Longitude = 808.786, Email = "*****@*****.**" }); context.Notes.Add(new Note { Remark = "this is third Note", Latitude = 323.987, Longitude = 708.786, Email = "*****@*****.**" }); context.Notes.Add(new Note { Remark = "last Note", Latitude = 223.987, Longitude = 608.786, Email = "*****@*****.**" }); context.ApplicationUsers.Add(new ApplicationUser { FirstName = "firstName", LastName = "lastName", Email = "*****@*****.**", Password = "******" }); context.ApplicationUsers.Add(new ApplicationUser { FirstName = "firstName2", LastName = "lastName2", Email = "*****@*****.**", Password = "******" }); context.SaveChanges(); } var note = new Note { CreatedDate = DateTime.Now, Email = "*****@*****.**", Id = 12, Latitude = 12, Longitude = 23, Remark = "test remark" }; using (var context = new ApplicationDbContext(options)) { NoteRepository noteRepository = new NoteRepository(context, landmarkService.Object); // Act var response = noteRepository.AddNote(note); // Assert Assert.AreEqual(5, response.Count()); } }
public void IsNoteExistTest_When_ElementIdIsLessOrEquelZero_Then_False(int number) { var repository = new NoteRepository(mock.Object); for (var i = 0; i <= number + 1; i++) { repository.AddNote(newTitle + $"{i}", newText + $"{i}"); } Assert.False(repository.IsNoteExist(number)); }
public void IsNoteExistTest_When_ElementExistInList_Then_True(int number) { var repository = new NoteRepository(mock.Object); for (var i = 0; i <= number + 1; i++) { repository.AddNote($"{newTitle}{i}", $"{newText}{i}"); } Assert.True(repository.IsNoteExist(number)); }
public void AddNoteShouldSuccess() { Note note = new Note { NoteTitle = "Testing", NoteContent = "Unit Testing", NoteStatus = "Started" }; int result = noteRepository.AddNote(note); Assert.NotEqual(0, result); Assert.True(noteRepository.Exists(note.NoteId)); Assert.Equal(3, note.NoteId); }
public void AddNoteTest_When_Add_Then_ChangeListCount(string title, string text) { var repository = new NoteRepository(mock.Object); var countBefore = repository.GetNotes().Count; repository.AddNote(title, text); var countAfter = repository.GetNotes().Count; Assert.Equal(countBefore + 1, countAfter); }
public void GetNoteTest_When_ElementExistInList_Then_True(int number) { var repository = new NoteRepository(mock.Object); for (var i = 1; i <= number + 1; i++) { repository.AddNote($"{newTitle}{i}", $"{newText}{i}"); } Assert.True(repository.GetNote(number).Title == $"{newTitle}{number}" && repository.GetNote(number).Text == $"{newText}{number}"); }
void Save() { if (_note.IdNote == -1) { noteRepository.AddNote(_note); } else { noteRepository.UpdateNote(_note); } UpdateWorkstapeNotify?.Invoke(); }
public void EditNoteTest_When_ValidData_Then_Edit(int number, string title, string text) { var repository = new NoteRepository(mock.Object); for (var i = 0; i <= number + 1; i++) { repository.AddNote($"{oldTitle}{i}", $"{oldTitle}{i}"); } repository.EditNote(number, title, text); var notes = repository.GetNotes(); Assert.True(!notes.Exists(x => x.Title == $"{oldTitle}{number}" && x.Text == $"{oldText}{number}") && notes.Exists(x => x.Title == title && x.Text == text)); }
public void EditNoteTest_When_NotCorrectareYouSureAboutThat_Then_NotEdit() { var noteProviderMock = new Mock <INoteProvider>(); noteProviderMock.Setup(x => x.CreateNoteList()).Returns(new List <Note>()); var id = "1"; var title = "title"; var text = "text"; var newTitle = string.Empty; var newText = string.Empty; var areYouSureAboutThatNotCorrect = "error"; var areYouSureAboutThat = "y"; var repository = new NoteRepository(noteProviderMock.Object); repository.AddNote(title, text); var linesToRead = new List <string>() { id, newTitle, areYouSureAboutThatNotCorrect, areYouSureAboutThat, newText, "n" }; var fakeConsoleProvider = new FakeConsoleProvider(linesToRead); var service = new NoteConsoleService( repository, fakeConsoleProvider, new Mock <ICommandHelper>().Object); service.Handle(nameof(Command.Edit)); var expected = $"Please enter id of note to edit:{Environment.NewLine}" + $"Current title of this note: {title}. Pick a new title:{Environment.NewLine}" + $"> Are you sure (y/n)?{Environment.NewLine}" + $"Wrong input! Pass only \"y\" or \"n\".{Environment.NewLine}" + $"Current text of this note: {text}. Pick a new text:{Environment.NewLine}" + $"> Text was NOT successfully changed. Enter title or text.{Environment.NewLine}" + $"Do you want to edit another note? (y/n){Environment.NewLine}"; Assert.Equal(expected, fakeConsoleProvider.Output); }
public void GenerateNotes( NoteRepository noteRepository, int countNotes ) { if (noteRepository == null || countNotes < 1) { throw new ArgumentException("noteRepository is null or countNotes <0"); } Random saintRandom = new Random(); DateTime dateNote = DateTime.Now.AddDays(-1); List <TypeJob> typeJobs = new TypeJobRepository(Properties.Resources.ConnectCommand).GetAllTypeJobs(); List <Relevance> relevances = new RelevanceRepository(Properties.Resources.ConnectCommand).GetAllRelevances(); List <Progress> progresses = new ProgressRepository(Properties.Resources.ConnectCommand).GetAllProgresses(); for (int i = 0; i < countNotes; i++) { noteRepository.RemoveNotes(dateNote); int[] timeLines = GetTimeLines(); for (int j = 0; j < timeLines.Length - 1; j += 1) { Note note = new Note(); note.NoteDate = dateNote; note.TypeJob = typeJobs[saintRandom.Next(1, 6)]; note.Relevance = relevances[saintRandom.Next(1, 4)]; note.Progress = progresses[saintRandom.Next(1, 4)]; note.TimeStart = new TimeSpan(timeLines[j], 1, 0); note.TimeFinish = new TimeSpan(timeLines[j + 1], 0, 0); noteRepository.AddNote(note); } dateNote = dateNote.AddDays(-1); } }
public void TestAddToDatabase() { Assert.AreEqual(0, repo.GetCount()); repo.AddNote(new Note("notetitle", "12/24/2011", 2, "heyyyyy QT")); Assert.AreEqual(1, repo.GetCount()); }
public void AddNoteTest() { NoteRepository repository = new NoteRepository(resConnect); Assert.ThrowsException <ArgumentNullException>(() => repository.AddNote(null)); }