chore: fixed a reference to Gallium

This commit is contained in:
D. Moonfire 2023-01-16 22:09:06 -06:00
parent edda9a2773
commit c73805ae93
29 changed files with 708 additions and 69 deletions

View file

@ -10,16 +10,16 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Temporal\MfGames.Nitride.Temporal.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Temporal\MfGames.Nitride.Temporal.csproj" />
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="Ical.Net" Version="4.2.0"/>
<PackageReference Include="NodaTime" Version="3.1.2"/>
<PackageReference Include="Zio" Version="0.15.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
<PackageReference Include="NodaTime" Version="3.1.2" />
<PackageReference Include="Zio" Version="0.15.0" />
</ItemGroup>
<!-- Include the source generator -->

View file

@ -10,15 +10,15 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Temporal\MfGames.Nitride.Temporal.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Temporal\MfGames.Nitride.Temporal.csproj" />
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="NodaTime" Version="3.1.2"/>
<PackageReference Include="Zio" Version="0.15.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="NodaTime" Version="3.1.2" />
<PackageReference Include="Zio" Version="0.15.0" />
</ItemGroup>
<!-- Include the source generator -->

View file

@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" />

View file

@ -10,15 +10,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.4.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="Handlebars.Net" Version="2.1.2"/>
<PackageReference Include="NodaTime.Testing" Version="3.1.2"/>
<PackageReference Include="Open.Threading" Version="2.2.1"/>
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Handlebars.Net" Version="2.1.2" />
<PackageReference Include="NodaTime.Testing" Version="3.1.2" />
<PackageReference Include="Open.Threading" Version="2.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<!-- Include the source generator -->

View file

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<!-- Include the source generator -->
@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
</ItemGroup>
</Project>

View file

@ -8,17 +8,17 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.4.0"/>
<PackageReference Include="DotNet.Glob" Version="3.1.3"/>
<PackageReference Include="FluentValidation" Version="11.2.1"/>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="MAB.DotIgnore" Version="3.0.2"/>
<PackageReference Include="Serilog" Version="2.11.0"/>
<PackageReference Include="Zio" Version="0.15.0"/>
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="FluentValidation" Version="11.2.1" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="MAB.DotIgnore" Version="3.0.2" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Zio" Version="0.15.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<!-- Include the source generator -->

View file

@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

View file

@ -10,17 +10,17 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride.Gemtext\MfGames.Nitride.Gemtext.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Html\MfGames.Nitride.Html.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Slugs\MfGames.Nitride.Slugs.csproj"/>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Gemtext\MfGames.Nitride.Gemtext.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Html\MfGames.Nitride.Html.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Slugs\MfGames.Nitride.Slugs.csproj" />
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="Markdig" Version="0.30.3"/>
<PackageReference Include="MfGames.Markdown.Gemtext" Version="1.2.2"/>
<PackageReference Include="Zio" Version="0.15.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Markdig" Version="0.30.3" />
<PackageReference Include="MfGames.Markdown.Gemtext" Version="1.2.2" />
<PackageReference Include="Zio" Version="0.15.0" />
</ItemGroup>
<!-- Include the source generator -->

View file

@ -0,0 +1,6 @@
namespace MfGames.Nitride.Temporal.Schedules;
public interface ApplySchedules
{
}

View file

@ -0,0 +1,24 @@
using MfGames.Gallium;
namespace MfGames.Nitride.Temporal.Schedules;
/// <summary>
/// A schedule is a specific schedule that can be applied to an entity to make
/// changes based on components.
/// </summary>
public interface ISchedule
{
/// <summary>
/// Determines if a schedule applies to a given entity.
/// </summary>
/// <param name="entity">The entity to test.</param>
/// <returns>True if the schedule applies to the given entity, otherwise false.</returns>
bool CanApply(Entity entity);
/// <summary>
/// Applies the schedule changes to the entity and returns the results.
/// </summary>
/// <param name="entity">The entity to update.</param>
/// <returns>The modified entity, if the changes can be applied, otherwise the same entity.</returns>
Entity Apply(Entity entity);
}

View file

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Description>An extension to Nitride static site generator to add a scheduling system for posts.</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
<!-- Include the source generator -->
<PropertyGroup>
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MfGames.Nitride.Generators\MfGames.Nitride.Generators.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
</Project>

