public void PutObjectWithIdUpdatesObjectAndDoesntCrashIndex() { string dbName = "PutOrEditWithIndex"; var expected = new Sword() { Name = "Excalibur", Cost = 1 }; using (var client = new InnerDbClient(dbName)) { int id = client.PutObject(masamune); Assert.IsNotNull(client.GetObject <Sword>(id)); client.AddIndex <Sword>("Name"); client.PutObject(expected, id); var actual = client.GetObject <Sword>(id); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); } using (var client = new InnerDbClient(dbName)) { var actual = client.GetObject <Sword>(s => s.Name == "Excalibur"); Assert.AreEqual(expected, actual); } }
public void DatabaseZipsAndUnzipsOnStartupAndShutdownRespectively() { string dbName = "ZipMe"; string archiveName = "ZipMe.innerdb"; using (var c = new InnerDbClient(dbName)) { c.PutObject(masamune); c.PutObject(lavos); } // Closed DB has a zip Assert.IsFalse(Directory.Exists(dbName)); Assert.IsTrue(File.Exists(archiveName)); using (var c = new InnerDbClient(dbName)) { // Active DB has a dir Assert.IsTrue(Directory.Exists(dbName)); Assert.IsFalse(File.Exists(archiveName)); } Assert.IsFalse(Directory.Exists(dbName)); Assert.IsTrue(File.Exists(archiveName)); }
public void PutObjectReturnsNonZeroId() { using (var client = new InnerDbClient("Empty")) { var actual = client.PutObject(masamune); Assert.Greater(actual, 0); } }
public void GetCollectionReturnsEmptyListIfNoItemsExist() { using (var client = new InnerDbClient("Empty")) { var actual = client.GetCollection <Sword>(); Assert.IsNotNull(actual); Assert.AreEqual(0, actual.Count); } }
public void GetByPredicateReturnsPutObject() { using (var client = new InnerDbClient("GetByPredicate")) { client.PutObject(masamune); client.PutObject(murasame); var actual = client.GetObject <Sword>(s => s.Name == "Masamune"); Assert.AreEqual(masamune, actual); } }
public void GetByIdReturnsPutObject() { using (var client = new InnerDbClient("GetAndPut")) { var id = client.PutObject(masamune); Assert.Greater(id, 0); var actual = client.GetObject <Sword>(id); Assert.AreEqual(masamune, actual); } }
public void EnumsDeserializeCorrectly() { using (var client = new InnerDbClient("EnumSerialization")) { var expected = new Creature("Dove", Alignment.Good); int id = client.PutObject(expected); var actual = client.GetObject <Creature>(c => c.Name == "Dove"); Assert.AreEqual(Alignment.Good, actual.Disposition); } }
public void IdsAreNotReusedAfterDeletion() { using (var client = new InnerDbClient("IdReuse")) { int first = client.PutObject(masamune); int second = client.PutObject(murasame); client.Delete(second); int third = client.PutObject(lavos); Assert.AreNotEqual(second, third); } }
public void DeleteDeletesObject() { using (var client = new InnerDbClient("Delete")) { int swordId = client.PutObject(masamune); Assert.IsNotNull(client.GetObject <Sword>(swordId)); Assert.IsNotNull(client.GetObject <Sword>(s => s.Name == "Masamune")); client.Delete(swordId); Assert.IsNull(client.GetObject <Sword>(swordId)); } }
public void PutObjectIncrementsIdRegardlessOfType() { using (var client = new InnerDbClient("AutoIncrementId")) { int first = client.PutObject(murasame); Assert.AreEqual(1, first); int second = client.PutObject(lavos); Assert.AreEqual(2, second); int third = client.PutObject(murasame); Assert.AreEqual(3, third); } }
public void GetCollectionReturnsPutObjects() { using (var client = new InnerDbClient("GetCollection")) { var actual = client.GetCollection <Sword>(); client.PutObject(masamune); client.PutObject(murasame); client.PutObject(lavos); actual = client.GetCollection <Sword>(); Assert.AreEqual(2, actual.Count); Assert.AreEqual(masamune, actual.ElementAt(0)); Assert.AreEqual(murasame, actual.ElementAt(1)); } }
public void JournalWritesJournalFilesAndRunsThemOnStartup() { string dbName = "JournalingAndRecovery"; string journalDir = string.Format(@"{0}\Journal", dbName); string dataDir = string.Format(@"{0}\Data", dbName); int id, secondId = 0; using (var client = new InnerDbClient(dbName)) { // Believe me when I say this is very heavily tested already from // the above tests running really fast. client.SetJournalIntervalMilliseconds(10000); id = client.PutObject(murasame); client.Delete(id); secondId = client.PutObject(masamune); // White-box of sorts. Okay for now. string[] files = System.IO.Directory.GetFiles(journalDir); Assert.AreEqual(3, files.Length); Assert.IsTrue(files.Any(f => f.Contains(id + "-Put.json"))); Assert.IsTrue(files.Any(f => f.Contains(id + "-Delete.json"))); Assert.IsTrue(files.Any(f => f.Contains(secondId + "-Put.json"))); } using (var client = new InnerDbClient(dbName)) { string[] data = new string[1]; // Wait for victory. bool isDone = false; var start = DateTime.Now; while (!isDone && ((DateTime.Now - start).TotalSeconds <= 5)) { var files = System.IO.Directory.GetFiles(journalDir); data = System.IO.Directory.GetFiles(dataDir); isDone = (files.Length == 0 && dataDir.Length == 1 && data.First().Contains("2.json")); } Assert.IsNull(client.GetObject <Sword>(id)); Assert.AreEqual(masamune, client.GetObject <Sword>(secondId)); } }
public void DataPersistsAcrossClients() { string dbName = "FileStorePersists"; int swordId, creatureId = 0; using (var client = new InnerDbClient(dbName)) { swordId = client.PutObject(murasame); creatureId = client.PutObject(lavos); } using (var client = new InnerDbClient(dbName)) { var actualSword = client.GetObject <Sword>(swordId); Assert.AreEqual(murasame, actualSword); var actualCreature = client.GetObject <Creature>(creatureId); Assert.AreEqual(lavos, actualCreature); } }