public async Task PeekMasterDataCommandHandle_WithoutData_ReturnsNullStream() { // Arrange var request = new PeekMasterDataCommand("fake_value", Guid.NewGuid().ToString()); var warehouseDomainServiceMock = new Mock <IMarketOperatorDataDomainService>(); warehouseDomainServiceMock .Setup(x => x.GetNextUnacknowledgedMasterDataAsync( It.Is <LegacyActorId>(r => string.Equals(r.Value, request.MarketOperator, StringComparison.OrdinalIgnoreCase)), It.Is <Uuid>(r => BundleIdCheck(r, request)))) .ReturnsAsync((Bundle?)null); var target = new PeekHandler( warehouseDomainServiceMock.Object, new Mock <ILogger>().Object, new Mock <ICorrelationContext>().Object); // Act var(hasContent, _, stream, _) = await target.Handle(request, CancellationToken.None).ConfigureAwait(false); // Assert Assert.False(hasContent); Assert.Equal(0, stream.Length); await stream.DisposeAsync().ConfigureAwait(false); }
public async Task PeekCommandHandle_WithData_ReturnsDataStream() { // Arrange var bundleId = Guid.NewGuid().ToString(); var request = new PeekCommand("fake_value", bundleId); var bundleContentMock = new Mock <IBundleContent>(); bundleContentMock .Setup(x => x.OpenAsync()) .ReturnsAsync(() => new MemoryStream(new byte[] { 1, 2, 3 })); var bundle = new Bundle( new Uuid(bundleId), new LegacyActorId(new GlobalLocationNumber("fake_value")), DomainOrigin.TimeSeries, new ContentType("fake_value"), Array.Empty <Uuid>(), bundleContentMock.Object, Enumerable.Empty <string>()); var warehouseDomainServiceMock = new Mock <IMarketOperatorDataDomainService>(); warehouseDomainServiceMock .Setup(x => x.GetNextUnacknowledgedAsync( It.Is <LegacyActorId>(r => string.Equals(r.Value, request.MarketOperator, StringComparison.OrdinalIgnoreCase)), It.Is <Uuid>(r => BundleIdCheck(r, request)))) .ReturnsAsync(bundle); var target = new PeekHandler( warehouseDomainServiceMock.Object, new Mock <ILogger>().Object, new Mock <ICorrelationContext>().Object); // Act var(hasContent, bid, stream, _) = await target.Handle(request, CancellationToken.None).ConfigureAwait(false); // Assert Assert.True(hasContent); Assert.Equal(bundleId, bid); Assert.Equal(1, stream.ReadByte()); Assert.Equal(2, stream.ReadByte()); Assert.Equal(3, stream.ReadByte()); await stream.DisposeAsync().ConfigureAwait(false); }