コード例 #1
0
    public async Task DisconnectMiddleware_OnlyAccepts_PostRequests(string httpMethod)
    {
        // Arrange
        var circuitIdFactory = TestCircuitIdFactory.CreateTestFactory();
        var registry         = new CircuitRegistry(
            Options.Create(new CircuitOptions()),
            NullLogger <CircuitRegistry> .Instance,
            circuitIdFactory);

        var middleware = new CircuitDisconnectMiddleware(
            NullLogger <CircuitDisconnectMiddleware> .Instance,
            registry,
            circuitIdFactory,
            (ctx) => Task.CompletedTask);

        var context = new DefaultHttpContext();

        context.Request.Method = httpMethod;

        // Act
        await middleware.Invoke(context);

        // Assert
        Assert.Equal(StatusCodes.Status405MethodNotAllowed, context.Response.StatusCode);
    }
コード例 #2
0
    public async Task Returns400BadRequest_IfNoCircuitIdOnForm()
    {
        // Arrange
        var circuitIdFactory = TestCircuitIdFactory.CreateTestFactory();
        var registry         = new CircuitRegistry(
            Options.Create(new CircuitOptions()),
            NullLogger <CircuitRegistry> .Instance,
            circuitIdFactory);

        var middleware = new CircuitDisconnectMiddleware(
            NullLogger <CircuitDisconnectMiddleware> .Instance,
            registry,
            circuitIdFactory,
            (ctx) => Task.CompletedTask);

        var context = new DefaultHttpContext();

        context.Request.Method      = HttpMethods.Post;
        context.Request.ContentType = "application/x-www-form-urlencoded";

        // Act
        await middleware.Invoke(context);

        // Assert
        Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
    }
コード例 #3
0
    public async Task Returns200OK_NonExistingCircuit()
    {
        // Arrange
        var circuitIdFactory = TestCircuitIdFactory.CreateTestFactory();
        var circuitId        = circuitIdFactory.CreateCircuitId();
        var registry         = new CircuitRegistry(
            Options.Create(new CircuitOptions()),
            NullLogger <CircuitRegistry> .Instance,
            circuitIdFactory);

        var middleware = new CircuitDisconnectMiddleware(
            NullLogger <CircuitDisconnectMiddleware> .Instance,
            registry,
            circuitIdFactory,
            (ctx) => Task.CompletedTask);

        using var memory = new MemoryStream();
        await new FormUrlEncodedContent(new Dictionary <string, string> {
            ["circuitId"] = circuitId.Secret,
        }).CopyToAsync(memory);
        memory.Seek(0, SeekOrigin.Begin);

        var context = new DefaultHttpContext();

        context.Request.Method      = HttpMethods.Post;
        context.Request.ContentType = "application/x-www-form-urlencoded";
        context.Request.Body        = memory;

        // Act
        await middleware.Invoke(context);

        // Assert
        Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
    }