NArrange.Tests.CSharp.CSharpTestFile.GetTestFileStream C# (CSharp) Method

GetTestFileStream() public static method

Opens a test file resource stream.
public static GetTestFileStream ( string resourceName ) : Stream
resourceName string Name of the resource.
return System.IO.Stream
        public static Stream GetTestFileStream(string resourceName)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream(
                typeof(CSharpTestUtilities), "TestSourceFiles." + resourceName);

            Assert.IsNotNull(stream, "Test stream could not be retrieved.");

            return stream;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Gets the test file contents.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>The test file contents.</returns>
        private static string GetTestFileContents(string fileName)
        {
            string contents = null;

            using (Stream stream = CSharpTestFile.GetTestFileStream(fileName))
            {
                Assert.IsNotNull(stream, "Test stream could not be retrieved.");

                StreamReader reader = new StreamReader(stream);
                contents = reader.ReadToEnd();
            }

            return(contents);
        }