Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge fix/method_detection into develop #46

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/MethodTimeLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using Catel.Logging;
using System.Reflection;
using System;
using System.Globalization;

Expand Down Expand Up @@ -32,8 +31,5 @@ public static void Log(Type type, string methodName, long milliseconds, string m
{
finalMessage += $" | {message}";
}

var logger = LogManager.GetLogger(type);
logger.Debug(finalMessage);
}
}
}
4 changes: 2 additions & 2 deletions src/Orc.Monitoring.Benchmarks/ReportOutputBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public void Setup()

_csvReportOutput = new CsvReportOutput(loggerFactory, _reportOutputHelper,
(outputDirectory) => new MethodOverrideManager(outputDirectory, loggerFactory, _fileSystem, csvUtils),
_fileSystem, reportArchiver);
_fileSystem, reportArchiver, csvUtils);
_csvReportOutput.SetParameters(CsvReportOutput.CreateParameters(_testOutputPath, "CsvTest"));

_ranttOutput = new RanttOutput(loggerFactory,
() => new EnhancedDataPostProcessor(loggerFactory),
_reportOutputHelper,
(outputDirectory) => new MethodOverrideManager(outputDirectory, loggerFactory, _fileSystem, csvUtils),
_fileSystem, reportArchiver, new ReportItemFactory(loggerFactory));
_fileSystem, reportArchiver, new ReportItemFactory(loggerFactory), csvUtils);
_ranttOutput.SetParameters(RanttOutput.CreateParameters(_testOutputPath));

_txtReportOutput = new TxtReportOutput(loggerFactory, _reportOutputHelper, reportArchiver, _fileSystem);
Expand Down
2 changes: 1 addition & 1 deletion src/Orc.Monitoring.Tests/CsvReportOutputLimitableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Setup()

_csvReportOutput = new CsvReportOutput(_loggerFactory, reportOutputHelper,
(outputDirectory) => new MethodOverrideManager(outputDirectory, _loggerFactory, _fileSystem, _csvUtils),
_fileSystem, _reportArchiver);
_fileSystem, _reportArchiver, _csvUtils);
var parameters = CsvReportOutput.CreateParameters(_testOutputPath, TestConstants.DefaultReportName);
_csvReportOutput.SetParameters(parameters);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Orc.Monitoring.Tests/CsvReportOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Setup()
var reportOutputHelper = new ReportOutputHelper(_loggerFactory, new ReportItemFactory(_loggerFactory));
_csvReportOutput = new CsvReportOutput(_loggerFactory, reportOutputHelper,
(outputDirectory) => new MethodOverrideManager(outputDirectory, _loggerFactory, _fileSystem, _csvUtils),
_fileSystem, _reportArchiver);
_fileSystem, _reportArchiver, _csvUtils);
_mockReporter = new Mock<IMethodCallReporter>();
_mockReporter.Setup(r => r.FullName).Returns("TestReporter");

Expand Down Expand Up @@ -208,16 +208,15 @@ public async Task Dispose_WhenFileIsLocked_HandlesGracefully()
}

[Test]
[Ignore("This test is not working as expected. We are not using StreamWriter directly in the code, so we cannot test this scenario.")]
public async Task WriteItem_WhenDiskIsFull_HandlesGracefully()
{
var mockFileSystem = new Mock<IFileSystem>();
mockFileSystem.Setup(fs => fs.CreateStreamWriter(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<Encoding>()))
.Throws(new IOException("Disk full"));

var csvUtils = TestHelperMethods.CreateCsvUtils(mockFileSystem.Object, _loggerFactory);

var csvReportOutput = new CsvReportOutput(_loggerFactory, new ReportOutputHelper(_loggerFactory, new ReportItemFactory(_loggerFactory)),
(outputDirectory) => new MethodOverrideManager(outputDirectory, _loggerFactory, mockFileSystem.Object, csvUtils), mockFileSystem.Object, _reportArchiver);
(outputDirectory) => new MethodOverrideManager(outputDirectory, _loggerFactory, mockFileSystem.Object, _csvUtils), mockFileSystem.Object, _reportArchiver, _csvUtils);

var parameters = CsvReportOutput.CreateParameters(_testFolderPath, _testFileName);
csvReportOutput.SetParameters(parameters);
Expand Down
24 changes: 12 additions & 12 deletions src/Orc.Monitoring.Tests/CsvReportWriterAdditionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Orc.Monitoring.Tests;
[TestFixture]
public class CsvReportWriterAdditionalTests
{
private StringWriter _stringWriter;
private string _fileName;
private MethodOverrideManager _overrideManager;
private List<ReportItem> _reportItems;
private TestLogger<CsvReportWriterAdditionalTests> _logger;
Expand All @@ -31,16 +31,16 @@ public void Setup()
_fileSystem = new InMemoryFileSystem(_loggerFactory);
_csvUtils = TestHelperMethods.CreateCsvUtils(_fileSystem, _loggerFactory);

_stringWriter = new StringWriter();
_overrideManager = new MethodOverrideManager(_fileSystem.GetTempPath(), _loggerFactory, _fileSystem, _csvUtils);
var outputDirectory = _fileSystem.GetTempPath();
_fileName = _fileSystem.Combine(outputDirectory, "report.csv");
_overrideManager = new MethodOverrideManager(outputDirectory, _loggerFactory, _fileSystem, _csvUtils);
_reportItems = [];
}

[TearDown]
public void TearDown()
{
_fileSystem.Dispose();
_stringWriter.Dispose();
}

