public void MainTest() { AsyncPump.Run( async() => { var writtenBytes = new byte[this.Random.Next(3072, 10241)]; this.Random.NextBytes(writtenBytes); using (var output = new MemoryStream()) { using (var framer = new GlowOutput(1024, 0, (s, e) => output.Write(e.FramedPackage, 0, e.FramedPackageLength))) { framer.WriteBytes(writtenBytes); framer.Finish(); } output.Position = 0; var reader = new S101Reader(output.ReadAsync, 1024); Assert.IsTrue(await reader.ReadAsync(CancellationToken.None)); Assert.IsInstanceOfType(reader.Message.Command, typeof(EmberData)); using (var input = new MemoryStream()) { await reader.Payload.CopyToAsync(input); CollectionAssert.AreEqual(writtenBytes, input.ToArray()); } await reader.DisposeAsync(CancellationToken.None); } }); }
private static Task TestGlowOutput(byte[] block, int blockCount) { using (var output = new GlowOutput(1024, 0, (s, e) => { })) { for (int index = 0; index < blockCount; ++index) { output.WriteBytes(block); } output.Finish(); } return(Task.FromResult(false)); }