47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
using Grpc.Core;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Grpc;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
public class LowReviewTransportTests
|
|
{
|
|
private static SiteStreamGrpcServer Server() => new(
|
|
Substitute.For<ISiteStreamSubscriber>(), NullLogger<SiteStreamGrpcServer>.Instance);
|
|
|
|
[Theory]
|
|
[InlineData(2001)]
|
|
[InlineData(int.MaxValue)]
|
|
public async Task Pulls_RejectOversizedRowRequestsBeforeReading(int size)
|
|
{
|
|
var server = Server();
|
|
var queue = Substitute.For<ISiteAuditQueue>();
|
|
var store = Substitute.For<IOperationTrackingStore>();
|
|
server.SetSiteAuditQueue(queue);
|
|
server.SetOperationTrackingStore(store);
|
|
var context = Substitute.For<ServerCallContext>();
|
|
var audit = await Assert.ThrowsAsync<RpcException>(() => server.PullAuditEvents(
|
|
new PullAuditEventsRequest { BatchSize = size }, context));
|
|
var calls = await Assert.ThrowsAsync<RpcException>(() => server.PullSiteCalls(
|
|
new PullSiteCallsRequest { BatchSize = size }, context));
|
|
Assert.Equal(StatusCode.InvalidArgument, audit.StatusCode);
|
|
Assert.Equal(StatusCode.InvalidArgument, calls.StatusCode);
|
|
Assert.Empty(queue.ReceivedCalls());
|
|
Assert.Empty(store.ReceivedCalls());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RetiredSiteIngestRpcs_ReturnUnimplementedEvenForEmptyBatches()
|
|
{
|
|
var server = Server();
|
|
var context = Substitute.For<ServerCallContext>();
|
|
var audit = await Assert.ThrowsAsync<RpcException>(() => server.IngestAuditEvents(new(), context));
|
|
var cached = await Assert.ThrowsAsync<RpcException>(() => server.IngestCachedTelemetry(new(), context));
|
|
Assert.Equal(StatusCode.Unimplemented, audit.StatusCode);
|
|
Assert.Equal(StatusCode.Unimplemented, cached.StatusCode);
|
|
}
|
|
}
|