public void jsonStore_Updates_range_of_records_with_string_id() { var InstrumentStore = new JsonStore <InstrumentDocuments>(); var myBatch = new List <InstrumentDocuments>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new InstrumentDocuments { Id = "USA #" + i, Category = "String # " + i, Type = "Guitar" }); } InstrumentStore.Add(myBatch); // Re-load, and update: var companies = InstrumentStore.TryLoadData(); for (int i = 0; i < qtyToAdd; i++) { companies.ElementAt(i).Type = "Banjo " + i; } InstrumentStore.Update(companies); // Reload, and check updated names: companies = InstrumentStore.TryLoadData().Where(c => c.Type.StartsWith("Banjo")).ToList(); Assert.IsTrue(companies.Count == qtyToAdd); }
public RegisterResult RegisterUser(User user, string password) { user.SaltedHash = new SaltedHash(password); var data = GetAllUsers(); if (data.Any(u => u.Name == user.Name)) { return(RegisterResult.UserExists); } if (data.Any(u => u.Email == user.Email)) { return(RegisterResult.EmailExists); } data.Add(user); _database.Update <UserCollection>(data); return(RegisterResult.Success); }
public void jsonStore_Updates_record_with_string_id() { var InstrumentStore = new JsonStore<InstrumentDocuments>(); var newInstrument = new InstrumentDocuments { Id = "USA456", Category = "String", Type = "Guitar" }; InstrumentStore.Add(newInstrument); // Now go fetch the record again and update: string newType = "Banjo"; var foundInstrument = InstrumentStore.TryLoadData().FirstOrDefault(i => i.Id == "USA456"); foundInstrument.Type = newType; InstrumentStore.Update(foundInstrument); Assert.IsTrue(foundInstrument != null && foundInstrument.Type == newType); }
public void jsonStore_Updates_record_with_string_id() { var InstrumentStore = new JsonStore <InstrumentDocuments>(); var newInstrument = new InstrumentDocuments { Id = "USA456", Category = "String", Type = "Guitar" }; InstrumentStore.Add(newInstrument); // Now go fetch the record again and update: string newType = "Banjo"; var foundInstrument = InstrumentStore.TryLoadData().FirstOrDefault(i => i.Id == "USA456"); foundInstrument.Type = newType; InstrumentStore.Update(foundInstrument); Assert.IsTrue(foundInstrument != null && foundInstrument.Type == newType); }
public Task AddLoginAsync(User user, UserLoginInfo login) { if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("user"); } if (!user.Logins.Any(x => x.LoginProvider == login.LoginProvider && x.ProviderKey == login.ProviderKey)) { user.Logins.Add(new UserLoginInfo(login.LoginProvider, login.ProviderKey)); UserDb.Update(user); } return(Task.FromResult(true)); }
public void jsonStore_Updates_range_of_records_with_string_id() { var InstrumentStore = new JsonStore<InstrumentDocuments>(); var myBatch = new List<InstrumentDocuments>(); int qtyToAdd = 10; for (int i = 1; i <= qtyToAdd; i++) { myBatch.Add(new InstrumentDocuments { Id = "USA #" + i, Category = "String # " + i, Type = "Guitar" }); } InstrumentStore.Add(myBatch); // Re-load, and update: var companies = InstrumentStore.TryLoadData(); for (int i = 0; i < qtyToAdd; i++) { companies.ElementAt(i).Type = "Banjo " + i; } InstrumentStore.Update(companies); // Reload, and check updated names: companies = InstrumentStore.TryLoadData().Where(c => c.Type.StartsWith("Banjo")).ToList(); Assert.IsTrue(companies.Count == qtyToAdd); }
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(); }