fix: FilterOutFutureInstant should not filter out all non-Instant components

This commit is contained in:
Dylan R. E. Moonfire 2022-07-09 20:48:12 -05:00
parent 88dc0e6fe7
commit c206cd6ef7
2 changed files with 35 additions and 4 deletions

View file

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

View file

@ -46,4 +46,33 @@ public class FilterOutFutureInstantTests : TemporalTestBase
Entity entity = Assert.Single(output);
Assert.Equal("past", entity.Get<string>());
}
[Fact]
public void KeepsNonInstant()
{
// 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("neither"),
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("neither", entity.Get<string>());
}
}