public void SaveNonce(DbNonce nonce) { using (var db = new LiteDatabase(DbName)) { db.GetCollection <DbNonce>().Upsert(nonce); } }
public void RemoveNonce(DbNonce nonce) { using (var db = new LiteDatabase(DbName)) { db.GetCollection <DbNonce>().Delete(nonce.Id); } }
public string GenerateNonce() { var nonce = new DbNonce { Nonce = Guid.NewGuid().ToString(), }; _repo.SaveNonce(nonce); return(nonce.Nonce); }
public void SaveAndFindNonce() { var nonceVal = Guid.NewGuid().ToString(); var emptyNonceVal = Guid.Empty.ToString(); var dbNonce = new DbNonce { Nonce = nonceVal, }; Assert.AreEqual(0, dbNonce.Id); _repo.SaveNonce(dbNonce); Assert.AreEqual(1, dbNonce.Id); // Get Nonce by DB ID var getNonce = _repo.GetNonce(dbNonce.Id); Assert.IsNotNull(getNonce, "existing nonce by DB ID"); Assert.AreEqual(dbNonce.Id, getNonce.Id); Assert.AreEqual(dbNonce.Nonce, getNonce.Nonce); getNonce = _repo.GetNonce(int.MaxValue); Assert.IsNull(getNonce, "non-existent nonce by DB ID"); // Get Nonce by Value getNonce = _repo.GetNonceByValue(emptyNonceVal); Assert.IsNull(getNonce, "non-existent nonce by value"); getNonce = _repo.GetNonceByValue(nonceVal); Assert.IsNotNull(getNonce, "existing nonce by value"); // Remove _repo.RemoveNonce(getNonce); getNonce = _repo.GetNonce(dbNonce.Id); Assert.IsNull(getNonce, "existing nonce after remove by DB ID"); getNonce = _repo.GetNonceByValue(nonceVal); Assert.IsNull(getNonce, "existing nonce after remove by value"); }