Skip to content

Commit

Permalink
Resolves #45 (#84)
Browse files Browse the repository at this point in the history
* Entering a match result with a future actual start date or actual end date will be rejected as error
* Replace depreciated NLogBuilder.ConfigureNLog(...) with LogManager.Setup().LoadConfigurationFromFile(...)
  • Loading branch information
axunonb authored Jul 10, 2023
1 parent 54e8b4a commit 4c101ca
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
11 changes: 6 additions & 5 deletions League.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using NLog.Extensions.Logging;
using TournamentManager.MultiTenancy;
using Axuno.BackgroundTask;
using NLog;

namespace League.WebApp;

Expand All @@ -19,10 +20,10 @@ public static async Task Main(string[] args)
{
// NLog: setup the logger first to catch all errors
var currentDir = Directory.GetCurrentDirectory();
var logger = NLogBuilder
.ConfigureNLog($@"{currentDir}{Path.DirectorySeparatorChar}{LeagueStartup.ConfigurationFolder}{Path.DirectorySeparatorChar}NLog.Internal.config")
var logger = LogManager.Setup()
.LoadConfigurationFromFile(
$@"{currentDir}{Path.DirectorySeparatorChar}{LeagueStartup.ConfigurationFolder}{Path.DirectorySeparatorChar}NLog.Internal.config")
.GetCurrentClassLogger();

// Allows for <target name="file" xsi:type="File" fileName = "${var:logDirectory}logfile.log"... >
NLog.LogManager.Configuration.Variables["logDirectory"] = currentDir + Path.DirectorySeparatorChar;

Expand All @@ -37,8 +38,8 @@ public static async Task Main(string[] args)
builder.Logging.ClearProviders();
// Enable NLog as logging provider for Microsoft.Extension.Logging
builder.Logging.AddNLog(loggingConfig);
NLogBuilder.ConfigureNLog(Path.Combine(builder.Environment.ContentRootPath, LeagueStartup.ConfigurationFolder,
$"NLog.{builder.Environment.EnvironmentName}.config"));
LogManager.Setup()
.LoadConfigurationFromFile($"NLog.{builder.Environment.EnvironmentName}.config");

builder.WebHost.ConfigureServices((context, services) =>
{
Expand Down
2 changes: 1 addition & 1 deletion League/BackgroundTasks/SendEmailTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task RunAsync(CancellationToken cancellationToken)
{
try
{
await _mailMergeService.Sender.SendAsync(mmm, null!);
await _mailMergeService.Sender.SendAsync(mmm, null);
}
catch (Exception e) when (e is TaskCanceledException || e is OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public async Task RealMatchDate_Within_Round_Legs(DateTime? realStart, bool fail
}

[Test]
public async Task RealMatchDate_May_Not_Be_Null()
public async Task RealMatchDate_Must_Not_Be_Null()
{
var match = new MatchEntity
{
Expand All @@ -215,6 +215,32 @@ public async Task RealMatchDate_May_Not_Be_Null()
});
}

[Test]
public async Task RealMatchDate_Must_Not_Be_Future_Date()
{
var today = new DateTime(2023, 7, 1, 23, 59, 59);
var match = new MatchEntity
{
Id = 1,
RealStart = today.AddDays(1),
RealEnd = today.AddDays(1),
RoundId = 2,
LegSequenceNo = 1,
HomeTeamId = 7,
GuestTeamId = 10
};

var mv = new MatchResultValidator(match, _data) { Today = today };
await mv.CheckAsync(MatchResultValidator.FactId.RealMatchDateTodayOrBefore, CancellationToken.None);
var factResults = mv.GetFailedFacts();
Assert.Multiple(() =>
{
Assert.AreEqual(1, factResults.Count);
Assert.AreEqual(MatchResultValidator.FactId.RealMatchDateTodayOrBefore, factResults.First().Id);
Assert.NotNull(factResults.First().Message);
});
}

[Test]
public async Task RealMatchDate_Should_Equal_Fixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace TournamentManager.ModelValidators;
public class MatchResultValidator : AbstractValidator<MatchEntity, (ITenantContext TenantContext,
Axuno.Tools.DateAndTime.TimeZoneConverter TimeZoneConverter, (MatchRuleEntity MatchRule, SetRuleEntity SetRule) Rules), MatchResultValidator.FactId>
{
internal DateTime Today { get; set; } = DateTime.UtcNow; // used for unit tests
public enum FactId
{
RealMatchDateIsSet,
RealMatchDateTodayOrBefore,
RealMatchDateWithinRoundLegs,
RealMatchDateEqualsFixture,
RealMatchDurationIsPlausible,
Expand Down Expand Up @@ -47,6 +49,21 @@ public void CreateFacts()
})
});

Facts.Add(
new Fact<FactId>
{
Id = FactId.RealMatchDateTodayOrBefore,
FieldNames = new[] { nameof(Model.RealStart), nameof(Model.RealEnd) },
Enabled = true,
Type = FactType.Error,
CheckAsync = (cancellationToken) => Task.FromResult(
new FactResult
{
Message = MatchResultValidatorResource.ResourceManager.GetString(nameof(FactId.RealMatchDateTodayOrBefore)) ?? string.Empty,
Success = Model.RealStart?.Date <= Today.Date && Model.RealEnd?.Date <= Today.Date
})
});

Facts.Add(
new Fact<FactId>
{
Expand Down Expand Up @@ -166,4 +183,4 @@ await Data.TenantContext.DbContext.AppDb.RoundRepository.GetRoundWithLegsAsync(M
}
});
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="RealMatchDateIsSet" xml:space="preserve">
<value>Spielbeginn und -ende müssen angegeben werden</value>
</data>
<data name="RealMatchDateTodayOrBefore" xml:space="preserve">
<value>Der tatsächliche Spieltag kann nicht in der Zukunft liegen</value>
</data>
<data name="RealMatchDateWithinRoundLegs" xml:space="preserve">
<value>Spieldatum in {0} muss innerhalb {1} sein</value>
<comment>0 = round description, 1 = date range</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="RealMatchDateIsSet" xml:space="preserve">
<value>Start and end time of the match must be set</value>
</data>
<data name="RealMatchDateTodayOrBefore" xml:space="preserve">
<value>Actual match day cannot be in the future</value>
</data>
<data name="RealMatchDateWithinRoundLegs" xml:space="preserve">
<value>Match date in {0} must be within {1}</value>
<comment>0 = round description, 1 = date range</comment>
Expand Down

0 comments on commit 4c101ca

Please sign in to comment.