[Test]
Expand Down Expand Up @@ -74,13 +74,13 @@ public async Task WriteReportItemsCsvAsync_HandlesCustomColumns()
AttributeParameters = new HashSet<string> { "CustomColumn1", "CustomColumn3" }
});

var writer = new CsvReportWriter(_stringWriter, _reportItems, _overrideManager);
var writer = new CsvReportWriter(_fileName, _reportItems, _overrideManager, _loggerFactory, _csvUtils);

// Act
await writer.WriteReportItemsCsvAsync();

// Assert
var content = _stringWriter.ToString();
var content = await _fileSystem.ReadAllTextAsync(_fileName);
var lines = content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Assert.That(lines.Length, Is.EqualTo(3), "Should have header and two data lines");
Expand All @@ -102,13 +102,13 @@ public async Task WriteRelationshipsCsvAsync_HandlesVariousRelationshipTypes()
_reportItems.Add(new ReportItem { Id = "2", Parent = "1", MethodName = "ChildMethod", Parameters = new Dictionary<string, string> { { "IsExtension", "True" } } });
_reportItems.Add(new ReportItem { Id = "3", Parent = "1", MethodName = "GenericMethod", Parameters = new Dictionary<string, string> { { "IsGeneric", "True" } } });

var writer = new CsvReportWriter(_stringWriter, _reportItems, _overrideManager);
var writer = new CsvReportWriter(_fileName, _reportItems, _overrideManager, _loggerFactory, _csvUtils);

// Act
await writer.WriteRelationshipsCsvAsync();

// Assert
var content = _stringWriter.ToString();
var content = await _fileSystem.ReadAllTextAsync(_fileName);
var lines = content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Assert.That(lines[1], Does.Contain("Static"));
Expand All @@ -120,13 +120,13 @@ public async Task WriteRelationshipsCsvAsync_HandlesVariousRelationshipTypes()
public async Task WriteReportItemsCsvAsync_HandlesEmptyReportItems()
{
// Arrange
var writer = new CsvReportWriter(_stringWriter, _reportItems, _overrideManager);
var writer = new CsvReportWriter(_fileName, _reportItems, _overrideManager, _loggerFactory, _csvUtils);

// Act
await writer.WriteReportItemsCsvAsync();

// Assert
var content = _stringWriter.ToString();
var content = await _fileSystem.ReadAllTextAsync(_fileName);
var lines = content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Assert.That(lines.Length, Is.EqualTo(1), "Should only have header line");
Expand All @@ -148,13 +148,13 @@ public async Task WriteReportItemsCsvAsync_HandlesNullValues()
}
});

var writer = new CsvReportWriter(_stringWriter, _reportItems, _overrideManager);
var writer = new CsvReportWriter(_fileName, _reportItems, _overrideManager, _loggerFactory, _csvUtils);

// Act
await writer.WriteReportItemsCsvAsync();

// Assert
var content = _stringWriter.ToString();
var content = await _fileSystem.ReadAllTextAsync(_fileName);
_logger.LogInformation($"CSV Content:\n{content}");
var lines = content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Expand Down
18 changes: 10 additions & 8 deletions src/Orc.Monitoring.Tests/CsvReportWriterSpecialCharactersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TestUtilities.Logging;
using TestUtilities.Mocks;
Expand All @@ -15,7 +16,7 @@
[TestFixture]
public class CsvReportWriterSpecialCharactersTests
{
private StringWriter _stringWriter;
private string _fileName;
private MethodOverrideManager _overrideManager;
private List<ReportItem> _reportItems;
private TestLogger<CsvReportWriterSpecialCharactersTests> _logger;
Expand All @@ -32,21 +33,22 @@ public void Setup()
_fileSystem = new InMemoryFileSystem(_loggerFactory);
_csvUtils = TestHelperMethods.CreateCsvUtils(_fileSystem, _loggerFactory);

_stringWriter = new StringWriter();
_overrideManager = new MethodOverrideManager(_fileSystem.GetTempPath(), _loggerFactory, _fileSystem, _csvUtils);

var outputDirectory = _fileSystem.GetTempPath();
_fileName = _fileSystem.Combine(outputDirectory, "report.csv");
_overrideManager = new MethodOverrideManager(outputDirectory, _loggerFactory, _fileSystem, _csvUtils);
_reportItems = [];
}

[TearDown]
public void TearDown()
{
_fileSystem.Dispose();
_stringWriter.Dispose();
}

[Test]
[Ignore("We are handling special characters in the CsvUlitls class")]
public void WriteReportItemsCsv_HandlesSpecialCharacters()
public async Task WriteReportItemsCsv_HandlesSpecialCharactersAsync()
{
// Arrange
_reportItems.Add(new ReportItem
Expand All @@ -64,13 +66,13 @@ public void WriteReportItemsCsv_HandlesSpecialCharacters()
AttributeParameters = new HashSet<string> { "Param_With_Comma", "Param_With_Quotes" }
});

var writer = new CsvReportWriter(_stringWriter, _reportItems, _overrideManager);
var writer = new CsvReportWriter(_fileName, _reportItems, _overrideManager, _loggerFactory, _csvUtils);

// Act
writer.WriteReportItemsCsv();
await writer.WriteReportItemsCsvAsync();

// Assert
var content = _stringWriter.ToString();
var content = await _fileSystem.ReadAllTextAsync(_fileName);
_logger.LogInformation($"CSV Content:\n{content}");
var lines = content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Expand Down
Loading