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 GetSingleErrorLogFileDoesNotThrow(Type exceptionType) { // Use reflection to create an exception of the given C# type. var exception = exceptionType.GetConstructor(Type.EmptyTypes).Invoke(null) as System.Exception; var mockDirectory = Mock.Of <Directory>(); ErrorLogHelper.Instance._crashesDirectory = mockDirectory; Mock.Get(mockDirectory).Setup(d => d.EnumerateFiles(It.IsAny <string>())).Throws(exception); // Retrieve the error log by the ID. var errorLogFile = ErrorLogHelper.GetStoredErrorLogFile(Guid.NewGuid()); Assert.IsNull(errorLogFile); }
public void GetSingleErrorLogFile() { 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}.json")).Returns(fileList); // Retrieve the error log by the ID. var errorLogFile = ErrorLogHelper.GetStoredErrorLogFile(id); // Validate the contents. Assert.AreSame(expectedFile, errorLogFile); }