コード例 #1
0
    public async Task Messages_filtered_between_specific_dates_only_include_messages_sent_between_those_dates()
    {
        // Arrange
        var after    = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
        var before   = new DateTimeOffset(2021, 08, 01, 0, 0, 0, TimeSpan.Zero);
        var filePath = _tempOutput.GetTempFilePath();

        // Act
        await new ExportChannelsCommand
        {
            Token        = Secrets.DiscordToken,
            ChannelIds   = new[] { ChannelIds.DateRangeTestCases },
            ExportFormat = ExportFormat.Json,
            OutputPath   = filePath,
            Before       = Snowflake.FromDate(before),
            After        = Snowflake.FromDate(after)
        }.ExecuteAsync(new FakeConsole());

        // Assert
        var timestamps = Json
                         .Parse(await File.ReadAllTextAsync(filePath))
                         .GetProperty("messages")
                         .EnumerateArray()
                         .Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
                         .ToArray();

        timestamps.All(t => t <before && t> after).Should().BeTrue();

        timestamps.Should().BeEquivalentTo(new[]
        {
            new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
            new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
            new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
            new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero)
        }, o =>
        {
            return(o
                   .Using <DateTimeOffset>(ctx =>
                                           ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
                                           )
                   .WhenTypeIs <DateTimeOffset>());
        });
    }