public void NoteHistoryIsSaved() { var sample_notes = DbStorageTests.GetSampleNotes (); using (var storage = new DbStorage (this.connFactory, this.testUser.Username, this.testUser.Manifest, use_history: true)) { foreach(var note in sample_notes) { storage.SaveNote (note); } } // modify the notes using (var storage = new DbStorage (this.connFactory, this.testUser.Username, this.testUser.Manifest, use_history: true)) { foreach(var note in sample_notes) { note.Title = "Random new title"; storage.SaveNote (note); } } // for each note there should exist a backup copy foreach (var note in sample_notes) { using (var db = connFactory.OpenDbConnection ()) { var archived_note = db.FirstOrDefault<DBArchivedNote> (n => n.Guid == note.Guid); Assert.IsNotNull (archived_note); Assert.AreNotEqual ("Random new title", archived_note.Title); } } }
public DatabaseNoteRepository(IDbConnectionFactory factory, DbStorageFactory storageFactory, IUser user) : base(factory) { this.storage = storageFactory.GetDbStorage (user); engine = new Engine (storage); using (var db = connFactory.OpenDbConnection ()) { this.dbUser = db.Select<DBUser> (u => u.Username == user.Username)[0]; } if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
public void DateUtcIsCorrectlyStored() { DbStorage storage = new DbStorage(connFactory, testUser.Username); var tomboy_note = new Note (); tomboy_note.ChangeDate = new DateTime (2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); tomboy_note.CreateDate = tomboy_note.ChangeDate; tomboy_note.MetadataChangeDate = tomboy_note.ChangeDate; storage.SaveNote (tomboy_note); var stored_note = storage.GetNotes ().Values.First (); storage.Dispose (); Assert.AreEqual (tomboy_note.ChangeDate, stored_note.ChangeDate.ToUniversalTime ()); }
public void DateUtcIsCorrectlyStored() { DbStorage storage = new DbStorage(testUser); var tomboy_note = new Note(); tomboy_note.ChangeDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); tomboy_note.CreateDate = tomboy_note.ChangeDate; tomboy_note.MetadataChangeDate = tomboy_note.ChangeDate; storage.SaveNote(tomboy_note); var stored_note = storage.GetNotes().Values.First(); storage.Dispose(); Assert.AreEqual(tomboy_note.ChangeDate, stored_note.ChangeDate.ToUniversalTime()); }
public void StoreSomeNotes() { string username = "******"; var sample_notes = GetSampleNotes (); using (var store = new DbStorage (username)) { sample_notes.ForEach (n => store.SaveNote (n)); } // now check if we have stored that notes using (var store = new DbStorage (username)) { var stored_notes = store.GetNotes ().Values.ToList (); Assert.AreEqual (sample_notes.Count, stored_notes.Count); stored_notes.ForEach(n => Assert.Contains (n, sample_notes)); } }
public void StoreSomeNotes() { var sample_notes = GetSampleNotes(); using (var store = new DbStorage(testUser)) { sample_notes.ForEach(n => store.SaveNote(n)); } // now check if we have stored that notes using (var store = new DbStorage(testUser)) { var stored_notes = store.GetNotes().Values.ToList(); Assert.AreEqual(sample_notes.Count, stored_notes.Count); stored_notes.ForEach(n => Assert.Contains(n, sample_notes)); // check that the dates are still the same stored_notes.ForEach(n => { var sample_note = sample_notes.First(sn => sn.Guid == n.Guid); Assert.AreEqual(n.ChangeDate, sample_note.ChangeDate); }); } }
public void StoreSomeNotes() { var sample_notes = GetSampleNotes (); using (var store = new DbStorage (testUser)) { sample_notes.ForEach (n => store.SaveNote (n)); } // now check if we have stored that notes using (var store = new DbStorage (testUser)) { var stored_notes = store.GetNotes ().Values.ToList (); Assert.AreEqual (sample_notes.Count, stored_notes.Count); stored_notes.ForEach(n => Assert.Contains (n, sample_notes)); // check that the dates are still the same stored_notes.ForEach(n => { var sample_note = sample_notes.First(sn => sn.Guid == n.Guid); Assert.AreEqual (n.ChangeDate, sample_note.ChangeDate); }); } }
public void StoreAndDelete() { StoreSomeNotes(); using (var store = new DbStorage(testUser)) { var stored_notes = store.GetNotes().Values.ToList(); var deleted_note = stored_notes[0]; store.DeleteNote(deleted_note); Assert.AreEqual(stored_notes.Count - 1, store.GetNotes().Values.Count); Assert.That(!store.GetNotes().Values.Contains(deleted_note)); deleted_note = stored_notes[1]; store.DeleteNote(deleted_note); Assert.AreEqual(stored_notes.Count - 2, store.GetNotes().Values.Count); Assert.That(!store.GetNotes().Values.Contains(deleted_note)); deleted_note = stored_notes[2]; store.DeleteNote(deleted_note); Assert.AreEqual(stored_notes.Count - 3, store.GetNotes().Values.Count); Assert.That(!store.GetNotes().Values.Contains(deleted_note)); } }
public void StoreAndDelete() { StoreSomeNotes (); using (var store = new DbStorage (testUser)) { var stored_notes = store.GetNotes ().Values.ToList (); var deleted_note = stored_notes[0]; store.DeleteNote (deleted_note); Assert.AreEqual (stored_notes.Count - 1, store.GetNotes ().Values.Count); Assert.That (! store.GetNotes ().Values.Contains (deleted_note)); deleted_note = stored_notes[1]; store.DeleteNote (deleted_note); Assert.AreEqual (stored_notes.Count - 2, store.GetNotes ().Values.Count); Assert.That (! store.GetNotes ().Values.Contains (deleted_note)); deleted_note = stored_notes[2]; store.DeleteNote (deleted_note); Assert.AreEqual (stored_notes.Count - 3, store.GetNotes ().Values.Count); Assert.That (! store.GetNotes ().Values.Contains (deleted_note)); } }
public DatabaseNoteRepository(string username) { dbConnection = DbConfig.GetConnection (); dbUser = dbConnection.First<DBUser> (u => u.Username == username); storage = new DbStorage (dbUser); engine = new Engine (storage); if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
public DatabaseNoteRepository(string username) { username = username; dbConnection = DbConfig.GetConnection (); storage = new DbStorage (username); engine = new Engine (storage); var db_user = dbConnection.Select <DBUser> ("Username = {0}", username); if (db_user.Count == 0) { dbUser = new DBUser () { Username = username }; } else dbUser = db_user[0]; if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest = new SyncManifest (); dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
public void NoteIsEncryptedIsCorrectlySet() { // test with encrypted notes DbStorage storage = new DbEncryptedStorage (this.connFactory, this.testUser, key); var sample_notes = DbStorageTests.GetSampleNotes (); foreach(var note in sample_notes) { storage.SaveNote (note); } storage.Dispose (); foreach(var note in sample_notes) { // the stored notes should only contain hex chars using (var db = connFactory.OpenDbConnection ()) { var db_note = db.First<DBNote> (n => n.Guid == note.Guid); // this will fail if any non-hex chars are in Assert.IsTrue (db_note.IsEncypted); } } storage = new DbStorage (this.connFactory, this.testUser.Username); sample_notes = DbStorageTests.GetSampleNotes (); foreach(var note in sample_notes) { storage.SaveNote (note); } storage.Dispose (); foreach(var note in sample_notes) { // the stored notes should only contain hex chars using (var db = connFactory.OpenDbConnection ()) { var db_note = db.First<DBNote> (n => n.Guid == note.Guid); // this will fail if any non-hex chars are in Assert.IsFalse (db_note.IsEncypted); } } }