Skip to content

Commit

Permalink
Fix wrong mapping and add tests (#33)
Browse files Browse the repository at this point in the history
* fix datetime format error while deserialize test report

* add more date time formats
update test

---------

Co-authored-by: vdungsrikaew <virasak.dungsrikaew@agoda.com>
  • Loading branch information
virasak and virasakagoda committed Jun 23, 2023
1 parent f2db673 commit 7ec3160
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ public void WhenInitTestCaseConverter_ShouldPopulateListOfTestCasesCorrectly()
";
var result = new NUnitXmlEventConverter(report);
result.TestCases.Count.ShouldBe(4);

for (int i = 1; i <= 4; i++)
{
result.TestCases[i - 1].Name.ShouldBe($"{i}WhenOneIsOne_ItSHouldBeOne",customMessage:$"Name on {i}");
result.TestCases[i - 1].Id.ShouldBe($"0-100{i}", customMessage: $"Id on {i}");
result.TestCases[i - 1].Fullname.ShouldBe($"Agoda.TestingLib.Tests.UnitTest{(i+1) / 2}.{i}WhenOneIsOne_ItSHouldBeOne", customMessage: $"Fullname on {i}");
result.TestCases[i - 1].Duration.ShouldBe(0.033255, customMessage: $"Duration on {i}");
result.TestCases[i - 1].Duration.ShouldBe(0.033255, customMessage: $"Duration on {i}");

var duration = (result.TestCases[i - 1].EndTime - result.TestCases[i - 1].StartTime).TotalSeconds;
duration.ShouldBe(0.0331569, customMessage: $"Duration on {i}");
}

}
}
20 changes: 17 additions & 3 deletions src/Agoda.Tests.Metrics.NUnit/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ namespace Agoda.Tests.Metrics.NUnit
[XmlRoot(ElementName = "test-case")]
public class TestCase
{
private static readonly string[] Formats =
{
"yyyy-MM-ddTHH:mm:ss.fffffffZ",
"yyyy-MM-dd HH:mm:ss.fffffffZ",
"yyyy-MM-ddTHH:mm:ss.fffffff",
"yyyy-MM-dd HH:mm:ss.fffffff",
"yyyy-MM-ddTHH:mm:ssZ",
"yyyy-MM-dd HH:mm:ssZ",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-dd HH:mm:ss",
};

[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
Expand All @@ -33,21 +44,24 @@ public class TestCase
[XmlAttribute(AttributeName = "result")]
public string Result { get; set; }

[XmlIgnore]
public DateTime StartTime { get; set; }

[XmlAttribute(AttributeName = "start-time")]
public string StartTimeRaw
{
set => StartTime = DateTime.TryParseExact(value, new[] { "yyyy-MM-dd HH:mm:ssZ", "yyyy-MM-ddTHH:mm:ss"}, CultureInfo.InvariantCulture, DateTimeStyles.None, out var result) ? result : DateTime.MinValue;
get => StartTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffff");
set => StartTime = DateTime.TryParseExact(value, Formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var result) ? result : DateTime.MinValue;
}


[XmlIgnore]
public DateTime EndTime { get; set; }

[XmlAttribute(AttributeName = "end-time")]
public string EndTimeRaw
{
set => StartTime = DateTime.TryParseExact(value, new[] { "yyyy-MM-dd HH:mm:ssZ", "yyyy-MM-ddTHH:mm:ss"}, CultureInfo.InvariantCulture, DateTimeStyles.None, out var result) ? result : DateTime.MinValue;
get => EndTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff");
set => EndTime = DateTime.TryParseExact(value, Formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var result) ? result : DateTime.MinValue;
}

[XmlAttribute(AttributeName = "duration")]
Expand Down

0 comments on commit 7ec3160

Please sign in to comment.