2021-02-15 07:46:19 +00:00
|
|
|
using System.IO;
|
|
|
|
using INetMock.Client.Audit;
|
2021-02-20 14:18:08 +00:00
|
|
|
using INetMock.Client.Audit.Serialization;
|
2021-02-15 07:46:19 +00:00
|
|
|
using INetMock.Client.Test.Hex;
|
|
|
|
using Xunit;
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
namespace INetMock.Client.Test.Audit.Serialization;
|
|
|
|
|
|
|
|
public class GenericReaderTest
|
2021-02-15 07:46:19 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
private const string HttpEventPayload = "000000a7120b088092b8c398feffffff01180120022a047f00000132047f00000138d8fc0140504a3308041224544c535f45434448455f45434453415f574954485f4145535f3235365f4342435f5348411a096c6f63616c686f7374a2014c080112096c6f63616c686f73741a15687474703a2f2f6c6f63616c686f73742f6173646622084854545020312e312a1c0a0641636365707412120a106170706c69636174696f6e2f6a736f6e";
|
|
|
|
private const string DnsEventPayload = "0000004e120b088092b8c398feffffff01180220012a100000000000000000000000000000000132100000000000000000000000000000000138d8fc014050aa0110120e0801120a6769746c61622e636f6d";
|
2021-02-15 07:46:19 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
private readonly byte[] _httpEventPayloadBytes;
|
|
|
|
private readonly byte[] _dnsEventPayloadBytes;
|
2021-02-15 07:46:19 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
public GenericReaderTest()
|
|
|
|
{
|
|
|
|
_httpEventPayloadBytes = HttpEventPayload.HexToByteArray();
|
|
|
|
_dnsEventPayloadBytes = DnsEventPayload.HexToByteArray();
|
|
|
|
}
|
2021-02-15 07:46:19 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
[Fact]
|
|
|
|
public async void TestRead_HttpEvent_Success()
|
|
|
|
{
|
|
|
|
await using var protoReader = new ProtoReader(new MemoryStream(_httpEventPayloadBytes));
|
|
|
|
await using IEventReader reader = new GenericReader(protoReader);
|
|
|
|
await foreach (var ev in reader.ReadAllAsync())
|
2021-02-15 07:46:19 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
Assert.NotNull(ev);
|
|
|
|
Assert.NotNull(ev.Details);
|
|
|
|
|
|
|
|
Assert.NotNull(ev.DetailsAs<HttpDetails>());
|
|
|
|
Assert.Null(ev.DetailsAs<DnsDetails>());
|
|
|
|
|
|
|
|
var httpEvent = (Event<HttpDetails>)ev;
|
|
|
|
Assert.NotNull(httpEvent);
|
|
|
|
Assert.NotNull(httpEvent.Details);
|
2021-02-15 07:46:19 +00:00
|
|
|
}
|
2022-01-26 14:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async void TestRead_DnsEvent_Success()
|
|
|
|
{
|
|
|
|
await using var memStream = new MemoryStream(_dnsEventPayloadBytes);
|
|
|
|
await using var protoReader = new ProtoReader(new MemoryStream(_dnsEventPayloadBytes));
|
|
|
|
await using IEventReader reader = new GenericReader(protoReader);
|
|
|
|
await foreach (var ev in reader.ReadAllAsync())
|
2021-02-15 07:46:19 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
Assert.NotNull(ev);
|
|
|
|
Assert.NotNull(ev.Details);
|
|
|
|
Assert.NotNull(ev.DetailsAs<DnsDetails>());
|
|
|
|
|
|
|
|
var dnsEvent = (Event<DnsDetails>)ev;
|
|
|
|
Assert.NotNull(dnsEvent);
|
|
|
|
Assert.NotNull(dnsEvent.Details);
|
2021-02-15 07:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|