View file

@ -0,0 +1,33 @@
using System;
using System.Text.RegularExpressions;
using MfGames.Gallium;
using MfGames.Nitride.Generators;
namespace MfGames.Nitride.Temporal.Schedules;
/// <summary>
/// A schedule that uses the `UPath` of the entity to determine an offset from
/// a starting point and calculates the information from there.
/// </summary>
[WithProperties]
public partial class NumericalPathSchedule
{
public NumericalPathSchedule()
{
this.PathRegex = new Regex(@"^.*(\d+)");
this.GetPath = (entity) => entity.Get<UPath>().ToString();
this.CaptureGroup = 1;
this.CaptureOffset = -1;
}
public Regex? PathRegex { get; set; }
public Func<Entity, string> GetPath { get; set; }
public DateTime? ScheduleStart { get; set; }
public SchedulePeriod SchedulePeriod { get; set; }
public int CaptureGroup { get; set; }
public int CaptureOffset { get; set; }
}

View file

@ -0,0 +1,41 @@
# Date Processing
One of the common features of static websites are blogs which leads to having
some form of date-centric processing of pages to build archive pages, calendars,
and being able to write posts in the future.
With the component system, the date of a given file is simply attached to
`Nodatime.Instant` component of the `Entity` object for the bulk of the
processing.
## Supporting Time Zones
The concept of time zones while date processing is one that is frequently
overlooked. A date is a date, right? However, most blogs and news sites have a
concept of when a new day starts but it isn't always the same time as the server
that is building the site. While a blog might be in America/Chicago time, a CI
server could be set to UTC (such as Azure build servers) and the
"day" may roll over fix or six hours before or after the blog's time.
This is why Nitride uses `Instant` for when pages are implemented. These are
points in time that are independent of time zones, but we also provide tools for
converting a date model or one from the path into a proper instant based on the
blog's time zone.
## Why NodaTime?
We decided to use [NodaTime](https://nodatime.org/) instead of the built-in date
time functions for a number of reasons, mainly because it has a more intuitive
way of handling time zones
## Configuring
There are two callbacks on `NitrideBuilder` that can be used to define the date
and time processing for the blog.
```csharp
NitrideBuilder builder;
builder
.ConfigureDates((NitrideClock clock) => clock.SetTimeZone())
```

View file

@ -0,0 +1,79 @@
using System;
using Autofac;
using MfGames.Nitride.Commands;
using MfGames.Nitride.Temporal.Cli;
using Serilog;
namespace MfGames.Nitride.Temporal.Schedules.Setup;
public static class NitrideTemporalSchedulesBuilderExtensions
{
/// <summary>
/// Extends the builder to allow for configuring the temporal
/// settings for generation.
/// </summary>
public static NitrideBuilder UseTemporal(
this NitrideBuilder builder,
Action<NitrideTemporalConfiguration>? configure = null)
{
// Get the configuration so we can set the various options.
var config = new NitrideTemporalConfiguration();
configure?.Invoke(config);
// Add in the module registration.
builder.ConfigureContainer(
x =>
{
// Register the module.
x.RegisterModule<NitrideTemporalModule>();
// Add in the CLI options.
if (config.AddDateOptionToCommandLine)
{
x.RegisterType<DatePipelineCommandOption>()
.As<IPipelineCommandOption>();
}
if (config.AddExpireOptionToCommandLine
&& config.Expiration != null)
{
x.Register(
context =>
{
ILogger logger = context.Resolve<ILogger>();
Timekeeper
clock = context.Resolve<Timekeeper>();
return new ExpiresPipelineCommandOption(
logger,
clock,
config.Expiration);
})
.As<IPipelineCommandOption>();
}
});
if (config.DateTimeZone != null)
{
builder.ConfigureSite(
(
_,
scope) =>
{
ILogger logger = scope.Resolve<ILogger>();
Timekeeper timekeeper = scope.Resolve<Timekeeper>();
timekeeper.DateTimeZone = config.DateTimeZone;
logger.Verbose(
"Setting time zone to {Zone:l}",
timekeeper.DateTimeZone);
});
}
return builder;
}
}

View file

@ -0,0 +1,20 @@
using Autofac;
namespace MfGames.Nitride.Temporal.Schedules.Setup;
public class NitrideTemporalSchedulesModule : Module
{
/// <inheritdoc />
protected override void Load(ContainerBuilder builder)
{
builder.RegisterOperators(this);
builder.RegisterValidators(this);
builder.RegisterType<Timekeeper>()
.AsSelf()
.SingleInstance();
builder.RegisterGeneric(typeof(SetInstantFromComponent<>))
.As(typeof(SetInstantFromComponent<>));
}
}

View file

@ -0,0 +1,18 @@
using FluentValidation;
namespace MfGames.Nitride.Temporal.Schedules.Validators;
public class CreateDateIndexesValidator : AbstractValidator<CreateDateIndexes>
{
public CreateDateIndexesValidator()
{
this.RuleFor(a => a.Timekeeper)
.NotNull();
this.RuleFor(a => a.CreateIndex)
.NotNull();
this.RuleFor(a => a.Formats)
.NotNull();
}
}

View file

@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="YamlDotNet" Version="12.0.0" />
</ItemGroup>

View file

@ -18,7 +18,7 @@
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="FluentValidation" Version="11.2.1" />
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="MfGames.ToolBuilder" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />

View file

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.78.0" />
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />

View file

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="xunit" Version="2.4.2" />

View file

@ -6,18 +6,18 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MfGames.Nitride.Markdown\MfGames.Nitride.Markdown.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Tests\MfGames.Nitride.Tests.csproj"/>
<ProjectReference Include="..\..\src\MfGames.Nitride.Markdown\MfGames.Nitride.Markdown.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Tests\MfGames.Nitride.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Markdig" Version="0.30.4"/>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="MfGames.Markdown.Gemtext" Version="1.2.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1"/>
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114"/>
<PackageReference Include="Slugify.Core" Version="3.0.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="MfGames.Markdown.Gemtext" Version="1.2.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="Slugify.Core" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -6,21 +6,21 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj"/>
<ProjectReference Include="..\..\src\MfGames.Nitride.Slugs\MfGames.Nitride.Slugs.csproj"/>
<ProjectReference Include="..\MfGames.Nitride.Tests\MfGames.Nitride.Tests.csproj"/>
<ProjectReference Include="..\..\src\MfGames.Nitride.IO\MfGames.Nitride.IO.csproj" />
<ProjectReference Include="..\..\src\MfGames.Nitride.Slugs\MfGames.Nitride.Slugs.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Tests\MfGames.Nitride.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1"/>
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Zio" Version="0.15.0"/>
<PackageReference Include="Zio" Version="0.15.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>

View file

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MfGames.Nitride.Temporal.Schedules\MfGames.Nitride.Temporal.Schedules.csproj" />
<ProjectReference Include="..\MfGames.Nitride.Tests\MfGames.Nitride.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.78.0" />
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -0,0 +1,324 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MfGames.Gallium;
using MfGames.Nitride.Temporal.Tests;
using MfGames.Nitride.Tests;
using Xunit;
using Xunit.Abstractions;
namespace MfGames.Nitride.Temporal.Schedules.Tests;
public class TestPageModel
{
public string Access { get; set; }
}
public class TestSchedule : NumericalPathSchedule
{
}
public class ApplySchedulesTests : TemporalSchedulesTestBase
{
public ApplySchedulesTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void MonthOnlyIndexes()
{
using TemporalSchedulesTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
CreateDateIndexes op = context.Resolve<CreateDateIndexes>()
.WithFormats("yyyy-MM")
.WithCreateIndex(this.CreateIndex);
List<Entity> input = new()
{
new Entity().Add("page1")
.Add(timekeeper.CreateInstant(2021, 1, 2)),
new Entity().Add("page2")
.Add(timekeeper.CreateInstant(2021, 2, 2)),
new Entity().Add("page3")
.Add(timekeeper.CreateInstant(2022, 1, 2)),
};
List<Tuple<string, List<string>?, List<string>?>> actual =
this.GetActual(op, input);
var expected = new List<Tuple<string, List<string>?, List<string>?>>
{
new(
"index-2021-01",
new List<string> { "page1" },
new List<string>()),
new(
"index-2021-02",
new List<string> { "page2" },
new List<string>()),
new(
"index-2022-01",
new List<string> { "page3" },
new List<string>()),
new("page1", null, null),
new("page2", null, null),
new("page3", null, null),
};
TestHelper.CompareObjects(expected, actual);
}
[Fact]
public void YearMonthDayIndexes()
{
using TemporalSchedulesTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
CreateDateIndexes op = context.Resolve<CreateDateIndexes>()
.WithFormats("yyyy/MM/dd", "yyyy/MM", "yyyy")
.WithCreateIndex(this.CreateIndex);
List<Entity> input = new()
{
new Entity().Add("page1")
.Add(timekeeper.CreateInstant(2021, 1, 2)),
new Entity().Add("page2")
.Add(timekeeper.CreateInstant(2021, 2, 2)),
new Entity().Add("page3")
.Add(timekeeper.CreateInstant(2022, 1, 2)),
};
List<Tuple<string, List<string>?, List<string>?>> actual =
this.GetActual(op, input);
var expected = new List<Tuple<string, List<string>?, List<string>?>>
{
new(
"index-2021",
new List<string>(),
new List<string> { "index-2021/01", "index-2021/02" }),
new(
"index-2021/01",
new List<string>(),
new List<string> { "index-2021/01/02" }),
new(
"index-2021/01/02",
new List<string> { "page1" },
new List<string>()),
new(
"index-2021/02",
new List<string>(),
new List<string> { "index-2021/02/02" }),
new(
"index-2021/02/02",
new List<string> { "page2" },
new List<string>()),
new(
"index-2022",
new List<string>(),
new List<string> { "index-2022/01" }),
new(
"index-2022/01",
new List<string>(),
new List<string> { "index-2022/01/02" }),
new(
"index-2022/01/02",
new List<string> { "page3" },
new List<string>()),
new("page1", null, null),
new("page2", null, null),
new("page3", null, null),
};
TestHelper.CompareObjects(expected, actual);
}
[Fact]
public void YearMonthDayIndexesThreshold1()
{
using TemporalSchedulesTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
CreateDateIndexes op = context.Resolve<CreateDateIndexes>()
.WithFormats("yyyy/MM/dd", "yyyy/MM", "yyyy")
.WithCreateIndex(this.CreateIndex)
.WithLessThanEqualCollapse(1);
List<Entity> input = new()
{
new Entity().Add("page1")
.Add(timekeeper.CreateInstant(2021, 1, 2)),
new Entity().Add("page2")
.Add(timekeeper.CreateInstant(2021, 2, 2)),
new Entity().Add("page3")
.Add(timekeeper.CreateInstant(2022, 1, 2)),
};
List<Tuple<string, List<string>?, List<string>?>> actual =
this.GetActual(op, input);
var expected = new List<Tuple<string, List<string>?, List<string>?>>
{
new(
"index-2021",
new List<string>(),
new List<string> { "index-2021/01", "index-2021/02" }),
new(
"index-2021/01",
new List<string> { "page1" },
new List<string> { "index-2021/01/02" }),
new(
"index-2021/01/02",
new List<string> { "page1" },
new List<string>()),
new(
"index-2021/02",
new List<string> { "page2" },
new List<string> { "index-2021/02/02" }),
new(
"index-2021/02/02",
new List<string> { "page2" },
new List<string>()),
new(
"index-2022",
new List<string> { "page3" },
new List<string> { "index-2022/01" }),
new(
"index-2022/01",
new List<string> { "page3" },
new List<string> { "index-2022/01/02" }),
new(
"index-2022/01/02",
new List<string> { "page3" },
new List<string>()),
new("page1", null, null),
new("page2", null, null),
new("page3", null, null),
};
TestHelper.CompareObjects(expected, actual);
}
[Fact]
public void YearMonthIndexes()
{
using TemporalSchedulesTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
CreateDateIndexes op = context.Resolve<CreateDateIndexes>()
.WithFormats("yyyy-MM", "yyyy")
.WithCreateIndex(this.CreateIndex);
List<Entity> input = new()
{
new Entity().Add("page1")
.Add(timekeeper.CreateInstant(2021, 1, 2)),
new Entity().Add("page2")
.Add(timekeeper.CreateInstant(2021, 2, 2)),
new Entity().Add("page3")
.Add(timekeeper.CreateInstant(2022, 1, 2)),
};
List<Tuple<string, List<string>?, List<string>?>> actual =
this.GetActual(op, input);
var expected = new List<Tuple<string, List<string>?, List<string>?>>
{
new(
"index-2021",
new List<string>(),
new List<string> { "index-2021-01", "index-2021-02" }),
new(
"index-2021-01",
new List<string> { "page1" },
new List<string>()),
new(
"index-2021-02",
new List<string> { "page2" },
new List<string>()),
new(
"index-2022",
new List<string>(),
new List<string> { "index-2022-01" }),
new(
"index-2022-01",
new List<string> { "page3" },
new List<string>()),
new("page1", null, null),
new("page2", null, null),
new("page3", null, null),
};
TestHelper.CompareObjects(expected, actual);
}
[Fact]
public void YearOnlyIndexes()
{
using TemporalSchedulesTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
CreateDateIndexes op = context.Resolve<CreateDateIndexes>()
.WithFormats("yyyy")
.WithCreateIndex(this.CreateIndex);
List<Entity> input = new()
{
new Entity().Add("page1")
.Add(timekeeper.CreateInstant(2021, 1, 2)),
new Entity().Add("page2")
.Add(timekeeper.CreateInstant(2021, 2, 2)),
new Entity().Add("page3")
.Add(timekeeper.CreateInstant(2022, 1, 2)),
};
List<Tuple<string, List<string>?, List<string>?>> actual =
this.GetActual(op, input);
var expected = new List<Tuple<string, List<string>?, List<string>?>>
{
new(
"index-2021",
new List<string> { "page1", "page2" },
new List<string>()),
new("index-2022", new List<string> { "page3" }, new List<string>()),
new("page1", null, null),
new("page2", null, null),
new("page3", null, null),
};
TestHelper.CompareObjects(expected, actual);
}
private Entity CreateIndex(DateIndex a)
{
return new Entity().Add(a)
.Add($"index-{a.Key}");
}
private List<Tuple<string, List<string>?, List<string>?>> GetActual(
CreateDateIndexes op,
List<Entity> input)
{
var actual = op.Run(input)
.Select(
x => new Tuple<string, List<string>?, List<string>?>(
x.Get<string>(),
x.GetOptional<DateIndex>()
?.Entries.Select(a => a.Get<string>())
.OrderBy(b => b)
.ToList(),
x.GetOptional<DateIndex>()
?.Indexes.Select(a => a.Get<string>())
.OrderBy(b => b)
.ToList()))
.OrderBy(x => x.Item1)
.ToList();
return actual;
}
}

View file

@ -0,0 +1,13 @@
using MfGames.TestSetup;
using Xunit.Abstractions;
namespace MfGames.Nitride.Temporal.Schedules.Tests;
public abstract class TemporalSchedulesTestBase : TestBase<TemporalTestContext>
{
protected TemporalSchedulesTestBase(ITestOutputHelper output)
: base(output)
{
}
}

View file

@ -0,0 +1,16 @@
using Autofac;
using MfGames.Nitride.Temporal.Setup;
using MfGames.Nitride.Tests;
namespace MfGames.Nitride.Temporal.Schedules.Tests;
public class TemporalTestContext : NitrideTestContext
{
/// <inheritdoc />
protected override void ConfigureContainer(ContainerBuilder builder)
{
base.ConfigureContainer(builder);
builder.RegisterModule<NitrideTemporalModule>();
}
}

View file

@ -8,13 +8,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.78.0"/>
<PackageReference Include="MfGames.Gallium" Version="0.3.0"/>
<PackageReference Include="MfGames.TestSetup" Version="1.0.6"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1"/>
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.3"/>
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="CompareNETObjects" Version="4.78.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="MfGames.TestSetup" Version="1.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.3" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
@ -26,7 +26,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MfGames.Nitride\MfGames.Nitride.csproj"/>
<ProjectReference Include="..\..\src\MfGames.Nitride\MfGames.Nitride.csproj" />
</ItemGroup>
</Project>

View file

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MfGames.Gallium" Version="0.3.0" />
<PackageReference Include="MfGames.Gallium" Version="0.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" />
<PackageReference Include="xunit" Version="2.4.2" />