public async Task BotDataBag_Stream() { var data = MakeBotData(); await data.LoadAsync(default(CancellationToken)); var bag = data.PrivateConversationData; var key = "PrivateConversationData"; Assert.AreEqual(0, bag.Count); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(0, stream.Length); } Assert.AreEqual(1, bag.Count); var blob = Encoding.UTF8.GetBytes(key); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(0, stream.Length); stream.Write(blob, 0, blob.Length); Assert.AreEqual(blob.Length, stream.Length); } Assert.AreEqual(1, bag.Count); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(blob.Length, stream.Length); var read = new byte[blob.Length]; stream.Read(read, 0, blob.Length); CollectionAssert.AreEqual(read, blob); } Assert.AreEqual(1, bag.Count); }
public void BotDataBag_Stream() { var data = MakeBotData(); var bag = data.PerUserInConversationData; var key = "PerUserInConversationData"; Assert.AreEqual(0, bag.Count); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(0, stream.Length); } Assert.AreEqual(1, bag.Count); var blob = Encoding.UTF8.GetBytes(key); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(0, stream.Length); stream.Write(blob, 0, blob.Length); Assert.AreEqual(blob.Length, stream.Length); } Assert.AreEqual(1, bag.Count); using (var stream = new BotDataBagStream(bag, key)) { Assert.AreEqual(blob.Length, stream.Length); var read = new byte[blob.Length]; stream.Read(read, 0, blob.Length); CollectionAssert.AreEqual(read, blob); } Assert.AreEqual(1, bag.Count); }