public void SaveErrorLogFileWithObfuscateUserName() { // Prepared data. Constants.UserName = "******"; var pathWithUserName = $"C:\\{Constants.UserName}\\some\\path"; var errorLog = new ManagedErrorLog { Id = Guid.NewGuid(), ProcessId = 123, Exception = new Ingestion.Models.Exception { StackTrace = pathWithUserName } }; var expectedException = new System.Exception(pathWithUserName); // Call method. ErrorLogHelper.SaveErrorLogFiles(expectedException, errorLog); // Verify obfuscated data. var fileExceptionContent = ErrorLogHelper.GetStoredExceptionFile(errorLog.Id).ReadAllText(); var fileErrorContant = ErrorLogHelper.GetStoredErrorLogFile(errorLog.Id).ReadAllText(); Assert.IsFalse(fileErrorContant.Contains(Constants.UserName)); Assert.IsFalse(fileExceptionContent.Contains(Constants.UserName)); }
public void GetStoredExceptionFile() { var id = Guid.NewGuid(); var expectedFile = Mock.Of <File>(); var fileList = new List <File> { expectedFile }; var mockDirectory = Mock.Of <Directory>(); ErrorLogHelper.Instance._crashesDirectory = mockDirectory; Mock.Get(mockDirectory).Setup(d => d.EnumerateFiles($"{id}.exception")).Returns(fileList); // Retrieve the error log by the ID. var exceptionLogFile = ErrorLogHelper.GetStoredExceptionFile(id); // Validate the contents. Assert.AreSame(expectedFile, exceptionLogFile); }