Ejemplo n.º 1
0
        public async Task ExecuteResultAsync_SetsStatusCodeAndLocationHeader()
        {
            // Arrange
            var location      = "/test/";
            var formatter     = CreateMockFormatter();
            var httpContext   = GetHttpContext(formatter);
            var actionContext = GetActionContext(httpContext);

            // Act
            var result = new AcceptedResult(location, "testInput");
            await result.ExecuteResultAsync(actionContext);

            // Assert
            Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode);
            Assert.Equal(location, httpContext.Response.Headers["Location"]);
        }
Ejemplo n.º 2
0
        public async Task ExecuteResultAsync_SetsObjectValueOfFormatter(object value)
        {
            // Arrange
            var    location    = "/test/";
            var    formatter   = CreateMockFormatter();
            var    httpContext = GetHttpContext(formatter);
            object actual      = null;

            formatter.Setup(f => f.WriteAsync(It.IsAny <OutputFormatterWriteContext>()))
            .Callback((OutputFormatterWriteContext context) => actual = context.Object)
            .Returns(Task.FromResult(0));

            var actionContext = GetActionContext(httpContext);

            // Act
            var result = new AcceptedResult(location, value);
            await result.ExecuteResultAsync(actionContext);

            // Assert
            Assert.Same(value, actual);
        }