public async Task SetsLocationHeader(JSendUnauthorizedResult result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.Headers.WwwAuthenticate.Should().BeEquivalentTo(result.Challenges);
        }
        public async Task SetsContentTypeHeader(JSendUnauthorizedResult result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
        }
        public async Task SetsStatusCode(JSendUnauthorizedResult result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.StatusCode.Should().Be(result.StatusCode);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes requests that fail authorization by creating a JSend formatted <see cref="HttpStatusCode.Unauthorized"/> result.
        /// </summary>
        /// <param name="actionContext">The context.</param>
        protected override void HandleUnauthorizedRequest(HttpActionContext actionContext)
        {
            if (actionContext == null) throw new ArgumentNullException(nameof(actionContext));
            Contract.Assert(actionContext.ControllerContext != null);

            var result = new JSendUnauthorizedResult(
                Enumerable.Empty<AuthenticationHeaderValue>(), actionContext.Request);

            actionContext.Response = result.ExecuteAsync(CancellationToken.None).Result;
        }
        public async Task ResponseIsSerializedIntoBody(JSendUnauthorizedResult result)
        {
            // Fixture setup
            var serializedResponse = JsonConvert.SerializeObject(result.Response);
            // Exercise system
            var httpResponse = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            var content = await httpResponse.Content.ReadAsStringAsync();

            content.Should().Be(serializedResponse);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Processes requests that fail authorization by creating a JSend formatted <see cref="HttpStatusCode.Unauthorized"/> result.
        /// </summary>
        /// <param name="actionContext">The context.</param>
        protected override void HandleUnauthorizedRequest(HttpActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }
            Contract.Assert(actionContext.ControllerContext != null);

            var result = new JSendUnauthorizedResult(
                Enumerable.Empty <AuthenticationHeaderValue>(), actionContext.Request);

            actionContext.Response = result.ExecuteAsync(CancellationToken.None).Result;
        }
 public async Task ResponseIsSerializedIntoBody(JSendUnauthorizedResult result)
 {
     // Fixture setup
     var serializedResponse = JsonConvert.SerializeObject(result.Response);
     // Exercise system
     var httpResponseMessage = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     var content = await httpResponseMessage.Content.ReadAsStringAsync();
     content.Should().Be(serializedResponse);
 }
 public async Task SetsLocationHeader(JSendUnauthorizedResult result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.Headers.WwwAuthenticate.Should().BeEquivalentTo(result.Challenges);
 }
 public async Task SetsContentTypeHeader(JSendUnauthorizedResult result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
 }
 public async Task SetsStatusCode(JSendUnauthorizedResult result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.StatusCode.Should().Be(result.StatusCode);
 }