Example #1
0
        public async Task Run_PerformsCreateIfUpdateRequiresReplacement_ForNestedTypes(
            string name,
            string requestId,
            string stackId,
            string logicalResourceId,
            [Substitute] ILambdaContext context
            )
        {
            using var generation = await project.GenerateAssembly();

            using var server = new InMemoryServer();

            var requestType = CustomResourceRequestType.Update;

            var(assembly, _) = generation;

            var handler = new HandlerWrapper <object>(assembly, handlerTypeName);
            var request = CreateRequest(assembly, name);

            request.RequestType       = requestType;
            request.ResponseURL       = new Uri(server.Address);
            request.StackId           = stackId;
            request.RequestId         = requestId;
            request.LogicalResourceId = logicalResourceId;
            request.ResourceProperties.Metadata.CreatedBy    = "Joe New";
            request.OldResourceProperties.Metadata.CreatedBy = "Joe Old";

            using var inputStream = await StreamUtils.CreateJsonStream(request);

            await handler.Run(inputStream, context);

            var httpRequest = server.Requests
                              .Should()
                              .Contain(request =>
                                       request.HttpMethod == "PUT"
                                       )
                              .Which;

            // Tests to make sure status is serialized to all caps
            httpRequest.Body.Should().MatchRegex("\"Status\":[ ]?\"SUCCESS\"");

            var body = JsonSerializer.Deserialize <CustomResourceResponse <ResponseData> >(httpRequest.Body);

            body.Should().Match <CustomResourceResponse <ResponseData> >(response =>
                                                                         response.PhysicalResourceId == name &&
                                                                         response.StackId == stackId &&
                                                                         response.RequestId == requestId &&
                                                                         response.LogicalResourceId == logicalResourceId &&
                                                                         response.Status == CustomResourceResponseStatus.Success &&
                                                                         response.Data !.MethodCalled == "Create"
                                                                         );
        }
Example #2
0
        public async Task TracingShouldBeEnabled()
        {
            using var generation = await project.GenerateAssembly();

            var(assembly, _) = generation;
            var handler = new HandlerWrapper <bool>(assembly, "Lambdajection.CompilationTests.Tracing.Handler");

            using var inputStream = await StreamUtils.CreateJsonStream(string.Empty);

            bool result = await handler.Run(inputStream, null !);

            result.Should().BeTrue();
        }
Example #3
0
        public async Task Run_ShouldNotSendFailure_IfOldNameIsLessThan3Chars(
            string requestId,
            string stackId,
            string logicalResourceId,
            CustomResourceRequestType requestType,
            [Substitute] ILambdaContext context
            )
        {
            var name    = "abcde";
            var oldName = "a";

            using var generation = await project.GenerateAssembly();

            using var server = new InMemoryServer();

            var(assembly, _) = generation;
            var handler = new HandlerWrapper <object>(assembly, handlerTypeName);
            var request = CreateRequest(assembly, name);

            request.RequestType                = requestType;
            request.ResponseURL                = new Uri(server.Address);
            request.StackId                    = stackId;
            request.RequestId                  = requestId;
            request.LogicalResourceId          = logicalResourceId;
            request.PhysicalResourceId         = null;
            request.OldResourceProperties.Name = oldName;

            var inputStream = await StreamUtils.CreateJsonStream(request);

            await handler.Run(inputStream, context);

            var httpRequest = server.Requests
                              .Should()
                              .Contain(request =>
                                       request.HttpMethod == "PUT"
                                       )
                              .Which;

            var body = JsonSerializer.Deserialize <CustomResourceResponse <ResponseData> >(httpRequest.Body);

            body.Should().Match <CustomResourceResponse <ResponseData> >(response =>
                                                                         response.StackId == stackId &&
                                                                         response.RequestId == requestId &&
                                                                         response.LogicalResourceId == logicalResourceId &&
                                                                         response.Status == CustomResourceResponseStatus.Success
                                                                         );
        }
Example #4
0
        public async Task Run_ShouldReturnIdIfUsingCamelCase(
            string id
            )
        {
            using var generation = await project.GenerateAssembly();

            var(assembly, _) = generation;
            var requestType = assembly.GetType("Lambdajection.CompilationTests.Serialization.Request") !;
            var handler     = new HandlerWrapper <string>(assembly, "Lambdajection.CompilationTests.Serialization.Handler");
            var request     = (dynamic)Activator.CreateInstance(requestType) !;

            request.Id = id;

            using var inputStream = await StreamUtils.CreateJsonStream(request, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });

            string result = await handler.Run(inputStream, null);

            result.Should().Be(id);
        }