~ruther/NosSmooth

ref: 994aad0e431e34fae3d1bc656a436ae07de98efd NosSmooth/Tests/NosSmooth.Core.Tests/Fakes/Packets/FakePacketHandler.cs -rw-r--r-- 1.2 KiB
994aad0e — František Boháček feat(packets): make vnum int 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
//  FakePacketHandler.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using NosSmooth.Core.Packets;
using NosSmooth.Packets;
using Remora.Results;

namespace NosSmooth.Core.Tests.Fakes.Packets;

/// <summary>
/// Fake Responder of a packet.
/// </summary>
/// <typeparam name="TPacket">The packet to respond to.</typeparam>
public class FakePacketResponder<TPacket> : IPacketResponder<TPacket>
    where TPacket : IPacket
{
    private readonly Func<PacketEventArgs<TPacket>, Result> _handler;

    /// <summary>
    /// Initializes a new instance of the <see cref="FakePacketResponder{TPacket}"/> class.
    /// </summary>
    /// <param name="handler">The function respond handler.</param>
    public FakePacketResponder(Func<PacketEventArgs<TPacket>, Result> handler)
    {
        _handler = handler;
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<TPacket> packetArgs, CancellationToken ct = default)
        => Task.FromResult(_handler(packetArgs));
}
Do not follow this link