public void Biggylist_Updates_Single_Item_In_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var newProperty = new Property { Id = 1, Name = "John's Luxury Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; propertyList.Add(newProperty); int addedItemId = newProperty.Id; // Just to be sure, reload from backing store and check what was added: propertyList = new BiggyList<Property>(_propertyStore); var addedProperty = propertyList.FirstOrDefault(p => p.Id == addedItemId); bool isAddedProperly = addedProperty.Name.Contains("John's Luxury"); // Now Update: string newName = "John's Low-Rent Apartments"; addedProperty.Name = newName; propertyList.Update(addedProperty); // Go fetch again: propertyList = new BiggyList<Property>(_propertyStore); addedProperty = propertyList.FirstOrDefault(p => p.Id == addedItemId); bool isUpdatedProperly = addedProperty.Name == newName; Assert.IsTrue(isAddedProperly && isUpdatedProperly); }
public void Updates_Item_With_OVerride_From_List_And_Store() { // Just in case: var overriddenClients = new BiggyList <Client>(new SQLServerStore <Client>(_hostDb)); overriddenClients.Clear(); // Add a new record: var newClient = new Client() { LastName = "Atten", FirstName = "John", Email = "*****@*****.**" }; overriddenClients.Add(newClient); int newId = newClient.ClientId; // Update the same record-by-id with a new instance. OverrideClient overrides Equals with the id: var updateMe = new Client() { ClientId = newId, LastName = "Appleseed", FirstName = "John", Email = "*****@*****.**" }; overriddenClients.Update(updateMe); // Open a new instance, to see if the item was added to the backing store as well: var altClientList = new BiggyList <Client>(new SQLServerStore <Client>(_connectionStringName)); var updated = altClientList.FirstOrDefault(c => c.LastName == "Appleseed"); Assert.True(updated != null && updated.LastName == "Appleseed"); }
public void Biggylist_Updates_Single_Item_In_Pg_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var newPropertyDocument = new PropertyDocument { Name = "John's Luxury Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; PropertyDocumentList.Add(newPropertyDocument); int addedItemId = newPropertyDocument.Id; // Just to be sure, reload from backing store and check what was added: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); var addedPropertyDocument = PropertyDocumentList.FirstOrDefault(p => p.Id == addedItemId); bool isAddedProperly = addedPropertyDocument.Name.Contains("John's Luxury"); // Now Update: string newName = "John's Low-Rent Apartments"; addedPropertyDocument.Name = newName; PropertyDocumentList.Update(addedPropertyDocument); // Go fetch again: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); addedPropertyDocument = PropertyDocumentList.FirstOrDefault(p => p.Id == addedItemId); bool isUpdatedProperly = addedPropertyDocument.Name == newName; Assert.IsTrue(isAddedProperly && isUpdatedProperly); }
public OrderBase AddOrder(OrderBase newItem) { ///// int newId = (orders.Count > 0) ? newId = orders.Max(id => id.Id) + 1 : 1; // Ensure that the new item's association property is value var associatedObject = producers.SingleOrDefault(i => i.Id == newItem.Id); if (associatedObject == null) { return(null); } var addedItem = new ProduceOrderModel { Id = newId, Produce = associatedObject }; addedItem.Price = newItem.Price; addedItem.Quantity += 1; orders.Add(addedItem); return(Mapper.Map <OrderBase>(addedItem)); }
public void Biggylist_Removes_Single_Item_From_Pg_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var newPropertyDocument = new PropertyDocument { Name = "John's High-End Apartments", Address = "16 PropertyDocument Parkway, Portland, OR 97204" }; PropertyDocumentList.Add(newPropertyDocument); int addedItemId = newPropertyDocument.Id; // Just to be sure, reload from backing store and check what was added: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); var addedPropertyDocument = PropertyDocumentList.FirstOrDefault(p => p.Id == addedItemId); bool isAddedProperly = addedPropertyDocument.Name.Contains("High-End"); int qtyAdded = PropertyDocumentList.Count; // Delete: var foundPropertyDocument = PropertyDocumentList.FirstOrDefault(); PropertyDocumentList.Remove(foundPropertyDocument); PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int remaining = PropertyDocumentList.Count; Assert.IsTrue(isAddedProperly && qtyAdded == 1 && remaining == 0); }
public void Biggylist_Removes_All_Items_From_Pg_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List <PropertyDocument>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "Marvin Gardens " + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Re-load from back-end: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int qtyAdded = PropertyDocumentList.Count; PropertyDocumentList.Clear(); // Delete: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int remaining = PropertyDocumentList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == 0); }
public void Biggylist_Removes_Range_Of_Items_From_Pg_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List <PropertyDocument>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "Boardwalk " + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Re-load from back-end: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int qtyAdded = PropertyDocumentList.Count; // Select 5 for deletion: int qtyToDelete = 5; var deleteThese = PropertyDocumentList.Where(c => c.Id <= qtyToDelete); PropertyDocumentList.Remove(deleteThese); // Delete: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int remaining = PropertyDocumentList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == qtyAdded - qtyToDelete); }
public void Biggylist_Updates_Range_Of_Items_In_Pg_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List <PropertyDocument>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "John's Luxury Townhomes" + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Just to be sure, reload from backing store and check what was added: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int addedCount = PropertyDocumentList.Count; // Update each item: for (int i = 0; i < qtyToAdd; i++) { PropertyDocumentList.ElementAt(i).Name = "John's Low-Rent Brick Homes " + i; } PropertyDocumentList.Update(PropertyDocumentList.ToList()); // Reload, and check updated names: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); var updatedItems = PropertyDocumentList.Where(p => p.Name.Contains("Low-Rent Brick")); Assert.IsTrue(updatedItems.Count() == qtyToAdd); }
public DownloadRecord InitDownload(DownloadRecord downloadRecord) { lock (JsonStore) { var dRecords = new BiggyList <DownloadRecord>(JsonStore); var dr = dRecords.FirstOrDefault(a => a.Url == downloadRecord.Url); if (dr == null) { if (downloadRecord.DownloadItem == null) { downloadRecord.DownloadItem = new DownloadItem() { IsComplete = false }; } dRecords.Add(downloadRecord); dr = downloadRecord; } else { dr.IsCancelled = downloadRecord.IsCancelled; } dr.Hash = GetHashString(downloadRecord.Url); var finalFolder = EnsurePath(dr.Hash); var fullPath = Path.Combine(finalFolder, dr.FileName); dr.FullPath = fullPath; dRecords.Update(dr); return(dr); } }
void RunBenchmarks() { Console.WriteLine("Writing 1000 records sync"); var sw = new Stopwatch(); var products = new BiggyList<Product>(); //1000 writes? for (int i = 0; i < 1000; i++) { var p = new Product { Sku = "SKU" + i, Name = "Steve", Price = 12.00M }; products.Add(p); } sw.Start(); products.Save(); sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("Resetting..."); products.ClearAndSave(); Console.WriteLine("Writing 1000 records async"); //1000 writes? for (int i = 0; i < 1000; i++) { var p = new Product { Sku = "SKUDDY" + i, Name = "Steve", Price = 12.00M }; products.Add(p); } sw.Start(); products.SaveAsync(); sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); sw.Reset(); //1000 writes? Console.WriteLine("Writing 1000 records with write happening in a loop"); sw.Start(); for (int i = 0; i < 1000; i++) { var p = new Product { Sku = "SKU" + i, Name = "Steve", Price = 12.00M }; products.Add(p); //bad idea... run it and see why products.Save(); } sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("Reading from records"); sw.Start(); var p2 = products.Where(x => x.Sku == "SKU22").FirstOrDefault(); Console.WriteLine(p2.Sku); sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); Console.Read(); }
public static void Run() { Console.WriteLine("Loading from File Store..."); var clients = new BiggyList<Client>(new JsonStore<Client>("clients")); clients.Clear(); var sw = new Stopwatch(); // Write a modest-sized batch to a file: int SMALL_BATCH_QTY = 1000; Console.WriteLine("Write {0} documents", SMALL_BATCH_QTY); var addRange = new List<Client>(); for (int i = 0; i < SMALL_BATCH_QTY; i++) { addRange.Add(new Client() { ClientId = i, LastName = string.Format("Atten {0}", i.ToString()), FirstName = "John", Email = "*****@*****.**" }); } sw.Start(); clients.Add(addRange); sw.Stop(); Console.WriteLine("Just inserted {0} as documents in {1} ms", clients.Count(), sw.ElapsedMilliseconds); int LARGE_BATCH_QTY = 100000; Console.WriteLine("Write {0} documents", LARGE_BATCH_QTY); sw.Reset(); clients.Clear(); // Write a Bigger-sized batch to a file: // Reset the temp List; addRange = new List<Client>(); for (int i = 0; i < LARGE_BATCH_QTY; i++) { addRange.Add(new Client() { ClientId = i, LastName = string.Format("Atten {0}", i.ToString()), FirstName = "John", Email = "*****@*****.**" }); } sw.Start(); clients.Add(addRange); sw.Stop(); Console.WriteLine("Just inserted {0} as documents in {1} ms", clients.Count(), sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); Console.WriteLine("Querying Middle 400 Documents"); var found = clients.Where(x => x.ClientId > 100 && x.ClientId < 500); sw.Stop(); Console.WriteLine("Queried {0} documents in {1}ms", found.Count(), sw.ElapsedMilliseconds); }
public Reads() { var list1 = new BiggyList<Product>(); test1 = new Product { Sku = "XXX", Name = "Steve's Stuffs", Price = 100.00M }; list1.Add(test1); list1.Save(); //this should read from the file _products = new BiggyList<Product>(); }
public void WontDuplicate() { _products.ClearAndSave(); _products.Add(test1); Assert.True(_products.Count == 1); //Product has Equals set to compare SKU var test2 = new Product { Sku = "XXX", Name = "Other Kine Stuffs", Price = 100.00M }; _products.Add(test2); Assert.True(_products.Count == 1); //now be sure it's the updated product Assert.True(_products.First().Name == "Other Kine Stuffs"); }
public void UpdateAlbums() { for (int i = 0; i < AlbumList.Count; i++) { var store = new BiggyList<Settings>(settingStore); Settings setting = new Settings(); setting.AlbumName = AlbumList[i]; store.Add(setting); } }
public static void Run() { Console.WriteLine("Loading from File Store..."); var monkies = new BiggyList<Monkey>(); monkies.Clear(); var sw = new Stopwatch(); Console.WriteLine("Loading 10,000 documents"); sw.Start(); var addRange = new List<Monkey>(); for (int i = 0; i < 10000; i++) { monkies.Add(new Monkey {ID = i, Name = "MONKEY " + i, Birthday = DateTime.Today, Description = "The Monkey on my back" }); } sw.Stop(); Console.WriteLine("Just inserted {0} as documents in {1} ms", monkies.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Loading 100,000 documents"); sw.Reset(); monkies.Clear(); sw.Start(); for (int i = 0; i < 100000; i++) { monkies.Add(new Monkey { ID = i, Name = "MONKEY " + i, Birthday = DateTime.Today, Description = "The Monkey on my back" }); } sw.Stop(); Console.WriteLine("Just inserted {0} as documents in {1} ms", monkies.Count, sw.ElapsedMilliseconds); //use a DB that has an int PK sw.Reset(); sw.Start(); Console.WriteLine("Loading {0}...", monkies.Count); monkies.Reload(); sw.Stop(); Console.WriteLine("Loaded {0} documents from Postgres in {1}ms", monkies.Count, sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); Console.WriteLine("Querying Middle 100 Documents"); var found = monkies.Where(x => x.ID > 100 && x.ID < 500); sw.Stop(); Console.WriteLine("Queried {0} documents in {1}ms", found.Count(), sw.ElapsedMilliseconds); }
public IHttpActionResult ArchiveLogs([FromUri] string password) { if (password != "ArchiveLogs") //just to make { return(Unauthorized()); } foreach (var item in Log) { ArchiveLogList.Add(item); } foreach (var item in BlogLogs) { ArchiveLogList.Add(item); } Log.Clear(); BlogLogs.Clear(); return(Ok()); }
public async Task <JsonResult <Status> > Update(string name) { var status = Status.Ok; try { Bitmap image; using (var requestStream = await Request.Content.ReadAsStreamAsync()) image = new Bitmap(requestStream); var page = _pages.SingleOrDefault(x => x.Name == name); if (page == null) { _pages.Add(new PageModel { Name = name, OriginalImagePath = _imageStore.Save(image, name + "." + Environment.OriginalId) }); } else if (!page.HumanComparisonRequired) { page.ComparisonImagePath = _imageStore.Save(image, name + "." + Environment.ComparisonId); await Task.Run(() => page.GenerateComparison()); _pages.Update(page); } else { status = Status.HumanComparisonRequired; } } catch (Exception exception) { status = new Status { Message = !exception.Message.IsNullOrEmpty() ? exception.Message : exception.InnerException.Message }; } return(Json(status)); }
public void Biggylist_Adds_Single_Item_To_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var newProperty = new Property { Id = 1, Name = "Watergate Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; propertyList.Add(newProperty); // Reload from the store: propertyList = new BiggyList<Property>(_propertyStore); var addedItems = propertyList.FirstOrDefault(p => p.Name.Contains("Watergate")); Assert.IsTrue(initialCount == 0 && propertyList.Count == 1); }
public Reads() { var list1 = new BiggyList <Product>(); test1 = new Product { Sku = "XXX", Name = "Steve's Stuffs", Price = 100.00M }; list1.Add(test1); list1.Save(); //this should read from the file _products = new BiggyList <Product>(); }
public void Biggylist_Adds_Single_Item_To_Sqlite_Store() { var PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var newPropertyDocument = new PropertyDocument { Name = "Watergate Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; PropertyDocumentList.Add(newPropertyDocument); // Reload from the store: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); var addedItems = PropertyDocumentList.FirstOrDefault(p => p.Name.Contains("Watergate")); Assert.IsTrue(initialCount == 0 && PropertyDocumentList.Count == 1 && addedItems.Id == 1); }
public Writes() { //clear out the list _products = new BiggyList<Product>(); //empty the db _products.ClearAndSave(); test1 = new Product { Sku = "XXX", Name = "Steve's Stuffs", Price = 100.00M }; _products.Saved += _products_Saved; _products.ItemAdded += _products_ItemAdded; _products.Add(test1); _products.Save(); }
public SurveyFull AddSurvey(SurveyAdd newItem) { // Calculate the next value for the identifier int newId = (surveys.Count > 0) ? newId = surveys.Max(id => id.Id) + 1 : 1; Survey addedItem = Mapper.Map <Survey>(newItem); addedItem.Id = newId; // Add the new item to the store surveys.Add(addedItem); // Return the new item return(Mapper.Map <SurveyFull>(addedItem)); }
//adding method public SurveyFull AddSurvey(SurveyAdd newItem) { //New id int newId = (surveys.Count > 0) ? newId = surveys.Max(id => id.Id) + 1 : 1; //new item w/ Mapper Survey addedItem; addedItem = Mapper.Map <Survey>(newItem); addedItem.Id = newId; //Add new item surveys.Add(addedItem); //return value return(Mapper.Map <SurveyFull>(addedItem)); }
public Writes() { //clear out the list _products = new BiggyList <Product>(); //empty the db _products.ClearAndSave(); test1 = new Product { Sku = "XXX", Name = "Steve's Stuffs", Price = 100.00M }; _products.Saved += _products_Saved; _products.ItemAdded += _products_ItemAdded; _products.Add(test1); _products.Save(); }
public ProduceBase AddProduce(ProduceAdd newItem) { int newId = (producers.Count > 0) ? newId = producers.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Produce { Id = newId, Name = newItem.Name, Location = newItem.Location, Price = newItem.Price }; producers.Add(addedItem); return(Mapper.Map <ProduceBase>(addedItem)); }
public void Biggylist_Adds_Single_Item_To_Sqlite_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var newPropertyDocument = new PropertyDocument { Name = "Watergate Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; PropertyDocumentList.Add(newPropertyDocument); // Reload from the store: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); var addedItems = PropertyDocumentList.FirstOrDefault(p => p.Name.Contains("Watergate")); Assert.IsTrue(initialCount == 0 && PropertyDocumentList.Count == 1 && addedItems.Id == 1); }
public void Biggylist_Adds_Range_Of_Items_To_Pg_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List<Property>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { var newProperty = new Property { Name = "New Apartment " + i, Address = "Some Street in a Lonely Town" }; myBatch.Add(newProperty); } propertyList.Add(myBatch); // Reload from the store: propertyList = new BiggyList<Property>(_propertyStore); var addedItems = propertyList.FirstOrDefault(p => p.Name.Contains("New Apartment")); Assert.IsTrue(initialCount == 0 && propertyList.Count == qtyToAdd); }
public void Biggylist_Adds_Range_Of_Items_To_Sqlite_Store() { var PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List<PropertyDocument>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { var newPropertyDocument = new PropertyDocument { Name = "New Apartment " + i, Address = "Some Street in a Lonely Town" }; myBatch.Add(newPropertyDocument); } PropertyDocumentList.Add(myBatch); // Reload from the store: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); var addedItems = PropertyDocumentList.Where(p => p.Id > 0); Assert.IsTrue(initialCount == 0 && addedItems.Count() > 0); }
public void Biggylist_Adds_Single_Item_To_Json_Store() { var propertyList = new BiggyList <Property>(_propertyStore); int initialCount = propertyList.Count; var newProperty = new Property { Id = 1, Name = "Watergate Apartments", Address = "2639 I St NW, Washington, D.C. 20037" }; propertyList.Add(newProperty); // Reload from the store: propertyList = new BiggyList <Property>(_propertyStore); var addedItems = propertyList.FirstOrDefault(p => p.Name.Contains("Watergate")); Assert.IsTrue(initialCount == 0 && propertyList.Count == 1); }
public void UpdateCheckpoint(string checkpointToken) { var tenantCheckpoint = _tenantCheckpoints.SingleOrDefault(x => x.TenantId == _tenantId); if (tenantCheckpoint != null) { tenantCheckpoint.CheckpointToken = checkpointToken; _tenantCheckpoints.Update(tenantCheckpoint); } else { _tenantCheckpoints.Add(new TenantCheckpointTokenDocument { TenantId = _tenantId, CheckpointToken = checkpointToken }); } }
public void Biggylist_Adds_Range_Of_Items_To_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List<Property>(); int qtyToAdd = 10; // This test uses an initial index value of 1 so taht there is a non-zero ID for the first item: for (int i = 1; i <= qtyToAdd; i++) { var newProperty = new Property { Id = i, Name = "New Apartment " + i, Address = "Some Street in a Lonely Town" }; myBatch.Add(newProperty); } propertyList.Add(myBatch); // Reload from the store: propertyList = new BiggyList<Property>(_propertyStore); var addedItems = propertyList.FirstOrDefault(p => p.Name.Contains("New Apartment")); Assert.IsTrue(initialCount == 0 && propertyList.Count == qtyToAdd); }
// Add a new person public PersonFull AddPerson(PersonAdd newItem) { // Calculate the next value for the identifier int newId = (persons.Count > 0) ? newId = persons.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new PersonFull { Id = newId, FirstName = newItem.FirstName, LastName = newItem.LastName, Age = newItem.Age }; // Add the new item to the store persons.Add(addedItem); // Return the new item return(addedItem); }
//adding method public CarFull AddCar(CarAdd newItem) { //New id int newId = (cars.Count > 0) ? newId = cars.Max(id => id.Id) + 1 : 1; //new item var addedItem = new CarFull { Id = newId, Manufacturer = newItem.Manufacturer, Model = newItem.Model, MSRP = newItem.MSRP, Year = newItem.Year }; //Add new item cars.Add(addedItem); //return value return(addedItem); }
public VehicleBase AddVehicle(VehicleAdd newItem) { // Calculate the next value for the identifier int newId = (vehicles.Count > 0) ? newId = vehicles.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Vehicle { Id = newId, Model = newItem.Model, Trim = newItem.Trim, ModelYear = newItem.ModelYear, MSRP = newItem.MSRP }; // Add the new item to the store vehicles.Add(addedItem); // Return the new item return(Mapper.Map <VehicleBase>(addedItem)); }
//Add Serie public Serie AddSerie(string serie, out bool isAddResult) { Serie newSerie = new Serie(); int exist = _serieList.Count(c => c.SerieName == serie); if (exist < 1) { newSerie.SerieId = Guid.NewGuid().ToString(); newSerie.SerieName = serie; newSerie.SerieSeasson = 1; newSerie.SerieEpisode = 1; _serieList.Add(newSerie); isAddResult = true; } else { isAddResult = false; } return(newSerie); }
public VehicleBase AddVehicle(VehicleAdd newItem) { // Calculate the next value for the identifier int newId = (vehicles.Count > 0) ? newId = vehicles.Max(id => id.Id) + 1 : 1; // Ensure that the new item's association property is value var associatedObject = manufacturers.SingleOrDefault(i => i.Id == newItem.ManufacturerId); if (associatedObject == null) { // Uh oh... return(null); } // Create a new item; notice the property mapping var addedItem = new Vehicle { Id = newId, Model = newItem.Model, Trim = newItem.Trim, ModelYear = newItem.ModelYear, MSRP = newItem.MSRP, // New... Manufacturer = associatedObject }; // Alternative... use AutoMapper to do the job... //addedItem = Mapper.Map<Vehicle>(newItem); //addedItem.Id = newId; //addedItem.Manufacturer = associatedObject; // Add the new item to the store vehicles.Add(addedItem); // Return the new item return(Mapper.Map <VehicleBase>(addedItem)); }
//static void WhatWhat() { // var sw = new Stopwatch(); // sw.Start(); // var products = new MassiveList<NWProduct>(connectionStringName: "northwind", tableName: "products", primaryKeyName: "productid"); // sw.Stop(); // Console.WriteLine("Read " + products.Count + " into memory in " + sw.ElapsedMilliseconds + "ms"); // foreach (var p in products) { // Console.WriteLine(p.Sku); // } // sw.Reset(); // sw.Start(); // var readOne = products.FirstOrDefault(x => x.ProductName == "Product24"); // Console.WriteLine(readOne.ProductName); // sw.Stop(); // Console.WriteLine("Read single in " + sw.ElapsedMilliseconds + "ms"); // sw.Reset(); // sw.Start(); // var details = new MassiveList<OrderDetail>(connectionStringName: "northwind", tableName: "orderdetails", primaryKeyName: "orderdetailid"); // sw.Stop(); // Console.WriteLine("Read " + details.Count + " into memory in " + sw.ElapsedMilliseconds + "ms"); // Console.Read(); //} static void RunBenchmarks() { Console.WriteLine("Writing 1000 records sync"); var products = new BiggyList <Product>(); products.Clear(); //File.Delete(products.DbPath); //products.Reload(); //1000 writes? var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000; i++) { var p = new Product { Sku = "SKU" + i, Name = "Steve", Price = 12.00M }; products.Add(p); } sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("Reading from records"); sw.Start(); var p2 = products.Where(x => x.Sku == "SKU22").FirstOrDefault(); Console.WriteLine(p2.Sku); sw.Stop(); Console.WriteLine("{0}ms", sw.ElapsedMilliseconds); Console.Read(); }
public ManufacturerBase AddManufacturer(ManufacturerAdd newItem) { // Calculate the next value for the identifier int newId = (manufacturers.Count > 0) ? newId = manufacturers.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Manufacturer { Id = newId, Name = newItem.Name, Country = newItem.Country, YearStarted = newItem.YearStarted }; // Alternative... use AutoMapper to do the job... addedItem = Mapper.Map <Manufacturer>(newItem); addedItem.Id = newId; // Add the new item to the store manufacturers.Add(addedItem); // Return the new item return(Mapper.Map <ManufacturerBase>(addedItem)); }
public void Biggylist_Adds_Range_Of_Items_To_Sqlite_Store() { var PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List <PropertyDocument>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { var newPropertyDocument = new PropertyDocument { Name = "New Apartment " + i, Address = "Some Street in a Lonely Town" }; myBatch.Add(newPropertyDocument); } PropertyDocumentList.Add(myBatch); // Reload from the store: PropertyDocumentList = new BiggyList <PropertyDocument>(_PropertyDocumentStore); var addedItems = PropertyDocumentList.Where(p => p.Id > 0); Assert.IsTrue(initialCount == 0 && addedItems.Count() > 0); }
public void Biggylist_Adds_Range_Of_Items_To_SQLite_Store() { var propertyList = new BiggyList <Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List <Property>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { var newProperty = new Property { Name = "New Apartment " + i, Address = "Some Street in a Lonely Town" }; myBatch.Add(newProperty); } propertyList.Add(myBatch); // Reload from the store: propertyList = new BiggyList <Property>(_propertyStore); var addedItems = propertyList.FirstOrDefault(p => p.Name.Contains("New Apartment")); Assert.IsTrue(initialCount == 0 && propertyList.Count == qtyToAdd); }
public void Updates_Item_In_List_And_Store_With_Equals_Override() { var overrideWidgetList = new BiggyList <OverrideWidget>(new JsonStore <OverrideWidget>()); overrideWidgetList.Clear(); overrideWidgetList.Add(new OverrideWidget { SKU = "001", Name = "Test widget 1", Price = 2.00M }); var updatedItem = new OverrideWidget { SKU = "001", Name = "UPDATED", Price = 2.00M }; overrideWidgetList.Update(updatedItem); // Reload the list: overrideWidgetList = new BiggyList <OverrideWidget>(new JsonStore <OverrideWidget>()); // Grab from the list: var updatedInList = overrideWidgetList.FirstOrDefault(w => w.Name == "UPDATED"); // Make sure updated in both: Assert.True(updatedInList.Name == "UPDATED"); }
public static void Run() { var sw = new Stopwatch(); var _myDatabase = new PGCache("chinookPG"); Console.WriteLine("==========================================================="); Console.WriteLine("POSTGRES DOCUMENTS - INSERT A BUNCH OF DOCUMENTS"); Console.WriteLine("==========================================================="); // Build a table to play with from scratch each time: if(_myDatabase.TableExists("ClientDocuments")) { _myDatabase.DropTable("\"ClientDocuments\""); } IBiggyStore<ClientDocument> clientDocStore = new PGDocumentStore<ClientDocument>(_myDatabase); IBiggy<ClientDocument> clientDocs = new BiggyList<ClientDocument>(clientDocStore); int INSERT_MODEST_QTY = 10000; Console.WriteLine("Insert {0} records as documents...", INSERT_MODEST_QTY); var addThese = new List<ClientDocument>(); for(int i = 0; i < INSERT_MODEST_QTY; i++) { addThese.Add(new ClientDocument { LastName = "Atten", FirstName = "John", Email = "*****@*****.**" }); } sw.Start(); clientDocs.Add(addThese); sw.Stop(); Console.WriteLine("Inserted {0} records as documents in {1} ms", INSERT_MODEST_QTY, sw.ElapsedMilliseconds); Console.WriteLine("==========================================================="); Console.WriteLine("POSTGRES DOCUMENTS - SOME FANCY COMPLEX DOCUMENT STUFF"); Console.WriteLine("==========================================================="); // Start clean with no existing table: if (_myDatabase.TableExists("ArtistWithAlbums")) { _myDatabase.DropTable("\"ArtistWithAlbums\""); } Console.WriteLine("Retreive artists, albums, and tracks from Db..."); sw.Reset(); sw.Start(); IBiggyStore<Artist> _artistStore = new PGStore<Artist>(_myDatabase); IBiggyStore<Album> _albumStore = new PGStore<Album>(_myDatabase); IBiggyStore<Track> _trackStore = new PGStore<Track>(_myDatabase); IBiggy<Artist> _artists = new BiggyList<Artist>(_artistStore); IBiggy<Album> _albums = new BiggyList<Album>(_albumStore); IBiggy<Track> _tracks = new BiggyList<Track>(_trackStore); sw.Stop(); Console.WriteLine("Query each artists albums and write to complex document store..."); var list = new List<ArtistWithAlbums>(); foreach (var artist in _artists) { var artistAlbums = from a in _albums where a.ArtistId == artist.ArtistId select a; var newArtistWithAlbums = new ArtistWithAlbums() { ArtistId = artist.ArtistId, Name = artist.Name, Albums = artistAlbums.ToList() }; list.Add(newArtistWithAlbums); } var docStore = new PGDocumentStore<ArtistWithAlbums>(_myDatabase); var artistWithAlbumsDocuments = new BiggyList<ArtistWithAlbums>(docStore); artistWithAlbumsDocuments.Add(list); sw.Stop(); Console.WriteLine("Added {0} Artist + Album records as complex documents in {1} ms", _artists.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Retreive artists and albums from Complex document store and hydrate"); sw.Reset(); sw.Start(); artistWithAlbumsDocuments = new BiggyList<ArtistWithAlbums>(docStore); sw.Stop(); int artistCount = artistWithAlbumsDocuments.Count(); int albumsCount = 0; foreach (var artist in artistWithAlbumsDocuments) { albumsCount += artist.Albums.Count(); } Console.WriteLine("\tRetreived and Re-Hydrated {0} Artist + {1} Album records from complex documents in {2} ms", artistCount, albumsCount, sw.ElapsedMilliseconds); }
//public Storage(string[] Albumname) //{ // settingStore = new JsonStore<Settings>(dbPath: HttpRuntime.AppDomainAppPath); // albumStore = new JsonStore<Albums>(dbPath: HttpRuntime.AppDomainAppPath); // AlbumList.AddRange(Albumname); //} void Refresh() { var store = new BiggyList<Albums>(albumStore); List<Albums> albumContent = new List<Albums>(); var drive = new GoogleDrive(); if (AlbumList.Count > 0) { for (int i = 0; i < AlbumList.Count; i++) { string AlbumId = drive.GetFolderID(AlbumList[i]); var contents = drive.ListFolderContent(AlbumId); foreach (var image in contents) { Albums album = new Albums(); album.Id = image.Id; album.Title = image.Title; album.AlbumName = AlbumList[i]; album.ThumbnailLink = image.ThumbnailLink; album.DownloadURL = image.DownloadUrl; albumContent.Add(album); } } store.Add(albumContent); } }
public static void Run() { var sw = new Stopwatch(); Console.WriteLine("==========================================================="); Console.WriteLine("Postgres - SOME FANCY QUERYING"); Console.WriteLine("==========================================================="); var _db = new PGCache(_connectionStringName); IBiggy<Artist> _artists; IBiggy<Album> _albums; IBiggy<Track> _tracks; Console.WriteLine("Loading up Artists from Chinook..."); sw.Start(); _artists = new BiggyList<Artist>(new PGStore<Artist>(_db)); sw.Stop(); Console.WriteLine("\tLoaded {0} Artist records in {1} ms", _artists.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Loading up Albums from Chinook..."); sw.Reset(); sw.Start(); _albums = new BiggyList<Album>(new PGStore<Album>(_db)); sw.Stop(); Console.WriteLine("\tLoaded {0} Albums in {1} ms", _artists.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Loading up tracks from Chinook..."); sw.Reset(); sw.Start(); _tracks = new BiggyList<Track>(new PGStore<Track>(_db)); sw.Stop(); Console.WriteLine("\tLoaded {0} Tracks in {1} ms", _tracks.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Grab the record for AC/DC..."); sw.Reset(); sw.Start(); var acdc = _artists.FirstOrDefault(a => a.Name == "AC/DC"); sw.Stop(); Console.WriteLine("\tFound AC/DC from memory in {0} ms", sw.ElapsedMilliseconds); Console.WriteLine("Find all the albums by AC/DC ..."); sw.Reset(); sw.Start(); var acdcAlbums = _albums.Where(a => a.ArtistId == acdc.ArtistId); sw.Stop(); Console.WriteLine("\tFound All {0} AC/DC albums from memory in {1} ms", acdcAlbums.Count(), sw.ElapsedMilliseconds); Console.WriteLine("Find all the Tracks from Albums by AC/DC ..."); sw.Reset(); sw.Start(); var acdcTracks = from t in _tracks join a in acdcAlbums on t.AlbumId equals a.AlbumId select t; sw.Stop(); Console.WriteLine("\tFound All {0} tracks by ACDC using in-memory JOIN in {1} ms:", acdcTracks.Count(), sw.ElapsedMilliseconds); foreach (var track in acdcTracks) { Console.WriteLine("\t-{0}", track.Name); } Console.WriteLine(Environment.NewLine); Console.WriteLine("==========================================================="); Console.WriteLine("POSTGES - BASIC CRUD OPERATIONS"); Console.WriteLine("==========================================================="); IBiggy<Customer> _customers; sw.Reset(); Console.WriteLine("Loading up customers from Chinook..."); sw.Start(); _customers = new BiggyList<Customer>(new PGStore<Customer>(_db)); sw.Stop(); Console.WriteLine("\tLoaded {0} records in {1}ms", _customers.Count(), sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("INSERTING a NEW Customer into Chinook..."); var newCustomer = new Customer() { LastName = "Atten", FirstName = "John", Email = "*****@*****.**" }; sw.Start(); _customers.Add(newCustomer); sw.Stop(); Console.WriteLine("\tWrote 1 record for a new count of {0} records in {1} ms", _customers.Count(), sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("UPDATING the new Customer record in Chinook..."); newCustomer.FirstName = "Fred"; sw.Start(); _customers.Update(newCustomer); sw.Stop(); Console.WriteLine("\tUpdated 1 record for a new count of {0} records in {1} ms", _customers.Count(), sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("DELETE the new Customer record in Chinook..."); sw.Start(); _customers.Remove(newCustomer); sw.Stop(); Console.WriteLine("\tDeleted 1 record for a new count of {0} records in {1} ms", _customers.Count(), sw.ElapsedMilliseconds); Console.WriteLine(Environment.NewLine); Console.WriteLine("==========================================================="); Console.WriteLine("POSTGES - BULK INSERTS AND DELETIONS"); Console.WriteLine("==========================================================="); Console.WriteLine("Creating Test Table..."); if(_db.TableExists("client")) { _db.DropTable("client"); } var columnDefs = new List<string>(); columnDefs.Add("client_id serial PRIMARY KEY NOT NULL"); columnDefs.Add("last_name Text NOT NULL"); columnDefs.Add("first_name Text NOT NULL"); columnDefs.Add("email Text NOT NULL"); _db.CreateTable("client", columnDefs); IBiggy<Client> _clients; sw.Reset(); int INSERT_QTY = 10000; Console.WriteLine("BULK INSERTING {0} client records in Chinook...", INSERT_QTY); _clients = new BiggyList<Client>(new PGStore<Client>(_db)); var inserts = new List<Client>(); for (int i = 0; i < INSERT_QTY; i++) { inserts.Add(new Client() { LastName = string.Format("Atten {0}", i.ToString()), FirstName = "John", Email = "*****@*****.**" }); } sw.Start(); var inserted = _clients.Add(inserts); sw.Stop(); Console.WriteLine("\tInserted {0} records in {1} ms", inserted.Count(), sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("Loading up Bulk inserted CLients from Chinook..."); sw.Start(); _clients = new BiggyList<Client>(new PGStore<Client>(_db)); sw.Stop(); Console.WriteLine("\tLoaded {0} records in {1}ms", _clients.Count(), sw.ElapsedMilliseconds); sw.Reset(); Console.WriteLine("DELETING added records from Chinook..."); var toRemove = _clients.Where(x => x.Email == "*****@*****.**"); sw.Start(); var removed = _clients.Remove(toRemove.ToList()); sw.Stop(); Console.WriteLine("\tDeleted {0} records in {1}ms", removed.Count(), sw.ElapsedMilliseconds); }
public static void Run() { var sw = new Stopwatch(); var _myDatabase = new SQLServerCache("chinook"); Console.WriteLine("==========================================================="); Console.WriteLine("SQL SERVER DOCUMENTS - INSERT A BUNCH OF DOCUMENTS"); Console.WriteLine("==========================================================="); // Build a table to play with from scratch each time: if(_myDatabase.TableExists("ClientDocuments")) { _myDatabase.DropTable("ClientDocuments"); } IBiggyStore<ClientDocument> clientDocStore = new SQLDocumentStore<ClientDocument>("chinook"); IBiggy<ClientDocument> clientDocs = new BiggyList<ClientDocument>(clientDocStore); int INSERT_MODEST_QTY = 10000; Console.WriteLine("Insert {0} records as documents...", INSERT_MODEST_QTY); var addThese = new List<ClientDocument>(); for(int i = 0; i < INSERT_MODEST_QTY; i++) { addThese.Add(new ClientDocument { LastName = "Atten", FirstName = "John", Email = "*****@*****.**" }); } sw.Start(); clientDocs.Add(addThese); sw.Stop(); Console.WriteLine("Inserted {0} records as documents in {1} ms", INSERT_MODEST_QTY, sw.ElapsedMilliseconds); Console.WriteLine("==========================================================="); Console.WriteLine("SQL SERVER DOCUMENTS - SOME FANCY COMPLEX DOCUMENT STUFF"); Console.WriteLine("==========================================================="); // Start clean with no existing table: var temp = new SQLServerCache("chinook"); if (temp.TableExists("ArtistWithAlbums")) { temp.DropTable("ArtistWithAlbums"); } Console.WriteLine("Retreive artists, albums, and tracks from Db..."); sw.Reset(); sw.Start(); IBiggyStore<Artist> _artistStore = new SQLServerStore<Artist>(_myDatabase); IBiggyStore<Album> _albumStore = new SQLServerStore<Album>(_myDatabase); IBiggyStore<Track> _trackStore = new SQLServerStore<Track>(_myDatabase); IBiggy<Artist> _artists = new BiggyList<Artist>(_artistStore); IBiggy<Album> _albums = new BiggyList<Album>(_albumStore); IBiggy<Track> _tracks = new BiggyList<Track>(_trackStore); sw.Stop(); Console.WriteLine("Query each artists albums and write to complex document store..."); var list = new List<ArtistWithAlbums>(); foreach (var artist in _artists) { var artistAlbums = from a in _albums where a.ArtistId == artist.ArtistId select a; var newArtistWithAlbums = new ArtistWithAlbums() { ArtistId = artist.ArtistId, Name = artist.Name, Albums = artistAlbums.ToList() }; list.Add(newArtistWithAlbums); } var docStore = new SQLDocumentStore<ArtistWithAlbums>(_myDatabase); var artistWithAlbumsDocuments = new BiggyList<ArtistWithAlbums>(docStore); artistWithAlbumsDocuments.Add(list); sw.Stop(); Console.WriteLine("Added {0} Artist + Album records as complex documents in {1} ms", _artists.Count(), sw.ElapsedMilliseconds); //Console.WriteLine("Retreive artists and albums from Complex document store and hydrate"); //// Re-hydrate the store, just to be sure: //_myDatabase = new SQLServerHost("chinook"); //sw.Reset(); //sw.Start(); //artistWithAlbumsDocuments = new BiggyList<ArtistWithAlbums>(docStore); //foreach (var artist in artistWithAlbumsDocuments) { // Console.WriteLine("\t{0}", artist.Name); // var albumNames = from a in artist.Albums select a.Title; // foreach (string name in albumNames) { // string useName = name; // if (name.Length > 10) { // useName = name.Remove(10, name.Length - 10); // } // Console.WriteLine("\t\t{0} ...", useName); // } //} //sw.Stop(); //Console.WriteLine("\tRetreived and Re-Hydrated/wrote to console {0} Artist + Album records from complex documents in {1} ms", _artists.Count(), sw.ElapsedMilliseconds); }
public void Updates_Item_With_OVerride_From_List_And_Store() { // Just in case: var overriddenClients = new BiggyList<Client>(new SQLServerStore<Client>(_hostDb)); overriddenClients.Clear(); // Add a new record: var newClient = new Client() { LastName = "Atten", FirstName = "John", Email = "*****@*****.**" }; overriddenClients.Add(newClient); int newId = newClient.ClientId; // Update the same record-by-id with a new instance. OverrideClient overrides Equals with the id: var updateMe = new Client() { ClientId = newId, LastName = "Appleseed", FirstName = "John", Email = "*****@*****.**" }; overriddenClients.Update(updateMe); // Open a new instance, to see if the item was added to the backing store as well: var altClientList = new BiggyList<Client>(new SQLServerStore<Client>(_connectionStringName)); var updated = altClientList.FirstOrDefault(c => c.LastName == "Appleseed"); Assert.True(updated != null && updated.LastName == "Appleseed"); }
public IHttpActionResult Post(ErrorLogItem value) { value.Date = DateTime.Now.ToString(); errors.Add(value); return(Ok()); }
public void Updates_Item_In_List_And_Store_With_Equals_Override() { var overrideWidgetList = new BiggyList<OverrideWidget>(new JsonStore<OverrideWidget>()); overrideWidgetList.Clear(); overrideWidgetList.Add(new OverrideWidget { SKU = "001", Name = "Test widget 1", Price = 2.00M }); var updatedItem = new OverrideWidget { SKU = "001", Name = "UPDATED", Price = 2.00M }; overrideWidgetList.Update(updatedItem); // Reload the list: overrideWidgetList = new BiggyList<OverrideWidget>(new JsonStore<OverrideWidget>()); // Grab from the list: var updatedInList = overrideWidgetList.FirstOrDefault(w => w.Name == "UPDATED"); // Make sure updated in both: Assert.True(updatedInList.Name == "UPDATED"); }
public void Biggylist_Updates_Range_Of_Items_In_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List<Property>(); int qtyToAdd = 10; // This test uses an initial index value of 1 so taht there is a non-zero ID for the first item: for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new Property { Id = i, Name = "John's Luxury Townhomes" + i, Address = i + " Property Parkway, Portland, OR 97204" }); } propertyList.Add(myBatch); // Just to be sure, reload from backing store and check what was added: propertyList = new BiggyList<Property>(_propertyStore); int addedCount = propertyList.Count; // Update each item: for (int i = 0; i < qtyToAdd; i++) { propertyList.ElementAt(i).Name = "John's Low-Rent Brick Homes " + i; } propertyList.Update(propertyList.ToList()); // Reload, and check updated names: propertyList = new BiggyList<Property>(_propertyStore); var updatedItems = propertyList.Where(p => p.Name.Contains("Low-Rent Brick")); Assert.IsTrue(updatedItems.Count() == qtyToAdd); }
public void Biggylist_Removes_All_Items_From_Sqlite_Store() { var PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List<PropertyDocument>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "Marvin Gardens " + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Re-load from back-end: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int qtyAdded = PropertyDocumentList.Count; PropertyDocumentList.Clear(); // Delete: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int remaining = PropertyDocumentList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == 0); }
public void Biggylist_Removes_Range_Of_Items_From_Sqlite_Store() { var PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List<PropertyDocument>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "Boardwalk " + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Re-load from back-end: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int qtyAdded = PropertyDocumentList.Count; // Select 5 for deletion: int qtyToDelete = 5; var deleteThese = PropertyDocumentList.Where(c => c.Id <= qtyToDelete); PropertyDocumentList.Remove(deleteThese); // Delete: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int remaining = PropertyDocumentList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == qtyAdded - qtyToDelete); }
public void Biggylist_Removes_All_Items_From_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List<Property>(); int qtyToAdd = 10; for (int i = 0; i < qtyToAdd; i++) { myBatch.Add(new Property { Id = i, Name = "Marvin Gardens " + i, Address = i + " Property Parkway, Portland, OR 97204" }); } propertyList.Add(myBatch); // Re-load from back-end: propertyList = new BiggyList<Property>(_propertyStore); int qtyAdded = propertyList.Count; propertyList.Clear(); // Delete: propertyList = new BiggyList<Property>(_propertyStore); int remaining = propertyList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == 0); }
public void Biggylist_Removes_Range_Of_Items_From_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var myBatch = new List<Property>(); int qtyToAdd = 10; // This test uses an initial index value of 1 so taht there is a non-zero ID for the first item: for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new Property { Id = i, Name = "Boardwalk " + i, Address = i + " Property Parkway, Portland, OR 97204" }); } propertyList.Add(myBatch); // Re-load from back-end: propertyList = new BiggyList<Property>(_propertyStore); int qtyAdded = propertyList.Count; // Select 5 for deletion: int qtyToDelete = 5; var deleteThese = propertyList.Where(c => c.Id <= qtyToDelete); propertyList.Remove(deleteThese); // Delete: propertyList = new BiggyList<Property>(_propertyStore); int remaining = propertyList.Count; Assert.IsTrue(qtyAdded == qtyToAdd && remaining == qtyAdded - qtyToDelete); }
public void Biggylist_Removes_Single_Item_From_Json_Store() { var propertyList = new BiggyList<Property>(_propertyStore); int initialCount = propertyList.Count; var newProperty = new Property { Id = 1, Name = "John's High-End Apartments", Address = "16 Property Parkway, Portland, OR 97204" }; propertyList.Add(newProperty); int addedItemId = newProperty.Id; // Just to be sure, reload from backing store and check what was added: propertyList = new BiggyList<Property>(_propertyStore); var addedProperty = propertyList.FirstOrDefault(p => p.Id == addedItemId); bool isAddedProperly = addedProperty.Name.Contains("High-End"); int qtyAdded = propertyList.Count; // Delete: var foundProperty = propertyList.FirstOrDefault(); propertyList.Remove(foundProperty); propertyList = new BiggyList<Property>(_propertyStore); int remaining = propertyList.Count; Assert.IsTrue(isAddedProperly && qtyAdded == 1 && remaining == 0); }
public void Biggylist_Updates_Range_Of_Items_In_Sqlite_Store() { var PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int initialCount = PropertyDocumentList.Count; var myBatch = new List<PropertyDocument>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new PropertyDocument { Name = "John's Luxury Townhomes" + i, Address = i + " PropertyDocument Parkway, Portland, OR 97204" }); } PropertyDocumentList.Add(myBatch); // Just to be sure, reload from backing store and check what was added: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); int addedCount = PropertyDocumentList.Count; // Update each item: for (int i = 0; i < qtyToAdd; i++) { PropertyDocumentList.ElementAt(i).Name = "John's Low-Rent Brick Homes " + i; } PropertyDocumentList.Update(PropertyDocumentList.ToList()); // Reload, and check updated names: PropertyDocumentList = new BiggyList<PropertyDocument>(_PropertyDocumentStore); var updatedItems = PropertyDocumentList.Where(p => p.Name.Contains("Low-Rent Brick")); Assert.IsTrue(updatedItems.Count() == qtyToAdd); }
public void Initializes_Memory_Only_List_With_True_Argument() { _biggyMemoryList = new BiggyList<Widget>(inMemory: true); var BiggyJsonList = new BiggyList<Widget>(); _biggyMemoryList.Clear(); BiggyJsonList.Clear(); var batch = new List<Widget>(); for (int i = 0; i < INSERT_QTY; i++) { batch.Add(new Widget { SKU = string.Format("00{0}", i), Name = string.Format("Test widget {0}", i), Price = i }); } _biggyMemoryList.Add(batch); BiggyJsonList.Add(batch); int memoryCount = _biggyMemoryList.Count(); _biggyMemoryList.Clear(); BiggyJsonList = new BiggyList<Widget>(); Assert.True(memoryCount == INSERT_QTY && _biggyMemoryList.Count() == 0 && BiggyJsonList.Count() == INSERT_QTY); }