fix: working on expire future instants and adding test

This commit is contained in:
Dylan R. E. Moonfire 2022-07-09 01:56:23 -05:00
parent 3cf8dc66c8
commit efb255aef2
3 changed files with 56 additions and 7 deletions

View file

@ -25,9 +25,9 @@ public partial class FilterOutFutureInstant : OperationBase
{ {
Instant now = this.Timekeeper.Clock.GetCurrentInstant(); Instant now = this.Timekeeper.Clock.GetCurrentInstant();
return input.SelectEntity<Instant>( return input.WhereEntity<Instant>(
( (
entity, _,
instant) => instant.CompareTo(now) <= 0 ? null : entity); instant) => instant.CompareTo(now) <= 0);
} }
} }

View file

@ -0,0 +1,49 @@
using System.Collections.Generic;
using Gallium;
using NodaTime;
using NodaTime.Testing;
using Xunit;
using Xunit.Abstractions;
namespace Nitride.Temporal.Tests;
public class FilterOutFutureInstantTests : TemporalTestBase
{
public FilterOutFutureInstantTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void FiltersOutFutureInstants()
{
// Create the context and set the timestamp to a constant value.
using TemporalTestContext context = this.CreateContext();
Timekeeper timekeeper = context.Resolve<Timekeeper>();
var now = Instant.FromUtc(2000, 6, 1, 0, 0);
timekeeper.Clock = new FakeClock(now);
// Create the entities.
List<Entity> input = new()
{
new Entity()
.Add("past")
.Add(Instant.FromUtc(1990, 6, 1, 0, 0)),
new Entity()
.Add("future")
.Add(Instant.FromUtc(2020, 6, 1, 0, 0)),
};
// Create the operation and run it.
FilterOutFutureInstant op = context.Resolve<FilterOutFutureInstant>();
IEnumerable<Entity> output = input.Run(op);
// Verify the values.
Entity entity = Assert.Single(output);
Assert.Equal("past", entity.Get<string>());
}
}