Example #1
0
        public void GetCallerInformation()
        {
            // Arrange
            string projectDirectory = Directory.GetParent(Directory.GetCurrentDirectory())?.Parent?.FullName;

            if (string.IsNullOrEmpty(projectDirectory))
            {
                throw new NotImplementedException();
            }
            const int callerLineNumber = 68;
            string    callerFilePath   = projectDirectory + @"\StackTraceTest.cs";
            string    callerMemberName = MethodBase.GetCurrentMethod().Name;
            var       expectedValue    = new Dictionary <string, string>
            {
                {
                    nameof(callerLineNumber), callerLineNumber.ToString()
                },
                {
                    nameof(callerFilePath), callerFilePath
                },
                {
                    nameof(callerMemberName), callerMemberName
                }
            };

            // Act
            Dictionary <string, string> actualValue = StackTraceHelper.GetCallerInformation();

            // Assert
            CollectionAssert.AreEquivalent(expectedValue, actualValue);
        }