public void UpdateNoteTags_AddingAllTheExistingTagsToAnExistingNoteThatHasNoTags() { using (var context = new NexusContext(_options)) { var note = DataProvider.CreateNote(); var tags = DataProvider.GetAlphabeticalTags(); context.Notes.Add(note); context.Tags.AddRange(tags); context.SaveChanges(); } using (var context = new NexusContext(_options)) { var noteRepo = new NoteRepository(context); var note = noteRepo.GetAll().Single(); noteRepo.UpdateNoteTags(note.Id, DataProvider.GetAlphabeticalTags().Select(t => t.Title)); noteRepo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(_options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.Equal(3, note.NoteTags.Count); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "B"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "C"); } }
public IHttpActionResult Delete(int id) { NoteRepository noterepo = new NoteRepository(); noterepo.Delete(id); return(StatusCode(HttpStatusCode.NoContent)); }
private void FullResync() { if (Repository.ProviderUID == Guid.Parse("37de6de1-26b0-41f5-b252-5e625d9ecfa3")) { return; // no full resync in headless } try { if (MessageBox.Show(Owner, "Do you really want to delete all local data and download the server data?", "Full resync?", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { return; } Repository.Shutdown(false); Repository.DeleteLocalData(); _repository = new NoteRepository(AppSettings.PATH_LOCALDB, this, Settings, Settings.ActiveAccount, dispatcher); _repository.Init(); OnExplicitPropertyChanged("Repository"); SelectedNote = null; } catch (Exception e) { App.Logger.Error("Main", "Full Synchronization failed", e); ExceptionDialog.Show(Owner, "Full Synchronization failed", e, string.Empty); } }
public void UpdateNoteTags_ModifyingExistingNoteTagsByAddingAndRemovingTags() { // SEEDING using (var context = new NexusContext(_options)) { var note = DataProvider.CreateNote().AssignNoteTags(DataProvider.GetAlphabeticalTags()); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(_options)) { var repo = new NoteRepository(context); // Adding D, removing C var note = context.Notes.First(); repo.UpdateNoteTags(note.Id, new[] { "A", "B", "D" }); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(_options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); var tagTitles = note.NoteTags.Select(nt => nt.Tag.Title).ToList(); Assert.Contains("A", tagTitles); Assert.Contains("B", tagTitles); Assert.Contains("D", tagTitles); Assert.DoesNotContain("C", tagTitles); } }
public HttpResponseMessage DeleteNote(int noteId) { var repo = new NoteRepository(); var result = repo.DeleteNote(noteId); return(Request.CreateUpdateRecordResponse(result)); }
public NoteBusinesses(IServiceProvider provider, NoteRepository repository, NoteReadRangeRepository readrepository, NoteReadRepository noteReadRepository) : base(provider, repository) { this._repository = repository; this._readrepository = readrepository; this._noteReadRepository = noteReadRepository; }
public void GetAllNotes_Should_return_list_of_notes_available() { // 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.ApplicationUsers.Add(new ApplicationUser { FirstName = "firstName", LastName = "lastName", Email = "*****@*****.**", Password = "******" }); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) { NoteRepository noteRepository = new NoteRepository(context, landmarkService.Object); // Act var response = noteRepository.GetAllNotes(); // Assert Assert.AreEqual(2, response.Count()); } }
public HttpResponseMessage GetNote(int noteId) { var repo = new NoteRepository(); var result = repo.GetNoteById(noteId); return(Request.CreateListRecordsResponse(result)); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Attempts = new AttemptRepository(_context); Exams = new ExamRepository(_context); Images = new ImageRepository(_context); NoteParameters = new NoteParameterRepository(_context); Notifications = new NotificationRepository(_context); Notes = new NoteRepository(_context); Opinions = new OpinionRepository(_context); Options = new OptionRepository(_context); Passages = new PassageRepository(_context); Questions = new QuestionRepository(_context); Requirements = new RequirementRepository(_context); Roles = new RoleRepository(_context); RoleClaims = new RoleClaimRepository(_context); Standards = new StandardRepository(_context); Sittings = new SittingRepository(_context); Topics = new TopicRepository(_context); Users = new UserRepository(_context); UserClaims = new UserClaimRepository(_context); UserLogins = new UserLoginRepository(_context); UserRoles = new UserRoleRepository(_context); UserTokens = new UserTokenRepository(_context); }
/// <summary> /// 저장 버튼 클릭스 해당 정보를 Note 객채로 변환해 DB에 저장 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnWrite_Click(object sender, EventArgs e) { if (IsImageTextCorrect()) { UploadProcess(); // 파일 업로드 프로세스 구현 Note note = new Note(); note.Name = txtName.Text; note.Email = HtmlUtility.Encode(txtEmail.Text); note.Homepage = txtHomepage.Text; note.Title = txtTitle.Text; note.Content = HtmlUtility.Encode(txtContent.Text); note.FileName = _FileName; note.FileSize = _FileSize; note.Password = txtPassword.Text; note.PostIp = Request.UserHostAddress; note.Encoding = rdoEncoding.SelectedValue; NoteRepository repo = new NoteRepository(); repo.Add(note); Response.Redirect("BoardList.aspx"); } else { lblError.Text = "보안코드가 틀립니다. 다시 입력하세요."; } }
public static bool ShowInputDialog(Window owner, string title, NoteRepository repo, INote initial, out INote result) { var notes = repo.Notes .OrderBy(p => p.Title.ToLower()) .ThenBy(p => p.CreationDate) .ToList(); var id = new NoteChooserDialog { Title = title, Notes = new ObservableCollection <INote>(notes), SelectedNote = initial }; if (owner != null) { id.Owner = owner; } var r = id.ShowDialog(); if (r == true && id.SelectedNote != null) { result = id.SelectedNote; return(true); } result = null; return(false); }
public async void GetNotesAsyncShouldReturnNotesFilteredByNameContains() { var databaseName = Guid.NewGuid().ToString(); using (var context = GetInMemoryDataContext(databaseName)) { // arrange SeedData(context); } using (var context = GetInMemoryDataContext(databaseName)) { // arrange var repository = new NoteRepository(context); var filters = new Filter[] { new Filter() { Field = "Name", Operator = "ct", Value = "ne" } }; // act List <Note> result = await repository.GetNotesAsync(x => true, filters, null); // assert Assert.NotEmpty(result); Assert.Equal(4, result.Count); } }
public async void GetNotesAsyncShouldReturnNotesOfSpecificCalendar() { var databaseName = Guid.NewGuid().ToString(); using (var context = GetInMemoryDataContext(databaseName)) { // arrange SeedData(context); } using (var context = GetInMemoryDataContext(databaseName)) { // arrange var repository = new NoteRepository(context); // act List <Note> result = await repository.GetNotesAsync(x => x.CalendarId == 1, null, null); // assert Assert.NotEmpty(result); Assert.DoesNotContain(result, x => x.CalendarId != 1); } }
public HttpResponseMessage AddNote(Note note) { var repository = new NoteRepository(); var result = repository.AddNote(note); return(Request.CreateAddRecordResponse(result)); }
// GET Notes | Create new connections of database public NotesController() { uowUser = new UserRepository(); uowNote = new NoteRepository(); noteRepository = uowNote.unitOfWork.EntityRepository; userRepository = uowUser.unitOfWork.EntityRepository; }
public HttpResponseMessage ListNote() { var repository = new NoteRepository(); var result = repository.ListNote(); return(Request.CreateListRecordsResponse(result)); }
public NoteManager(IUserInterfaceManager parentUI, string connectionString, int postId) { _parentUI = parentUI; _noteRepository = new NoteRepository(connectionString); _postRepository = new PostRepository(connectionString); _postId = postId; }
private NoteRepository GetNoteRepository() { var sqlConnectionProvider = new SqlConnectionProvider(ConnectionString); var noteRepository = new NoteRepository(sqlConnectionProvider); return(noteRepository); }
public void UpdateNoteTags_GivenTheSameNoteTagsToUpdateNotesTags() { using (var context = new NexusContext(_options)) { context.Database.EnsureCreated(); var note = DataProvider.CreateNote(); var tags = DataProvider.GetAlphabeticalTags(); note.AssignNoteTags(tags); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(_options)) { var noteRepo = new NoteRepository(context); var note = noteRepo.GetAll().Single(); noteRepo.UpdateNoteTags(note.Id, DataProvider.GetAlphabeticalTags().Select(t => t.Title)); noteRepo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(_options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.Equal(3, note.NoteTags.Count); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "B"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "C"); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var config = new MongoDBConfig(); Configuration.Bind(config); #region NoteCollecion var noteContext = new NoteContext(config); var noteRepository = new NoteRepository(noteContext); services.AddSingleton(noteRepository); #endregion services.AddControllers(); services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins("http://localhost:4200") .AllowAnyHeader() .AllowAnyMethod(); }); }); }
public void UpdateNoteTags_AddingNewTagBeforeAnExistingTag() { using (var context = new NexusContext(_options)) { context.Notes.Add(DataProvider.CreateNote()); context.Tags.AddRange(DataProvider.GetAlphabeticalTags()); context.SaveChanges(); } using (var context = new NexusContext(_options)) { var repo = new NoteRepository(context); var note = repo.GetAll().First(); repo.UpdateNoteTags(note.Id, new List <string>() { "X", "A" }); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(_options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.True(note.NoteTags.Count == 2); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "X"); } }
public void UpdateNote() { User _user = new UsersRepository(_connectionString, new CategoriesRepository(_connectionString)).Create(new User { Name = "TestUserUpdater" }); Category _category = new CategoriesRepository(_connectionString).Create(_user.Id, $"CategoryUpdater {_user.Name}"); Note testNote = new Note { Title = "TestTitleUpdate", Content = "TestContentUpdate", Owner = _user, DateCreated = DateTime.Now, DateChanged = DateTime.Now, Categories = new CategoriesRepository(_connectionString).GetUserCategories(_user.Id), SharedNote = null }; var noteToSQL = new NoteRepository(_connectionString).Create(testNote); noteToSQL.Title = "SuccessUpdate"; noteToSQL.Content = "eeee"; var noteAfterUpdate = new NoteRepository(_connectionString).UpdateNote(noteToSQL); Assert.AreEqual(noteToSQL.Content, noteAfterUpdate.Content); }
public HttpResponseMessage EditNote(int id, NoteDto notedto) { var repo = new NoteRepository(); var result = repo.Update(notedto); return(Request.CreateUpdateRecordResponse(result)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var config = new ServerConfig(); Configuration.Bind(config); var noteContext = new NoteContext(config.MongoDB); var repository = new NoteRepository(noteContext); services.AddSingleton <INoteRepository>(repository); var consumerConfig = new ConsumerConfig(); Configuration.Bind("Kafka", consumerConfig); services.AddSingleton <ConsumerConfig>(consumerConfig); services.AddHostedService <UserConsumer>(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Note API", Version = "v1", Description = "Note API", }); }); }
public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) { ApiController controller; if (controllerType == typeof(ProjectController)) { var projectRepository = new ProjectRepository(_eventBus); controller = new ProjectController(projectRepository); } else if (controllerType == typeof(TaskController)) { var taskRepository = new TaskRepository(_eventBus); controller = new TaskController(taskRepository); } else if (controllerType == typeof(NoteController)) { var noteRepository = new NoteRepository(_eventBus); controller = new NoteController(noteRepository); } else { throw new ArgumentException("Unexpected type!", nameof(controllerType)); } return(controller); }
public void GetPreviousNote_VisAndInvisNotes_HasPrevNote_ShouldTakeTheHiddenNoteIntoAccount() { var mockContext = new Mock <NexusContext>(); mockContext.Setup(nex => nex.Set <Note>()).Returns(TestHelpers.MockDbSet(new List <Note> { new Note { Id = 1, IsVisible = true, CreationDate = DateTime.Now }, new Note { Id = 2, IsVisible = false, CreationDate = DateTime.Now.AddDays(1) }, new Note { Id = 3, IsVisible = true, CreationDate = DateTime.Now.AddDays(2) }, })); var repository = new NoteRepository(mockContext.Object); var comparedNote = repository.Get(3); var previosNote = repository.GetPreviousNote(comparedNote, honorVisibilityRule: false); Assert.NotNull(previosNote); Assert.Equal(2, previosNote.Id); Assert.NotEqual(1, previosNote.Id); }
public void Test1_VisibleOnly_HasPrevNoteAndNextNoteButTheyreBothHidden_PrevNoteAndNextNodeShouldBeNull() { var mock = new Mock <NexusContext>(); mock.Setup(nex => nex.Set <Note>()).Returns(TestHelpers.MockDbSet(new List <Note> { new Note { Id = 1, IsVisible = false, CreationDate = DateTime.Now }, new Note { Id = 2, IsVisible = true, CreationDate = DateTime.Now.AddDays(1) }, new Note { Id = 3, IsVisible = false, CreationDate = DateTime.Now.AddDays(2) }, })); var repository = new NoteRepository(mock.Object); var comparedNote = repository.Get(id: 2); var prevNote = repository.GetPreviousNote(comparedNote, honorVisibilityRule: true); var nextNode = repository.GetNextNote(comparedNote, honorVisibilityRule: true); Assert.Null(prevNote); Assert.Null(nextNode); }
public void UpdateNoteTags_NoteHasNoTags_AddingBrandNewTagsToAnExistingNote() { string databaseName = Guid.NewGuid().ToString(); var options = InMemoryHelpers.CreateOptions(databaseName); using (var context = new NexusContext(options)) { var note = DataProvider.CreateNote(); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(options)) { var repo = new NoteRepository(context); var tagsToBeAdded = DataProvider.GetAlphabeticalTags(); var note = repo.GetAll().First(); repo.UpdateNoteTags(note.Id, tagsToBeAdded.Select(t => t.Title)); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.Equal(3, note.NoteTags.Count); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "B"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "C"); } }
public void GetNextNode_VisibleOnly_HasNextNotesButTheImmediateNextNoteIsHidden_ShouldOmitTheHiddenOne() { var mockContext = new Mock <NexusContext>(); mockContext.Setup(nex => nex.Set <Note>()).Returns(TestHelpers.MockDbSet(new List <Note> { new Note { Id = 1, IsVisible = true, CreationDate = DateTime.Now }, new Note { Id = 2, IsVisible = false, CreationDate = DateTime.Now.AddDays(1) }, new Note { Id = 3, IsVisible = true, CreationDate = DateTime.Now.AddDays(3) } })); var repository = new NoteRepository(mockContext.Object); var comparedNote = repository.Get(1); var nextNote = repository.GetNextNote(comparedNote, honorVisibilityRule: true); Assert.NotNull(nextNote); Assert.Equal(3, nextNote.Id); }
public override void OnAfterSave(ISaveRequestHandler handler) { var newList = Target.AsObject(handler.Row) as List<NoteRow>; if (newList == null) return; var idField = (handler.Row as IIdRow).IdField; var entityId = idField[handler.Row].Value; if (handler.IsCreate) { foreach (var note in newList) SaveNote(handler.UnitOfWork, note, handler.Row.Table, entityId, null); return; } var fld = NoteRow.Fields; var listRequest = new ListRequest { ColumnSelection = ColumnSelection.List, EqualityFilter = new Dictionary<string, object> { { fld.EntityType.PropertyName, handler.Row.Table }, { fld.EntityId.PropertyName, entityId } } }; var oldList = new NoteRepository().List(handler.Connection, listRequest).Entities; NoteListSave(handler.UnitOfWork, handler.Row.Table, entityId, oldList, newList); }
public void UpdateNoteTags_RemovingExistingNoteTags() { var options = SQLiteHelpers.CreateOptions(); // SEEDING using (var context = new NexusContext(options)) { context.Database.EnsureCreated(); // Creates the in-memory SQLite database var note = DataProvider.CreateNote().AssignNoteTags(DataProvider.GetAlphabeticalTags()); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(options)) { var repo = new NoteRepository(context); repo.UpdateNoteTags(1, new List <string>()); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).First(); Assert.False(note.NoteTags.Any()); } }
public void NoteIsUpdatedInSessionWhenUpdateIsCalled() { var mockSession = new Mock<ISession>(); NoteRepository noteRepository = new NoteRepository(mockSession.Object); Entities.Note note = new Entities.Note(); noteRepository.Update(note); mockSession.Verify(x => x.Update(note), Times.Once()); }
public void EntityIsSavedInSessionWhenAddIsCalled() { var mockSession = new Mock<ISession>(); NoteRepository noteRepository = new NoteRepository(mockSession.Object); Entities.Note note = new Entities.Note(); noteRepository.Add(note); mockSession.Verify(x => x.Save(note), Times.Once()); }
public void EntityIsLoadedFromSessionWhenLoadIsCalled() { var mockSession = new Mock<ISession>(); NoteRepository noteRepository = new NoteRepository(mockSession.Object); Guid id = Guid.NewGuid(); noteRepository.Load(id); mockSession.Verify(x => x.Load<Entities.Note>(id), Times.Once()); }
public void EntityIsDeletedFromSessionWhenRemoveIsCalled() { var mockSession = new Mock<ISession>(); NoteRepository noteRepository = new NoteRepository(mockSession.Object); Entities.Note note = new Entities.Note(); noteRepository.Remove(note); mockSession.Verify(x => x.Delete(note), Times.Once()); }
public void GetByOwnerIdOnlyReturnsNotesFromSpecifiedOwner() { Guid ownerId = Guid.NewGuid(); var mockSession = new Mock<ISession>(); var mockQueryable = new Mock<INHibernateQueryable<Entities.Note>>(); IList<Entities.Note> notes = new List<Entities.Note>(); notes.Add(new Entities.Note{OwnerId = ownerId}); notes.Add(new Entities.Note{OwnerId = Guid.NewGuid()}); mockQueryable.Setup(x => x.GetEnumerator()).Returns(notes.GetEnumerator); mockSession.Setup(x => x.Linq<Entities.Note>()).Returns(mockQueryable.Object); var noteRepository = new NoteRepository(mockSession.Object); var result = noteRepository.GetByOwnerId(ownerId); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.AreEqual(ownerId, result[0].OwnerId); }
public void OnReturn(IRetrieveRequestHandler handler) { if (ReferenceEquals(null, Target) || !handler.ShouldSelectField(Target)) return; var idField = (handler.Row as IIdRow).IdField; var fld = NoteRow.Fields; var listRequest = new ListRequest { ColumnSelection = ColumnSelection.List, EqualityFilter = new Dictionary<string, object> { { fld.EntityType.PropertyName, handler.Row.Table }, { fld.EntityId.PropertyName, idField[handler.Row] ?? -1 } } }; var notes = new NoteRepository().List(handler.Connection, listRequest).Entities; // users might be in another database, in another db server, so we can't simply use a join here var userIdList = notes.Where(x => x.InsertUserId != null).Select(x => x.InsertUserId.Value).Distinct(); if (userIdList.Any()) { var u = UserRow.Fields; IDictionary<int, string> userDisplayNames; using (var connection = SqlConnections.NewFor<UserRow>()) userDisplayNames = connection.Query(new SqlQuery() .From(u) .Select(u.UserId) .Select(u.DisplayName) .Where(u.UserId.In(userIdList))) .ToDictionary(x => (int)x.UserId, x => (string)x.DisplayName); string s; foreach (var x in notes) if (x.InsertUserId != null && userDisplayNames.TryGetValue(x.InsertUserId.Value, out s)) x.InsertUserDisplayName = s; } Target.AsObject(handler.Row, notes); }