Skip to content

Commit

Permalink
Cleaning up test support for date time parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
priorax authored and Doug Ferris committed May 30, 2024
1 parent b208617 commit 9aa4a75
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 0 additions & 4 deletions src/LibYear/Output/Json/DisplayVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ namespace LibYear.Output.Json;

internal sealed record DisplayVersion
{
[JsonPropertyName("versionNumber")]
public string VersionNumber { get; init; } = string.Empty;
[JsonPropertyName("releaseDate")]
public DateTime ReleaseDate { get; init; }
public Release Release { get; init; }
public DisplayVersion(Release release)
{
Release = release;
VersionNumber = release.Version.ToString();
ReleaseDate = release.Date;
}
Expand Down
21 changes: 12 additions & 9 deletions test/LibYear.Tests/Output/Json/JsonOutputTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibYear.Core;
using System.Security.AccessControl;
using LibYear.Core;
using LibYear.Core.Tests;
using LibYear.Output.Json;
using NSubstitute;
Expand Down Expand Up @@ -51,16 +52,17 @@ public void QuietModeResultInSingleLineOutput()
{
//arrange
var projectFile1 = new TestProjectFile("test project 1");
var dateTime = new DateTime(2020, 01, 02);
var solutionResults = new SolutionResult(new[]
{
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), DateTime.Today), new Release(new PackageVersion(1, 2, 3), DateTime.Today)) }),
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), dateTime), new Release(new PackageVersion(1, 2, 3), dateTime)) }),
});

// act
var result = JsonOutput.FormatOutput(solutionResults, true);

// assert
var expectedJsonOutput = @"{""YearsBehind"":0,""DaysBehind"":0,""Projects"":[{""Project"":""test project 1"",""YearsBehind"":0,""Packages"":[{""PackageName"":""test1"",""CurrentVersion"":{""versionNumber"":""1.2.3"",""releaseDate"":""2024-05-29""},""LatestVersion"":{""versionNumber"":""1.2.3"",""releaseDate"":""2024-05-29""},""YearsBehind"":0}]}]}";
var expectedJsonOutput = @"{""YearsBehind"":0,""DaysBehind"":0,""Projects"":[{""Project"":""test project 1"",""YearsBehind"":0,""Packages"":[{""PackageName"":""test1"",""CurrentVersion"":{""VersionNumber"":""1.2.3"",""ReleaseDate"":""2020-01-02""},""LatestVersion"":{""VersionNumber"":""1.2.3"",""ReleaseDate"":""2020-01-02""},""YearsBehind"":0}]}]}";
Assert.Equal(expectedJsonOutput, result);
}

Expand All @@ -70,9 +72,10 @@ public void NonQuietModeShouldResultInMultiLineOutput()
//arrange

var projectFile1 = new TestProjectFile("test project 1");
var dateTime = new DateTime(2020, 01, 02);
var results = new SolutionResult(new []
{
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), DateTime.Today), new Release(new PackageVersion(1, 2, 3), DateTime.Today)) }),
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), dateTime), new Release(new PackageVersion(1, 2, 3), dateTime)) }),
});

// act
Expand All @@ -91,12 +94,12 @@ public void NonQuietModeShouldResultInMultiLineOutput()
{
"PackageName": "test1",
"CurrentVersion": {
"versionNumber": "1.2.3",
"releaseDate": "2024-05-29"
"VersionNumber": "1.2.3",
"ReleaseDate": "2020-01-02"
},
"LatestVersion": {
"versionNumber": "1.2.3",
"releaseDate": "2024-05-29"
"VersionNumber": "1.2.3",
"ReleaseDate": "2020-01-02"
},
"YearsBehind": 0
}
Expand All @@ -105,6 +108,6 @@ public void NonQuietModeShouldResultInMultiLineOutput()
]
}
""";
Assert.Equal(expectedOutput, result);
Assert.Equal(expectedOutput.ReplaceLineEndings(), result);
}
}
23 changes: 12 additions & 11 deletions test/LibYear.Tests/Output/Table/TableOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class TableOutputTests
[Fact]
public void NoResultsProducesNoOutput()
{
//arrange
// arrange
var console = new TestConsole();

// Act
// act
var output = new TableOutput(console);
var result = new SolutionResult(Array.Empty<ProjectResult>());
output.DisplayAllResults(result, false);

// Assert
// assert
Assert.Empty(console.Output);
}

Expand All @@ -29,30 +29,32 @@ public void ShouldPrintATableIfQuietModeDisabled()
{
//arrange
var console = new TestConsole();
var legacyDateTime = new DateTime(2020, 01, 03);
var newDateTime = new DateTime(2020, 01, 05);

// Act
// act
var output = new TableOutput(console);
var projectFile1 = new TestProjectFile("test project 1");
var results = new SolutionResult(new []
{
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), DateTime.Today), new Release(new PackageVersion(1, 2, 3), DateTime.Today)) }),
new ProjectResult(projectFile1, new[] { new Result("test1", new Release(new PackageVersion(1, 2, 3), legacyDateTime), new Release(new PackageVersion(1, 2, 3), newDateTime)) }),
});
output.DisplayAllResults(results, false);

// Assert
// assert

Assert.NotEmpty(console.Output);
Assert.Contains("│ Package │ Installed │ Released │ Latest │ Released │ Age (y) │", console.Output);
Assert.Contains("│ test1 │ 1.2.3 │ 2024-05-24 │ 1.2.3 │ 2024-05-24 │ 0.0 │", console.Output);
Assert.Contains("│ test1 │ 1.2.3 │ 2020-01-03 │ 1.2.3 │ 2020-01-05 │ 0.0 │", console.Output);
}

[Fact]
public void ShouldPrintSimplifiedIfInQuietMode()
{
//arrange
// arrange
var console = new TestConsole();

// Act
// act
var output = new TableOutput(console);
var projectFile1 = new TestProjectFile("test project 1");
var results = new SolutionResult(new []
Expand All @@ -61,8 +63,7 @@ public void ShouldPrintSimplifiedIfInQuietMode()
});
output.DisplayAllResults(results, true);

// Assert

// assert
Assert.NotEmpty(console.Output);
Assert.Contains(" Project is 0.0 libyears ", console.Output);
}
Expand Down

0 comments on commit 9aa4a75

Please sign in to comment.