public void TestGetById() { Storage storage = new Storage(); storage.AddModel <User>(); Utils.FillUsers(storage, 20); User user1 = User.GetById(storage, 11); User user2 = User.GetById(storage, 15); User user3 = User.GetById(storage, 19); User user4 = User.GetById(storage, user1.Id); Assert.AreEqual(user1.name, "Person 11"); Assert.AreEqual(user2.name, "Person 15"); Assert.AreEqual(user3.name, "Person 19"); Assert.AreEqual(user4.name, "Person 11"); User unsavedUser = new User(storage) { name = "Jake" }; Utils.IsThrows(() => User.GetById(storage, unsavedUser.Id), "Getting invalid id must throw"); }
public void TestGetUnexistingId() { SQLiteStorage storage = new SQLiteStorage(inMemory: true); storage.AddModel <User>(); Utils.IsThrows(() => User.GetById(storage, 10), "Getting from empty storage must throw"); User user = new User(storage); user.Save(); Utils.IsNotThrows(() => User.GetById(storage, 0), "Getting valid id must not throw"); user.Remove(); Utils.IsThrows(() => User.GetById(storage, 0), "Getting removed id must throw"); }
public void TestRemove() { SQLiteStorage storage = new SQLiteStorage(inMemory: true); storage.AddModel <User>(); Utils.FillUsers(storage, 20); User[] users = User.GetAll(storage); Assert.AreEqual(users.Length, 20); users[5].Remove(); users[10].Remove(); users[15].Remove(); users = User.GetAll(storage); Assert.AreEqual(users.Length, 17); Utils.IsThrows(() => User.GetById(storage, 10), "Getting removed id must throw"); Utils.IsNotThrows(() => User.GetById(storage, 11), "Getting existing id must not throw"); }