public async Task ShouldStart()
        {
            var            fileName       = "test";
            ILambdaContext context        = null;
            var            lambdaFunction = new LambdaEntryPoint();

            var requestStr = @"{""Path"": ""/Test/Index"",
    ""HttpMethod"": ""GET"",
    ""Headers"": {
        ""accept"": ""text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"",
        ""accept-encoding"": ""gzip, deflate, br"",
        ""accept-language"": ""en-US,en;q=0.9"",
    },
    ""QueryStringParameters"": {},
    ""MultiValueQueryStringParameters"": null,
    ""Body"": """",
    ""IsBase64Encoded"": true
}";

            var request = JsonConvert.DeserializeObject <ApplicationLoadBalancerRequest>(requestStr);

            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Example #2
0
        public async Task TestUrls()
        {
            // ARRANGE
            CloudWatchScheduledEvent Event = new CloudWatchScheduledEvent(
                "0",
                Guid.Parse("125e7841-c049-462d-86c2-4efa5f64e293"),
                "123456789012",
                DateTime.Parse("2016-12-16T19:55:42Z"),
                "us-east-1",
                new string[] { "arn:aws:events:us-east-1:415720405880:rule/AreWeUp-TestUrls-X2YM3334N4JN" },
                new object()
                );

            TestLambdaLogger  TestLogger    = new TestLambdaLogger();
            TestClientContext ClientContext = new TestClientContext();

            ClientContext.Environment.Add("ConfigBucket", _Bucket);
            ClientContext.Environment.Add("ConfigKey", _ObjectKey);

            TestLambdaContext Context = new TestLambdaContext()
            {
                FunctionName    = "AreWeUp",
                FunctionVersion = "1",
                Logger          = TestLogger,
                ClientContext   = ClientContext
            };

            LambdaEntryPoint Func = new LambdaEntryPoint();

            // ACT
            await Func.ExecuteHealthChecks(Event, Context);

            // ASSERT
            Assert.True(true);
        }
        public void TestGetIdException()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var request = GetTestRequest("./SampleRequests/ValuesController-GetNegativeId.json");
            var context = new TestLambdaContext
            {
                FunctionName       = "ServerlessFunction",
                InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1",
            };

            APIGatewayProxyResponse response = null;
            var spans = BackendMock.CollectSpans(
                async() => response = await lambdaFunction.FunctionHandlerAsync(request, context));

            // Check response.
            Assert.Equal(500, response.StatusCode);

            // Check trace.
            Assert.Single(spans);
            var span = spans.First();

            Assert.Equal("api/Values/{id}", span.Name);
            Assert.True(span.Tags.TryGetValue("error", out var errorValue));
            Assert.Equal("true", errorValue);
            Assert.True(span.Tags.TryGetValue("sfx.error.kind", out var actualErrorKind));
            Assert.Equal(typeof(ArgumentOutOfRangeException).FullName, actualErrorKind);
        }
        public void TestGet()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var request = GetTestRequest("./SampleRequests/ValuesController-Get.json");
            var context = new TestLambdaContext
            {
                FunctionName       = "ServerlessFunction",
                InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1",
            };

            APIGatewayProxyResponse response = null;
            var spans = BackendMock.CollectSpans(
                async() => response = await lambdaFunction.FunctionHandlerAsync(request, context));

            // Check response.
            Assert.Equal(200, response.StatusCode);
            Assert.Equal("[\"value1\",\"value2\"]", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);

            // Check trace.
            Assert.Single(spans);
            var span = spans.First();

            Assert.Equal("api/Values", span.Name);
            Assert.True(span.Tags.TryGetValue("span.kind", out var spanKind));
            Assert.Equal("server", spanKind);
            Assert.True(span.Tags.TryGetValue("http.method", out var httpMethod));
            Assert.Equal("GET", httpMethod);
        }
        public void SetUp()
        {
            Environment.SetEnvironmentVariable("RemainingTimeThresholdSeconds", "10");
            Environment.SetEnvironmentVariable(nameof(ConnectionString), ConnectionString);

            _lambdaEntryPoint = new LambdaEntryPoint();
        }
Example #6
0
        public async Task TestGet(decimal balance)
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/ValuesController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);

            request.PathParameters["proxy"] += balance;

            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            var result = JsonConvert.DeserializeObject <decimal>(response.Body);

            Debug.WriteLine($"Balance: { balance } - Interest Rate: { result }");


            if (balance < 1000)
            {
                Assert.Equal(result, Math.Round(balance * 0.01m, 2));
            }
            else if (balance >= 1000 && balance < 5000)
            {
                Assert.Equal(result, Math.Round(balance * 0.015m, 2));
            }
            else if (balance >= 5000 && balance < 10000)
            {
                Assert.Equal(result, Math.Round(balance * 0.02m, 2));
            }
            else
            {
                Assert.Equal(result, Math.Round(balance * 0.03m, 2));
            }
        }
        public async Task TestSuccessWorkFlow()
        {
            Startup.Configuration[Startup.AppS3BucketKey] = this.BucketName;
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/ValuesController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);
        }
        public void TestGetId()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var request = GetTestRequest("./SampleRequests/ValuesController-GetId.json");
            var context = new TestLambdaContext
            {
                FunctionName       = "ServerlessFunction",
                InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1",
            };

            APIGatewayProxyResponse    response = null;
            IImmutableList <IMockSpan> spans    = null;
            const string propagatedTraceId      = "0123456789abceff";
            const string parentSpanId           = "0123456789abceff";

            try
            {
                TelemetryConfiguration.ContextPropagationEnabled = true;
                request.Headers = new Dictionary <string, string>
                {
                    { HttpHeaderNames.B3TraceId, propagatedTraceId },
                    { HttpHeaderNames.B3SpanId, parentSpanId },
                    { HttpHeaderNames.B3Sampled, "1" },
                };

                spans = BackendMock.CollectSpans(
                    async() => response = await lambdaFunction.FunctionHandlerAsync(request, context));
            }
            finally
            {
                TelemetryConfiguration.ContextPropagationEnabled = false;
            }

            // Check response.
            Assert.Equal(200, response.StatusCode);
            Assert.Equal("value_56", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("text/plain; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);

            // Check trace.
            Assert.Single(spans);
            var span = spans.First();

            Assert.Equal("api/Values/{id}", span.Name);
            Assert.True(span.Tags.TryGetValue("span.kind", out var spanKind));
            Assert.Equal("server", spanKind);
            Assert.True(span.Tags.TryGetValue("http.method", out var httpMethod));
            Assert.Equal("GET", httpMethod);

            // Check context propagation.
            Assert.True(span.ParentId.HasValue);
            Assert.Equal(propagatedTraceId, span.TraceId.ToString("x16"));
            Assert.Equal(parentSpanId, span.ParentId.Value.ToString("x16"));
        }
Example #9
0
        public async Task TestPost()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/RegistrationController-Post.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
        }
        public async Task TestGet(string requestJsonFileName)
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText($"./SampleRequests/{requestJsonFileName}");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.AreEqual(200, response.StatusCode);
        }
Example #11
0
        public async Task TestGetByCoordindates()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/SheetsController-GetByCoordinates.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("[{\"name\":\"Mardin-N47-b-17\",\"lat\":37.3,\"lon\":41.8,\"scale\":10}]", response.Body);
        }
Example #12
0
        public async Task TestGetByName()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/SheetsController-GetByName.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("{\"name\":\"Kırşehir-I31-a-20-d-4-a\",\"lat\":39.80625,\"lon\":33.7,\"scale\":1}", response.Body);
        }
        public void CanCreate()
        {
            System.Environment.SetEnvironmentVariable("TimeoutSqsSeconds", "10");
            System.Environment.SetEnvironmentVariable("SqsQueueUrl", "http://queue");
            System.Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "50");
            System.Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "50");
            System.Environment.SetEnvironmentVariable("AWS_SESSION_TOKEN", "50");

            LambdaEntryPoint lambdaEntry = new LambdaEntryPoint();

            Assert.That(lambdaEntry, Is.Not.Null);
        }
        public async Task TestGetMetaDataTest()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/StockController-GetMeta.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            var stockMeta = System.Text.Json.JsonSerializer.Deserialize <StockMeta[]>(response.Body);

            Assert.Equal(200, response.StatusCode);
        }
        public void CanCreateLambdaEntryPoint()
        {
            Environment.SetEnvironmentVariable("RemainingTimeThresholdSeconds", "10");
            Environment.SetEnvironmentVariable("SqsQueueUrl", "http://");
            Environment.SetEnvironmentVariable("TimeoutSqsSeconds", "10");
            Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "50");
            Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "50");
            Environment.SetEnvironmentVariable("AWS_SESSION_TOKEN", "50");

            LambdaEntryPoint lambdaEntryPoint = new LambdaEntryPoint();

            Assert.That(lambdaEntryPoint, Is.Not.Null);
        }
Example #16
0
        public async Task TestGet()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/ValuesController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }
        public async Task <APIGatewayProxyResponse> FunctionHandlerAsync(string jsonRequestPath)
        {
            var lambdaFunction = new LambdaEntryPoint();
            var context        = new TestLambdaContext();

            var fullPath   = Path.Combine(AppContext.BaseDirectory, "../../../", jsonRequestPath);
            var requestStr = File.ReadAllText(fullPath);
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);

            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            return(response);
        }
        public async Task TestGetWithoutAuthorization()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText(Directory.GetCurrentDirectory() + "/Requests/ValuesController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayAuthorizerProxyRequest>(requestStr);

            request.RequestContext.Authorizer = null;
            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(response.StatusCode, StatusCodes.Status401Unauthorized);
        }
        public async Task TestSuccessWorkFlow()
        {
            var lambdaFunction = new LambdaEntryPoint();

            Startup.Configuration[Startup.AppS3BucketKey] = this.BucketName;


            // Use sample API Gateway request that uploads an object with object key "foo.txt" and content of "Hello World".
            var requestStr = File.ReadAllText("./SampleRequests/S3ProxyController-Put.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);

            // Get with no object key in the resource path does an object list call
            requestStr = File.ReadAllText("./SampleRequests/S3ProxyController-Get.json");
            request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            context    = new TestLambdaContext();
            response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("text/json", response.MultiValueHeaders["Content-Type"][0]);
            Assert.Contains("foo.txt", response.Body);

            // Return the content of the new s3 object foo.txt
            requestStr = File.ReadAllText("./SampleRequests/S3ProxyController-GetByKey.json");
            request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            context    = new TestLambdaContext();
            response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("text/plain", response.MultiValueHeaders["Content-Type"][0]);
            Assert.Equal("Hello World", response.Body);

            // Delete the object
            requestStr = File.ReadAllText("./SampleRequests/S3ProxyController-Delete.json");
            request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            context    = new TestLambdaContext();
            response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);

            // Make sure the object was deleted
            requestStr = File.ReadAllText("./SampleRequests/S3ProxyController-GetByKey.json");
            request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            context    = new TestLambdaContext();
            response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(404, response.StatusCode);
        }
        public async Task TestGetWithAuthorization()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText(Directory.GetCurrentDirectory() + "/Requests/ValuesController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayAuthorizerProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(response.StatusCode, 200);
            Assert.Equal("[\"value1\",\"value2\"]", response.Body);
            Assert.True(response.Headers.ContainsKey("Content-Type"));
            Assert.Equal("application/json; charset=utf-8", response.Headers["Content-Type"]);
        }
Example #21
0
        public async Task HealthCheck_Should_Return_Ok_With_String_Message()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/KeepAliveController-Get.json");
            var request    = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context    = new TestLambdaContext();
            var response   = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("OK!", response.Body);
            Assert.True(response.Headers.ContainsKey("Content-Type"));
            Assert.Equal("application/json; charset=utf-8", response.Headers["Content-Type"]);
        }
Example #22
0
        public async Task TestNotification()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/Notification.json");
            var request = JsonConvert.DeserializeObject<APIGatewayProxyRequest>(requestStr);
            var context = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            // extract the person from the response body
            var person = JsonConvert.DeserializeObject<Person>(response.Body);
            Assert.Equal(response.StatusCode, 200);
            Assert.Equal(person.Name, "John");
            Assert.Equal(person.Surname, "Doe");
        }
Example #23
0
        public async Task TestConfirmation()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = File.ReadAllText("./SampleRequests/SubscriptionConfirmation.json");
            var request = JsonConvert.DeserializeObject<APIGatewayProxyRequest>(requestStr);
            var context = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            // return the length of the body received by the GET request of the 
            // confirmationUrl
            // http://example.com
            Assert.True(int.Parse(response.Body) > 0);
            Assert.Equal(response.StatusCode, 200);
        }
Example #24
0
        public async Task TestGet()
        {
            var lambdaFunction = new LambdaEntryPoint();

            var requestStr = await File.ReadAllTextAsync("./SampleRequests/BattleshipStateTrackerController-Get.json");

            var request  = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("[\"This is the Battleship State Tracker\",\"You can call APIs to create a board, add a ship and attack\"]", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }
Example #25
0
        public async Task TestAttackHit()
        {
            var lambdaFunction = new LambdaEntryPoint();
            var requestStr     = await File.ReadAllTextAsync("./SampleRequests/BattleshipStateTrackerController-Attack.json");

            var request = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);

            request.Headers = _headers;
            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("Hit", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("text/plain; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }
Example #26
0
    public async Task TestGet()
    {
        var lambdaFunction = new LambdaEntryPoint();

        var requestStr = File.ReadAllText("./SampleRequests/ValuesController-Get.json");
        var request    = JsonSerializer.Deserialize <APIGatewayProxyRequest>(requestStr, new JsonSerializerOptions
        {
            PropertyNameCaseInsensitive = true
        });
        var context  = new TestLambdaContext();
        var response = await lambdaFunction.FunctionHandlerAsync(request, context);

        Assert.Equal(200, response.StatusCode);
        Assert.Equal("[\"value1\",\"value2\"]", response.Body);
        Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
        Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
    }
Example #27
0
        public async Task TestAttackOutsideBoard()
        {
            var lambdaFunction = new LambdaEntryPoint();
            var requestStr     = await File.ReadAllTextAsync("./SampleRequests/BattleshipStateTrackerController-Attack.json");

            var request = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);

            request.Body    = "{\"boardName\":\"Bimal1\",\"attackPosition\":{\"xPosition\":14,\"yPosition\":7}}";
            request.Headers = _headers;
            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("Invalid attack position, please check orientation and position and try again", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("text/plain; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }
Example #28
0
 public static void Main(string[] args)
 {
     if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME")))
     {
         CreateHostBuilder(args).Build().Run();
     }
     else
     {
         var lambdaEntry     = new LambdaEntryPoint();
         var functionHandler = (Func <APIGatewayProxyRequest, ILambdaContext, Task <APIGatewayProxyResponse> >)(lambdaEntry.FunctionHandlerAsync);
         using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(functionHandler, new JsonSerializer()))
             using (var bootstrap = new LambdaBootstrap(handlerWrapper))
             {
                 bootstrap.RunAsync().Wait();
             }
     }
 }
Example #29
0
        public async Task TestAddShipHorizontalOrientation()
        {
            var lambdaFunction = new LambdaEntryPoint();
            var requestStr     = await File.ReadAllTextAsync("./SampleRequests/BattleshipStateTrackerController-AddShip.json");

            var request = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);

            request.Body =
                "{\n    \"boardName\": \"Bimal1\",\n    \"orientation\": \"horizontal\",\n   \"shipName\": \"HMAS Canberra1\",\n    \"startPosition\": {\n        \"xPosition\": 1,\n        \"yPosition\": 3\n    },\n    \"endPosition\": {\n        \"xPosition\": 4,\n        \"yPosition\": 3\n    }\n}";
            request.Headers = _headers;
            var context  = new TestLambdaContext();
            var response = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("success", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.Equal("text/plain; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }
Example #30
0
        public async Task Test_GetItem_NullReference_Post()
        {
            var lambdaFunction = new LambdaEntryPoint();
            var requestStr     = File.ReadAllText("./SampleRequests/BasketController-GetItem-NullRequest-Post.json");
            var request        = JsonConvert.DeserializeObject <APIGatewayProxyRequest>(requestStr);
            var context        = new TestLambdaContext();
            var response       = await lambdaFunction.FunctionHandlerAsync(request, context);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("[]", response.Body);
            Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type"));
            Assert.True(response.MultiValueHeaders.ContainsKey("Access-Control-Allow-Headers"));
            Assert.True(response.MultiValueHeaders.ContainsKey("Access-Control-Allow-Origin"));
            Assert.True(response.MultiValueHeaders.ContainsKey("Access-Control-Allow-Methods"));
            Assert.Equal("Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token", response.MultiValueHeaders["Access-Control-Allow-Headers"][0]);
            Assert.Equal("*", response.MultiValueHeaders["Access-Control-Allow-Origin"][0]);
            Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]);
        }