Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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 Task AddToRoleAsync(User user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException("role");
            }

            var roles = RoleDb.TryLoadData();
            var role  = roles.Where(f => f.Name == roleName).SingleOrDefault();

            if (role == null)
            {
                throw new KeyNotFoundException("role");
            }

            if (role != null && user.Roles != null && !user.Roles.Contains(roleName, StringComparer.InvariantCultureIgnoreCase))
            {
                user.Roles.Add(roleName);
            }

            return(Task.FromResult(0));
        }
        public Task <User> FindAsync(UserLoginInfo login)
        {
            string loginId = GetLoginId(login);
            var    user    = UserDb.TryLoadData().Where(f => f.Id == int.Parse(loginId)).SingleOrDefault();

            return(Task.FromResult(user));
        }
Esempio n. 5
0
    public void jsonStore_Inserts_record_with_string_id() {
      var InstrumentStore = new JsonStore<InstrumentDocuments>();
      var newInstrument = new InstrumentDocuments { Id = "USA123", Category = "String", Type = "Guitar" };
      InstrumentStore.Add(newInstrument);

      var foundInstrument = InstrumentStore.TryLoadData().FirstOrDefault(i => i.Id == "USA123");
      Assert.IsTrue(foundInstrument != null && foundInstrument.Id == "USA123");
    }
Esempio n. 6
0
    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);
    }
Esempio n. 7
0
 public void jsonStore_Inserts_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);
   var companies = InstrumentStore.TryLoadData();
   Assert.IsTrue(companies.Count == qtyToAdd);
 }
Esempio n. 8
0
    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);
    }
Esempio n. 9
0
        public void jsonStore_Inserts_record_with_string_id()
        {
            var InstrumentStore = new JsonStore <InstrumentDocuments>();
            var newInstrument   = new InstrumentDocuments {
                Id = "USA123", Category = "String", Type = "Guitar"
            };

            InstrumentStore.Add(newInstrument);

            var foundInstrument = InstrumentStore.TryLoadData().FirstOrDefault(i => i.Id == "USA123");

            Assert.IsTrue(foundInstrument != null && foundInstrument.Id == "USA123");
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void jsonStore_Deletes_all_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;

            // Delete:
            InstrumentStore.DeleteAll();
            int remaining = InstrumentStore.TryLoadData().Count;

            Assert.IsTrue(qtyAdded == qtyToAdd && remaining == 0);
        }
Esempio n. 12
0
        public void jsonStore_Inserts_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);
            var companies = InstrumentStore.TryLoadData();

            Assert.IsTrue(companies.Count == qtyToAdd);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
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();
    }
Esempio n. 15
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();
        }
Esempio n. 16
0
        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();
        }
Esempio n. 17
0
    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);
    }
Esempio n. 18
0
    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);
    }
Esempio n. 19
0
    public void jsonStore_Deletes_all_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;

      // Delete:
      InstrumentStore.DeleteAll();
      int remaining = InstrumentStore.TryLoadData().Count;
      Assert.IsTrue(qtyAdded == qtyToAdd && remaining == 0);
    }