-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to sort the repos in the table either alphabetically or according to their last modification. Ascending or descending order can be set as well.
- Loading branch information
Showing
13 changed files
with
277 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace RepoStatusTable.Options; | ||
|
||
public enum RepoOrderBy | ||
{ | ||
Alphabetically, | ||
LastModified | ||
} | ||
|
||
public enum RepoOrder | ||
{ | ||
Ascending, | ||
Descending | ||
} |
43 changes: 43 additions & 0 deletions
43
src/RepoStatusTable/Utilities/ReposDirectory/RepoOrderProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using RepoStatusTable.Facade; | ||
using RepoStatusTable.Options; | ||
|
||
namespace RepoStatusTable.Utilities.ReposDirectory; | ||
|
||
public interface IReposOrderProvider | ||
{ | ||
public IEnumerable<string> OrderAccordingToOptions( IEnumerable<string> directories ); | ||
} | ||
|
||
public class ReposOrderProvider : IReposOrderProvider | ||
{ | ||
private readonly IFileSystemFacade _fileSystemFacade; | ||
private readonly IOptions<RepoOptions> _repoOptions; | ||
|
||
public ReposOrderProvider( IOptions<RepoOptions> repoOptions, IFileSystemFacade fileSystemFacade ) | ||
{ | ||
_repoOptions = repoOptions; | ||
_fileSystemFacade = fileSystemFacade; | ||
} | ||
|
||
public IEnumerable<string> OrderAccordingToOptions( IEnumerable<string> directories ) | ||
{ | ||
var orderFunc = GetCompareFunc(); | ||
|
||
return _repoOptions.Value.Order switch | ||
{ | ||
RepoOrder.Ascending => directories.OrderBy( orderFunc ), | ||
RepoOrder.Descending => directories.OrderByDescending( orderFunc ), | ||
_ => throw new ArgumentOutOfRangeException() | ||
}; | ||
} | ||
|
||
private Func<string, IComparable> GetCompareFunc() | ||
{ | ||
return _repoOptions.Value.OrderBy switch | ||
{ | ||
RepoOrderBy.Alphabetically => d => d, | ||
RepoOrderBy.LastModified => d => _fileSystemFacade.GetLastWriteTime( d ), | ||
_ => throw new ArgumentOutOfRangeException() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/RepoStatusTable.UnitTests/Utilities/ReposOrderProviderBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Options; | ||
using RepoStatusTable.Facade; | ||
using RepoStatusTable.Options; | ||
using RepoStatusTable.Utilities.ReposDirectory; | ||
|
||
namespace RepoStatusTable.UnitTests.Utilities; | ||
|
||
public class ReposOrderProviderBuilder | ||
{ | ||
private readonly Mock<IFileSystemFacade> _fileSystemFacade = new(MockBehavior.Strict); | ||
private readonly RepoOptions _options = new(); | ||
|
||
public ReposOrderProviderBuilder WithDescendingOrder() | ||
{ | ||
_options.Order = RepoOrder.Descending; | ||
return this; | ||
} | ||
|
||
public ReposOrderProviderBuilder WithAscendingOrder() | ||
{ | ||
_options.Order = RepoOrder.Ascending; | ||
return this; | ||
} | ||
|
||
public ReposOrderProviderBuilder WithOrderByAlphabetically() | ||
{ | ||
_options.OrderBy = RepoOrderBy.Alphabetically; | ||
return this; | ||
} | ||
|
||
public ReposOrderProviderBuilder WithOrderByLastModified() | ||
{ | ||
_options.OrderBy = RepoOrderBy.LastModified; | ||
return this; | ||
} | ||
|
||
public ReposOrderProviderBuilder WithFileSystemFacadeLastWriteTimeReturns( string path, DateTime dateTime ) | ||
{ | ||
_fileSystemFacade.Setup( m => m.GetLastWriteTime( path ) ) | ||
.Returns( dateTime ); | ||
return this; | ||
} | ||
|
||
public ReposOrderProvider Build() | ||
{ | ||
return new ReposOrderProvider( | ||
new OptionsWrapper<RepoOptions>( _options ), | ||
_fileSystemFacade.Object ); | ||
} | ||
} |
Oops, something went wrong.