Skip to content

Commit 357be26

Browse files
committed
Fix tests
1 parent 57825b9 commit 357be26

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/Aspire.Dashboard/ConsoleLogs/LogParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public LogEntry CreateLogEntry(string rawText, bool isErrorOutput)
3535
if (TimestampParser.TryColorizeTimestamp(content, out var timestampParseResult))
3636
{
3737
isFirstLine = true;
38-
content = timestampParseResult.ModifiedText;
39-
timestamp = timestampParseResult.Timestamp;
38+
content = timestampParseResult.Value.ModifiedText;
39+
timestamp = timestampParseResult.Value.Timestamp;
4040
}
4141
// 2. Parse the content to look for info/warn/dbug header
4242
// TODO extract log level and use here

src/Aspire.Dashboard/ConsoleLogs/TimestampParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Globalization;
56
using System.Text.RegularExpressions;
67
using Aspire.Dashboard.Extensions;
@@ -12,7 +13,7 @@ public static partial class TimestampParser
1213
{
1314
private static readonly Regex s_rfc3339RegEx = GenerateRfc3339RegEx();
1415

15-
public static bool TryColorizeTimestamp(string text, out TimestampParserResult result)
16+
public static bool TryColorizeTimestamp(string text, [NotNullWhen(true)] out TimestampParserResult? result)
1617
{
1718
var match = s_rfc3339RegEx.Match(text);
1819

tests/Aspire.Dashboard.Tests/ConsoleLogsTests/TimestampParserTests.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,26 @@ public void TryColorizeTimestamp_DoesNotStartWithTimestamp_ReturnsFalse(string i
2121
}
2222

2323
[Theory]
24-
[InlineData("2023-10-10T15:05:30.123456789Z", true, "<span class=\"timestamp\">2023-10-10T15:05:30.123456789Z</span>", "2023-10-10T15:05:30.123456789Z")]
25-
[InlineData("2023-10-10T15:05:30.123456789Z ", true, "<span class=\"timestamp\">2023-10-10T15:05:30.123456789Z</span> ", "2023-10-10T15:05:30.123456789Z")]
26-
[InlineData("2023-10-10T15:05:30.123456789Z with some text after it", true, "<span class=\"timestamp\">2023-10-10T15:05:30.123456789Z</span> with some text after it", "2023-10-10T15:05:30.123456789Z")]
24+
[InlineData("2023-10-10T15:05:30.123456789Z", true, "", "2023-10-10T15:05:30.123456789Z")]
25+
[InlineData("2023-10-10T15:05:30.123456789Z ", true, " ", "2023-10-10T15:05:30.123456789Z")]
26+
[InlineData("2023-10-10T15:05:30.123456789Z with some text after it", true, " with some text after it", "2023-10-10T15:05:30.123456789Z")]
2727
[InlineData("With some text before it 2023-10-10T15:05:30.123456789Z", false, null, null)]
2828
public void TryColorizeTimestamp_ReturnsCorrectResult(string input, bool expectedResult, string? expectedOutput, string? expectedTimestamp)
2929
{
3030
var result = TimestampParser.TryColorizeTimestamp(input, out var parseResult);
3131

3232
Assert.Equal(expectedResult, result);
33-
Assert.Equal(expectedOutput, parseResult.ModifiedText);
34-
Assert.Equal(expectedTimestamp != null ? (DateTimeOffset?)DateTimeOffset.Parse(expectedTimestamp, CultureInfo.InvariantCulture) : null, parseResult.Timestamp);
33+
34+
if (result)
35+
{
36+
Assert.NotNull(parseResult);
37+
Assert.Equal(expectedOutput, parseResult.Value.ModifiedText);
38+
Assert.Equal(expectedTimestamp != null ? (DateTimeOffset?)DateTimeOffset.Parse(expectedTimestamp, CultureInfo.InvariantCulture) : null, parseResult.Value.Timestamp);
39+
}
40+
else
41+
{
42+
Assert.Null(parseResult);
43+
}
3544
}
3645

3746
[Theory]

0 commit comments

Comments
 (0)