Esempio n. 1
0
        //[InlineData(@"TestFiles\EmbeddedSourceFile.txt")]
        public void DisplaysSourceCodeLines_ForRelativeEmbeddedPaths(string relativePath)
        {
            // Arrange
            var provider = new EmbeddedFileProvider(
                GetType().GetTypeInfo().Assembly,
                baseNamespace: $"{typeof(ExceptionDetailsProviderTest).GetTypeInfo().Assembly.GetName().Name}.Resources");

            // Act
            var exceptionDetailProvider = new ExceptionDetailsProvider(provider, sourceCodeLineCount: 6);
            var stackFrame = exceptionDetailProvider.GetStackFrameSourceCodeInfo(
                "func1",
                relativePath,
                lineNumber: 10);

            // Assert
            // Lines 4-16 (inclusive) is the code block
            Assert.Equal(4, stackFrame.PreContextLine);
            Assert.Equal(GetCodeLines(4, 9), stackFrame.PreContextCode);
            Assert.Equal(GetCodeLines(10, 10), stackFrame.ContextCode);
            Assert.Equal(GetCodeLines(11, 16), stackFrame.PostContextCode);
        }
Esempio n. 2
0
        public void DisplaysSourceCodeLines_ForRelativePaths(string relativePath)
        {
            // Arrange
            var rootPath = Directory.GetCurrentDirectory();

            using (var provider = new PhysicalFileProvider(rootPath))
            {
                // Act
                var exceptionDetailProvider = new ExceptionDetailsProvider(provider, sourceCodeLineCount: 6);
                var stackFrame = exceptionDetailProvider.GetStackFrameSourceCodeInfo(
                    "func1",
                    relativePath,
                    lineNumber: 10);

                // Assert
                // Lines 4-16 (inclusive) is the code block
                Assert.Equal(4, stackFrame.PreContextLine);
                Assert.Equal(GetCodeLines(4, 9), stackFrame.PreContextCode);
                Assert.Equal(GetCodeLines(10, 10), stackFrame.ContextCode);
                Assert.Equal(GetCodeLines(11, 16), stackFrame.PostContextCode);
            }
        }
        public void DisplaysSourceCodeLines_ForAbsolutePaths(string absoluteFilePath)
        {
            // Arrange
            var rootPath = Directory.GetCurrentDirectory();

            // PhysicalFileProvider handles only relative paths but we fall back to work with absolute paths too
            using (var provider = new PhysicalFileProvider(rootPath))
            {
                // Act
                var exceptionDetailProvider = new ExceptionDetailsProvider(provider, logger: null, sourceCodeLineCount: 6);
                var stackFrame = exceptionDetailProvider.GetStackFrameSourceCodeInfo(
                    "func1",
                    absoluteFilePath,
                    lineNumber: 10);

                // Assert
                // Lines 4-16 (inclusive) is the code block
                Assert.Equal(4, stackFrame.PreContextLine);
                Assert.Equal(GetCodeLines(4, 9), stackFrame.PreContextCode);
                Assert.Equal(GetCodeLines(10, 10), stackFrame.ContextCode);
                Assert.Equal(GetCodeLines(11, 16), stackFrame.PostContextCode);
            }
        }