Ejemplo n.º 1
0
    internal async Task WebTransportStream_StreamTypesAreDefinedCorrectly(WebTransportStreamType type, bool canRead, bool canWrite)
    {
        var memory = new Memory <byte>(new byte[5]);
        var stream = WebTransportTestUtilities.CreateStream(type, memory);

        var streamDirectionFeature = stream.Features.GetRequiredFeature <IStreamDirectionFeature>();

        Assert.Equal(canRead, streamDirectionFeature.CanRead);
        Assert.Equal(canWrite, streamDirectionFeature.CanWrite);

        await stream.DisposeAsync();

        // test that you can't write or read from a stream after disposing
        Assert.False(streamDirectionFeature.CanRead);
        Assert.False(streamDirectionFeature.CanWrite);
    }
Ejemplo n.º 2
0
    public static WebTransportStream CreateStream(WebTransportStreamType type, Memory <byte>?memory = null)
    {
        var features = new FeatureCollection();

        features.Set <IStreamIdFeature>(new StreamId(streamCounter++));
        features.Set <IStreamDirectionFeature>(new DefaultStreamDirectionFeature(type != WebTransportStreamType.Output, type != WebTransportStreamType.Input));
        features.Set(Mock.Of <IConnectionItemsFeature>());
        features.Set(Mock.Of <IProtocolErrorCodeFeature>());

        var writer = new HttpResponsePipeWriter(new StreamWriterControl(memory));

        writer.StartAcceptingWrites();
        var transport = new DuplexPipe(new StreamReader(memory), writer);

        return(new WebTransportStream(TestContextFactory.CreateHttp3StreamContext("id", null, new TestServiceContext(), features, null, null, null, transport), type));
    }