WriteUtf8StringToStream() public static method

Writes the UTF8 string to a stream.
/// is null. /// or /// is null. ///
public static WriteUtf8StringToStream ( string value, Stream stream ) : void
value string The value to write to the stream.
stream Stream The stream to write to.
return void
Esempio n. 1
0
        public void WriteUtf8StringToStream_NullValue_ThrowsException()
        {
            var ex = Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                using (var ms = new MemoryStream())
                {
                    await StreamUtility.WriteUtf8StringToStream(null, ms);
                }
            });

            Assert.That(ex.ParamName.Equals("value", StringComparison.Ordinal));
        }
Esempio n. 2
0
        public async Task WriteUtfStringToStream_ValidString_WritesToStream()
        {
            var tempFolder = CreateTempFolder();
            var file       = Path.GetRandomFileName();
            var path       = Path.Combine(tempFolder, file);

            try
            {
                using (var stream = File.OpenWrite(path))
                {
                    await StreamUtility.WriteUtf8StringToStream("HelloWorld", stream);
                }

                var fi = new FileInfo(path);
                Assert.AreEqual(13, fi.Length);
            }
            finally
            {
                if (Directory.Exists(tempFolder))
                {
                    DeleteTempFolder(tempFolder);
                }
            }
        }
Esempio n. 3
0
        public void WriteUtf8StringToStream_NullStream_ThrowsException()
        {
            var ex = Assert.ThrowsAsync <ArgumentNullException>(async() => await StreamUtility.WriteUtf8StringToStream("ABCD", null));

            Assert.That(ex.ParamName.Equals("stream", StringComparison.Ordinal));
        }