Beispiel #1
0
        public async Task AddImage_SavesAndReturnsResponse()
        {
            // Arrange

            TestLambdaContext       context;
            APIGatewayProxyRequest  request;
            APIGatewayProxyResponse response;

            var imageFunctions = new ImageFunctions(_ddbClient, _s3Client, _tableName, _bucketName);

            var testImageRequest = new AddImageRequestModel
            {
                ImageType   = "phone",
                FileName    = $"my-image.png",
                ContentType = "image/png"
            };

            request = new APIGatewayProxyRequest
            {
                Body = JsonSerializer.Serialize(testImageRequest)
            };

            context = new TestLambdaContext();

            // Act
            response = await imageFunctions.AddImageAsync(request, context);

            // Assert
            Assert.Equal(201, response.StatusCode);
            Assert.NotEmpty(response.Body);

            var testResponse = JsonSerializer.Deserialize <AddImageResponseModel>(response.Body);

            Assert.NotNull(testResponse);

            Assert.NotEmpty(testResponse.Id);
            Assert.NotEmpty(testResponse.Key);
            Assert.NotEmpty(testResponse.UploadUrl);

            // Clean up after the test
            // Note: We don't need to create a bucket to test getting a pre-signed URL
            var deleteTableResponse = await _ddbClient.DeleteTableAsync(_tableName);

            Console.WriteLine($"Delete DDB table response: {deleteTableResponse.HttpStatusCode}");
        }