|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +using System.IO; |
| 17 | +using Xunit; |
| 18 | + |
| 19 | +namespace Amazon.Lambda.RuntimeSupport.UnitTests |
| 20 | +{ |
| 21 | + public class InvocationResponseTests |
| 22 | + { |
| 23 | + private const long MaxResponseSize = 20 * 1024 * 1024; |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Property 17: InvocationResponse Streaming Flag - Existing constructors set IsStreaming to false. |
| 27 | + /// Validates: Requirements 7.3, 8.1 |
| 28 | + /// </summary> |
| 29 | + [Fact] |
| 30 | + public void Constructor_WithStream_IsStreamingIsFalse() |
| 31 | + { |
| 32 | + var response = new InvocationResponse(new MemoryStream()); |
| 33 | + |
| 34 | + Assert.False(response.IsStreaming); |
| 35 | + Assert.Null(response.ResponseStream); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void Constructor_WithStreamAndDispose_IsStreamingIsFalse() |
| 40 | + { |
| 41 | + var response = new InvocationResponse(new MemoryStream(), false); |
| 42 | + |
| 43 | + Assert.False(response.IsStreaming); |
| 44 | + Assert.Null(response.ResponseStream); |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Property 17: InvocationResponse Streaming Flag - CreateStreamingResponse sets IsStreaming to true. |
| 49 | + /// Validates: Requirements 7.3, 8.1 |
| 50 | + /// </summary> |
| 51 | + [Fact] |
| 52 | + public void CreateStreamingResponse_SetsIsStreamingTrue() |
| 53 | + { |
| 54 | + var stream = new ResponseStream(MaxResponseSize); |
| 55 | + |
| 56 | + var response = InvocationResponse.CreateStreamingResponse(stream); |
| 57 | + |
| 58 | + Assert.True(response.IsStreaming); |
| 59 | + } |
| 60 | + |
| 61 | + [Fact] |
| 62 | + public void CreateStreamingResponse_SetsResponseStream() |
| 63 | + { |
| 64 | + var stream = new ResponseStream(MaxResponseSize); |
| 65 | + |
| 66 | + var response = InvocationResponse.CreateStreamingResponse(stream); |
| 67 | + |
| 68 | + Assert.Same(stream, response.ResponseStream); |
| 69 | + } |
| 70 | + |
| 71 | + [Fact] |
| 72 | + public void CreateStreamingResponse_DoesNotDisposeOutputStream() |
| 73 | + { |
| 74 | + var stream = new ResponseStream(MaxResponseSize); |
| 75 | + |
| 76 | + var response = InvocationResponse.CreateStreamingResponse(stream); |
| 77 | + |
| 78 | + Assert.False(response.DisposeOutputStream); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments