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(), NullLogger.Instance); [Theory] [InlineData(2001)] [InlineData(int.MaxValue)] public async Task Pulls_RejectOversizedRowRequestsBeforeReading(int size) { var server = Server(); var queue = Substitute.For(); var store = Substitute.For(); server.SetSiteAuditQueue(queue); server.SetOperationTrackingStore(store); var context = Substitute.For(); var audit = await Assert.ThrowsAsync(() => server.PullAuditEvents( new PullAuditEventsRequest { BatchSize = size }, context)); var calls = await Assert.ThrowsAsync(() => 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(); var audit = await Assert.ThrowsAsync(() => server.IngestAuditEvents(new(), context)); var cached = await Assert.ThrowsAsync(() => server.IngestCachedTelemetry(new(), context)); Assert.Equal(StatusCode.Unimplemented, audit.StatusCode); Assert.Equal(StatusCode.Unimplemented, cached.StatusCode); } }