public void jsonStore_Deletes_range_of_records_with_string_id() { var InstrumentStore = new JsonStore <InstrumentDocuments>(); var myBatch = new List <InstrumentDocuments>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new InstrumentDocuments { Id = "USA #" + i, Category = "String # " + i, Type = "Guitar" }); } InstrumentStore.Add(myBatch); // Re-load from back-end: var companies = InstrumentStore.TryLoadData(); int qtyAdded = companies.Count; // Select 5 for deletion: int qtyToDelete = 5; var deleteThese = new List <InstrumentDocuments>(); for (int i = 0; i < qtyToDelete; i++) { deleteThese.Add(companies.ElementAt(i)); } // Delete: InstrumentStore.Delete(deleteThese); int remaining = InstrumentStore.TryLoadData().Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == qtyAdded - qtyToDelete); }
public void WhenDeletingAnObjectWhichDoesNotExist_ANotFoundExceptionIsThrown() { // Arrange var store = new JsonStore(_rootFileLocation); // Assert Assert.Throws <KeyNotFoundException>(() => { store.Delete(Guid.NewGuid()); }); }
public void AfterDeletingAnObject_TheCorrespondingFileIsDeletedFromDisk() { // Arrange var store = new JsonStore(_rootFileLocation); var id = Guid.NewGuid(); var initialItemToStore = new StorableBase { Id = id, Properties = new Dictionary <string, object> { { "key", "value" } } }; _ = store.Put(initialItemToStore); // Act store.Delete(id); // Assert Assert.Empty(Directory.GetFiles(_rootFileLocation)); }
public void AfterDeletingAnObject_AttemptingToGetItThrowsANotFoundException() { // Arrange var store = new JsonStore(_rootFileLocation); var id = Guid.NewGuid(); var initialItemToStore = new StorableBase { Id = id, Properties = new Dictionary <string, object> { { "key", "value" } } }; _ = store.Put(initialItemToStore); // Act store.Delete(id); // Assert Assert.Throws <KeyNotFoundException>(() => { store.Get(id); }); }
public void jsonStore_Deletes_record_with_string_id() { var InstrumentStore = new JsonStore <InstrumentDocuments>(); var newInstrument = new InstrumentDocuments { Id = "USA789", Category = "String", Type = "Guitar" }; InstrumentStore.Add(newInstrument); // Load from back-end: var companies = InstrumentStore.TryLoadData(); int qtyAdded = companies.Count; // Delete: var foundInstrument = companies.FirstOrDefault(i => i.Id == "USA789"); InstrumentStore.Delete(foundInstrument); int remaining = InstrumentStore.TryLoadData().Count; Assert.IsTrue(qtyAdded == 1 && remaining == 0); }
public static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); var itemStore = new JsonStore<Client>(); sw.Stop(); Console.WriteLine("Initialized new Json store in {0} ms", sw.ElapsedMilliseconds); itemStore.DeleteAll(); int qtyToAdd = 1000; var newItems = new List<Client>(); for (int i = 0; i < qtyToAdd; i++) { newItems.Add(new Client { ClientId = i, FirstName = "First Name " + i, LastName = "Last Name " + i, Email = "sender" + i + "@Example.com" }); } var singleItem = newItems.ElementAt(0); sw.Reset(); sw.Start(); itemStore.Add(singleItem); sw.Stop(); Console.WriteLine("Inserted single item in {0} ms", sw.ElapsedMilliseconds); int savedId = singleItem.ClientId; sw.Reset(); sw.Start(); var savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); singleItem.LastName = "Updated Last"; singleItem.FirstName = "Updated First"; singleItem.Email = "*****@*****.**"; sw.Reset(); sw.Start(); itemStore.Update(singleItem); sw.Stop(); Console.WriteLine("Updated single item in {0} ms", sw.ElapsedMilliseconds); var notReferenceEqualItem = new Client { ClientId = singleItem.ClientId, FirstName = "Copy First", LastName = "Copy Last", Email = "Copy Email" }; sw.Reset(); sw.Start(); itemStore.Update(notReferenceEqualItem); sw.Stop(); Console.WriteLine("Updated copy of single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); sw.Reset(); sw.Start(); itemStore.Delete(singleItem); sw.Stop(); Console.WriteLine("Deleted single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Add(newItems); sw.Stop(); Console.WriteLine("Inserted {0} item in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); foreach (var item in savedItems) { int itemIndex = savedItems.IndexOf(item); item.LastName = string.Format("Updated Last {0}", itemIndex); item.FirstName = string.Format("Updated First {0}", itemIndex); item.Email = string.Format("Updated email {0}", itemIndex); } sw.Reset(); sw.Start(); itemStore.Update(savedItems); sw.Stop(); Console.WriteLine("Updated {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Delete(savedItems); sw.Stop(); Console.WriteLine("Deleted {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); Console.Read(); }
public static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); var itemStore = new JsonStore <Client>(); sw.Stop(); Console.WriteLine("Initialized new Json store in {0} ms", sw.ElapsedMilliseconds); itemStore.DeleteAll(); int qtyToAdd = 1000; var newItems = new List <Client>(); for (int i = 0; i < qtyToAdd; i++) { newItems.Add(new Client { ClientId = i, FirstName = "First Name " + i, LastName = "Last Name " + i, Email = "sender" + i + "@Example.com" }); } var singleItem = newItems.ElementAt(0); sw.Reset(); sw.Start(); itemStore.Add(singleItem); sw.Stop(); Console.WriteLine("Inserted single item in {0} ms", sw.ElapsedMilliseconds); int savedId = singleItem.ClientId; sw.Reset(); sw.Start(); var savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); singleItem.LastName = "Updated Last"; singleItem.FirstName = "Updated First"; singleItem.Email = "*****@*****.**"; sw.Reset(); sw.Start(); itemStore.Update(singleItem); sw.Stop(); Console.WriteLine("Updated single item in {0} ms", sw.ElapsedMilliseconds); var notReferenceEqualItem = new Client { ClientId = singleItem.ClientId, FirstName = "Copy First", LastName = "Copy Last", Email = "Copy Email" }; sw.Reset(); sw.Start(); itemStore.Update(notReferenceEqualItem); sw.Stop(); Console.WriteLine("Updated copy of single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); sw.Reset(); sw.Start(); itemStore.Delete(singleItem); sw.Stop(); Console.WriteLine("Deleted single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Add(newItems); sw.Stop(); Console.WriteLine("Inserted {0} item in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); foreach (var item in savedItems) { int itemIndex = savedItems.IndexOf(item); item.LastName = string.Format("Updated Last {0}", itemIndex); item.FirstName = string.Format("Updated First {0}", itemIndex); item.Email = string.Format("Updated email {0}", itemIndex); } sw.Reset(); sw.Start(); itemStore.Update(savedItems); sw.Stop(); Console.WriteLine("Updated {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Delete(savedItems); sw.Stop(); Console.WriteLine("Deleted {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); Console.Read(); }
public static void Main(string[] args) { var jsonDbDirPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); Console.WriteLine($"JSON Store Dir: {jsonDbDirPath}"); var sw = new Stopwatch(); sw.Start(); var itemStore = new JsonStore <Client>(new JsonDbCore(jsonDbDirPath, "hugo")); sw.Stop(); Console.WriteLine("Initialized new Json store in {0} ms", sw.ElapsedMilliseconds); itemStore.DeleteAll(); var clients = CreateClients(NO_OF_CLIENTS); var singleItem = clients.ElementAt(0); sw.Reset(); sw.Start(); itemStore.Add(singleItem); sw.Stop(); Console.WriteLine("Inserted single item in {0} ms", sw.ElapsedMilliseconds); int savedId = singleItem.ClientId; sw.Reset(); sw.Start(); var savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); singleItem.LastName = "Updated Last"; singleItem.FirstName = "Updated First"; singleItem.Email = "*****@*****.**"; sw.Reset(); sw.Start(); itemStore.Update(singleItem); sw.Stop(); Console.WriteLine("Updated single item in {0} ms", sw.ElapsedMilliseconds); var notReferenceEqualItem = new Client { ClientId = singleItem.ClientId, FirstName = "Copy First", LastName = "Copy Last", Email = "Copy Email" }; sw.Reset(); sw.Start(); itemStore.Update(notReferenceEqualItem); sw.Stop(); Console.WriteLine("Updated copy of single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); singleItem = savedItems.FirstOrDefault(itm => itm.ClientId == savedId); sw.Reset(); sw.Start(); itemStore.Delete(singleItem); sw.Stop(); Console.WriteLine("Deleted single item in {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Add(clients); sw.Stop(); Console.WriteLine("Inserted {0} item in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); foreach (var item in savedItems) { int itemIndex = savedItems.IndexOf(item); item.LastName = string.Format("Updated Last {0}", itemIndex); item.FirstName = string.Format("Updated First {0}", itemIndex); item.Email = string.Format("Updated email {0}", itemIndex); } sw.Reset(); sw.Start(); itemStore.Update(savedItems); sw.Stop(); Console.WriteLine("Updated {0} items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); savedItems = itemStore.TryLoadData(); sw.Stop(); Console.WriteLine("Loaded {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); itemStore.Delete(savedItems); sw.Stop(); Console.WriteLine("Deleted {0} updated items in {1} ms", savedItems.Count, sw.ElapsedMilliseconds); Console.Read(); }
public void jsonStore_Deletes_range_of_records_with_string_id() { var InstrumentStore = new JsonStore<InstrumentDocuments>(); var myBatch = new List<InstrumentDocuments>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new InstrumentDocuments { Id = "USA #" + i, Category = "String # " + i, Type = "Guitar" }); } InstrumentStore.Add(myBatch); // Re-load from back-end: var companies = InstrumentStore.TryLoadData(); int qtyAdded = companies.Count; // Select 5 for deletion: int qtyToDelete = 5; var deleteThese = new List<InstrumentDocuments>(); for (int i = 0; i < qtyToDelete; i++) { deleteThese.Add(companies.ElementAt(i)); } // Delete: InstrumentStore.Delete(deleteThese); int remaining = InstrumentStore.TryLoadData().Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == qtyAdded - qtyToDelete); }
public void jsonStore_Deletes_record_with_string_id() { var InstrumentStore = new JsonStore<InstrumentDocuments>(); var newInstrument = new InstrumentDocuments { Id = "USA789", Category = "String", Type = "Guitar" }; InstrumentStore.Add(newInstrument); // Load from back-end: var companies = InstrumentStore.TryLoadData(); int qtyAdded = companies.Count; // Delete: var foundInstrument = companies.FirstOrDefault(i => i.Id == "USA789"); InstrumentStore.Delete(foundInstrument); int remaining = InstrumentStore.TryLoadData().Count; Assert.IsTrue(qtyAdded == 1 && remaining == 0); }