public async Task MessageCanBeRetrieved() { // Arrange using (var con = OpenConnection()) using (var cache = new SqliteCache(con)) { var message = DummyGenerator.CreateDummyMessage(); message.ID = 111; message.SenderID = 222; message.RecipientID = 333; message.Text = "Hello World"; using (var cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO Messages (Id, Sender, Recipient, Data) VALUES (111,222,333, @json);"; cmd.AddParameter("json", JsonConvert.SerializeObject(message)); cmd.ExecuteNonQuery(); } // Act var list = await cache.GetMessages(); var fromDb = list.FirstOrDefault(); // Assert Assert.IsNotNull(fromDb); Assert.AreEqual(message.SenderID, fromDb.Sender); Assert.AreEqual(message.RecipientID, fromDb.Recipient); Assert.AreEqual(message.ID, fromDb.Id); var msg = JsonConvert.DeserializeObject <DirectMessage>(fromDb.Data); Assert.AreEqual(message.Text, msg.Text); } }
public async Task ClearRemovesAllDataFromCache() { // Arrange using (var con = OpenConnection()) using (var cache = new SqliteCache(con)) { await cache.AddHashtags(new[] { "one", "two", "three" }); await cache.AddMessages(new[] { new MessageCacheEntry(DummyGenerator.CreateDummyMessage()) }); await cache.AddStatuses(new[] { DummyGenerator.CreateDummyStatus() }); var userToCache = DummyGenerator.CreateDummyUserEx(1); userToCache.Name = userToCache.ScreenName = "test"; await cache.AddUsers(new[] { new UserCacheEntry(userToCache) }); // Act await cache.Clear(); // Assert var tags = await cache.GetKnownHashtags(); Assert.AreEqual(0, tags.Count()); var msg = await cache.GetMessages(); Assert.AreEqual(0, msg.Count); var user = await cache.GetUser(1); Assert.IsNull(user); var status = await cache.GetStatus(0); Assert.IsNull(status); } }