public void VCardTest() { storage.RemoveUser(username); var vcard1 = new Vcard { Fullname = username }; storage.SetVCard(username, vcard1); var vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); var u = new XmppUser(username, "password"); storage.SaveUser(u); vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); storage.SetVCard(username, vcard1); vcard2 = storage.GetVCard(username); Assert.AreEqual(vcard1.ToString(), vcard2.ToString()); vcard2 = storage.GetVCard("sss"); Assert.IsNull(vcard2); storage.SetVCard(username, null); vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); storage.RemoveUser(username); }
public void UserTest() { storage.RemoveUser(username); var u1 = new XmppUser(username, "password"); storage.SaveUser(u1); var u2 = storage.GetUser(username); Assert.AreEqual(u1.Name, u2.Name); Assert.AreEqual(u1.Password, u2.Password); u1 = new XmppUser(username, "password2"); storage.SaveUser(u1); u2 = storage.GetUser(username); Assert.AreEqual(u1.Name, u2.Name); Assert.AreEqual(u1.Password, u2.Password); u2 = storage.GetUser("sss"); Assert.IsNull(u2); storage.RemoveUser(username); u2 = storage.GetUser(username); Assert.IsNull(u2); }
public void SaveUser(XmppUser user) { Args.NotNull(user, "user"); Args.Requires <ArgumentException>(!string.IsNullOrEmpty(user.Name), "User name can not be empty."); Args.Requires <ArgumentException>(!string.IsNullOrEmpty(user.Password), "User password can not be empty."); using (var db = GetDb()) using (var tx = db.BeginTransaction()) { var exists = 0 < db.ExecScalar <int>(new SqlQuery("jabber_user").SelectCount().Where("username", user.Name)); var q = exists ? (ISqlInstruction) new SqlUpdate("jabber_user").Set("userpass", user.Password).Where("username", user.Name) : (ISqlInstruction) new SqlInsert("jabber_user").InColumnValue("username", user.Name).InColumnValue("userpass", user.Password); db.ExecuteNonQuery(q); tx.Commit(); } }