mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
// ==========================================================================
|
|
// EnrichWithTimestampHandlerTests.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.CQRS.Commands
|
|
{
|
|
public sealed class EnrichWithTimestampHandlerTests
|
|
{
|
|
private sealed class MyNormalCommand : AggregateCommand
|
|
{
|
|
}
|
|
|
|
private sealed class MyTimestampCommand : AggregateCommand, ITimestampCommand
|
|
{
|
|
public DateTime Timestamp { get; set; }
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_set_timestamp_for_timestamp_command()
|
|
{
|
|
var utc = DateTime.Today;
|
|
var sut = new EnrichWithTimestampHandler(() => utc);
|
|
|
|
var command = new MyTimestampCommand();
|
|
|
|
var result = await sut.HandleAsync(new CommandContext(command));
|
|
|
|
Assert.False(result);
|
|
Assert.Equal(utc, command.Timestamp);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_set_with_now_datetime_for_timestamp_command()
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
var sut = new EnrichWithTimestampHandler();
|
|
|
|
var command = new MyTimestampCommand();
|
|
|
|
var result = await sut.HandleAsync(new CommandContext(command));
|
|
|
|
Assert.False(result);
|
|
Assert.True(command.Timestamp >= now && command.Timestamp <= DateTime.UtcNow);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_do_nothing_for_normal_command()
|
|
{
|
|
var utc = DateTime.Today;
|
|
var sut = new EnrichWithTimestampHandler(() => utc);
|
|
|
|
var result = await sut.HandleAsync(new CommandContext(new MyNormalCommand()));
|
|
|
|
Assert.False(result);
|
|
}
|
|
}
|
|
}
|
|
|