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); } }
public async Task MessageCanBeAdded() { // Arrange using (var con = OpenConnection()) using (var cache = new SqliteCache(con)) { var message = DummyGenerator.CreateDummyMessage(); message.SenderID = 111; message.RecipientID = 222; message.ID = 333; message.Text = "Hello World"; var entry = new MessageCacheEntry(message); // Act await cache.AddMessages(new[] { entry }); // Assert using (var cmd = con.CreateCommand()) { cmd.CommandText = "SELECT Id, Sender, Recipient, Data FROM Messages;"; using (var reader = cmd.ExecuteReader()) { Assert.IsTrue(reader.Read()); Assert.AreEqual(333, reader.GetInt32(0)); Assert.AreEqual(111, reader.GetInt32(1)); Assert.AreEqual(222, reader.GetInt32(2)); var json = reader.GetString(3); var from = JsonConvert.DeserializeObject <DirectMessage>(json); Assert.AreEqual(message.Text, from.Text); } } } }