public void AddDeleteEntity() { lock (storageLock) { var db = new StorageClient(); Storage.JSONStringToDB("[]"); int id = db.Add <UserModel>(new UserModel() { Name = "test", Pwd = "testpwd" }); int id2 = db.Add <UserModel>(new UserModel() { Name = "test2", Pwd = "testpwd2" }); Assert.Equal(2, db.Get <UserModel>().Count); db.Delete <UserModel>(id); Assert.Equal("test2", db.Get <UserModel>(id2).Name); db.Delete <UserModel>(id2); Assert.Equal(0, db.Get <UserModel>().Count); } }
public void ParallelAddDelete() { lock (storageLock) { var db = new StorageClient(); Storage.JSONStringToDB("[]"); int id = 0; List <UserModel> lst = new List <UserModel>(); for (int i = 0; i < 300; i++) { lst.Add(new UserModel() { Name = "test", Pwd = "testpwd" }); } lst.AsParallel().ForAll(x => { id = db.Add <UserModel>(x); x.Id = id; }); lst.Select(x => new UserModel() { Id = x.Id }).AsParallel().ForAll(x => db.Delete <UserModel>(x.Id)); int cnt = db.Get <UserModel>().Count; Assert.Equal(0, cnt); } }