Exemplo n.º 1
0
        public async Task ValidateBuildRequest()
        {
            var stream = new TestableStream();
            await s_emptyCSharpBuildRequest.WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);

            stream.ReadStream.Position = 0;

            var validated  = false;
            var connection = CreateConnection(stream);

            connection.ServeBuildRequestFunc    = (req, token) => Task.FromResult(s_emptyBuildResponse);
            connection.ValidateBuildRequestFunc = _ => { validated = true; };
            await connection.HandleConnection().ConfigureAwait(true);

            Assert.True(validated);
        }
Exemplo n.º 2
0
        public async Task NoCompilationsProcessShutdown()
        {
            var stream = new TestableStream();
            await BuildRequest.CreateShutdown().WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);

            stream.ReadStream.Position = 0;

            var connection     = CreateConnection(stream);
            var connectionData = await connection.HandleConnection(allowCompilationRequests : false).ConfigureAwait(false);

            Assert.Equal(CompletionReason.ClientShutdownRequest, connectionData.CompletionReason);

            stream.WriteStream.Position = 0;
            var response = await BuildResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);

            Assert.Equal(BuildResponse.ResponseType.Shutdown, response.Type);
        }
Exemplo n.º 3
0
        public async Task NoCompilationsRejectBuildRequest()
        {
            var stream = new TestableStream();
            await s_emptyCSharpBuildRequest.WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);

            stream.ReadStream.Position = 0;

            var connection     = CreateConnection(stream);
            var connectionData = await connection.HandleConnection(allowCompilationRequests : false).ConfigureAwait(false);

            Assert.Equal(CompletionReason.CompilationNotStarted, connectionData.CompletionReason);

            stream.WriteStream.Position = 0;
            var response = await BuildResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);

            Assert.Equal(BuildResponse.ResponseType.Rejected, response.Type);
        }
        public async Task AcceptConnection_ShutdownRequest_ReturnsShutdownResponse()
        {
            // Arrange
            var stream = new TestableStream();
            await ServerRequest.CreateShutdown().WriteAsync(stream.ReadStream, CancellationToken.None);

            stream.ReadStream.Position = 0;

            var connection     = CreateConnection(stream);
            var connectionHost = CreateConnectionHost();
            var compilerHost   = CreateCompilerHost();
            var dispatcher     = new DefaultRequestDispatcher(connectionHost, compilerHost, CancellationToken.None);

            // Act
            var connectionResult = await dispatcher.AcceptConnection(
                Task.FromResult <Connection>(connection), accept : true, cancellationToken : CancellationToken.None);

            // Assert
            Assert.Equal(ConnectionResult.Reason.ClientShutdownRequest, connectionResult.CloseReason);
            stream.WriteStream.Position = 0;
            var response = await ServerResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);

            Assert.Equal(ServerResponse.ResponseType.Shutdown, response.Type);
        }
        public async Task AcceptConnection_AcceptFalse_RejectsBuildRequest()
        {
            // Arrange
            var stream = new TestableStream();
            await EmptyServerRequest.WriteAsync(stream.ReadStream, CancellationToken.None);

            stream.ReadStream.Position = 0;

            var connection     = CreateConnection(stream);
            var connectionHost = CreateConnectionHost();
            var compilerHost   = CreateCompilerHost();
            var dispatcher     = new DefaultRequestDispatcher(connectionHost, compilerHost, CancellationToken.None);

            // Act
            var connectionResult = await dispatcher.AcceptConnection(
                Task.FromResult <Connection>(connection), accept : false, cancellationToken : CancellationToken.None);

            // Assert
            Assert.Equal(ConnectionResult.Reason.CompilationNotStarted, connectionResult.CloseReason);
            stream.WriteStream.Position = 0;
            var response = await ServerResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);

            Assert.Equal(ServerResponse.ResponseType.Rejected, response.Type);
        }
Exemplo n.º 6
0
        public async Task NoCompilationsProcessShutdown()
        {
            var stream = new TestableStream();
            await BuildRequest.CreateShutdown().WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);
            stream.ReadStream.Position = 0;

            var connection = CreateConnection(stream);
            var connectionData = await connection.HandleConnection(allowCompilationRequests: false).ConfigureAwait(false);
            Assert.Equal(CompletionReason.ClientShutdownRequest, connectionData.CompletionReason);

            stream.WriteStream.Position = 0;
            var response = await BuildResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);
            Assert.Equal(BuildResponse.ResponseType.Shutdown, response.Type);
        }
Exemplo n.º 7
0
        public async Task NoCompilationsRejectBuildRequest()
        {
            var stream = new TestableStream();
            await s_emptyCSharpBuildRequest.WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);
            stream.ReadStream.Position = 0;

            var connection = CreateConnection(stream);
            var connectionData = await connection.HandleConnection(allowCompilationRequests: false).ConfigureAwait(false);
            Assert.Equal(CompletionReason.CompilationNotStarted, connectionData.CompletionReason);

            stream.WriteStream.Position = 0;
            var response = await BuildResponse.ReadAsync(stream.WriteStream).ConfigureAwait(false);
            Assert.Equal(BuildResponse.ResponseType.Rejected, response.Type);
        }
Exemplo n.º 8
0
        public async Task ValidateBuildRequest()
        {
            var stream = new TestableStream();
            await s_emptyCSharpBuildRequest.WriteAsync(stream.ReadStream, CancellationToken.None).ConfigureAwait(true);
            stream.ReadStream.Position = 0;

            var validated = false;
            var connection = CreateConnection(stream);
            connection.ServeBuildRequestFunc = (req, token) => Task.FromResult(s_emptyBuildResponse);
            connection.ValidateBuildRequestFunc = _ => { validated = true; };
            await connection.HandleConnection().ConfigureAwait(true);

            Assert.True(validated);
        }