Example #1
0
        public void Validate_Function_NoAuthentication_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow =>
                                       flow.Execute(action =>
                                                    action.Invoke(function =>
                                                                  function.WithName("fake")
                                                                  .OfType(FunctionType.Rest)
                                                                  .ForOperation(new Uri("http://fake.com/fake#fake"))
                                                                  .UseAuthentication("basic"))))
                           .End()
                           .Build();
            var function = new FunctionDefinition()
            {
                Name      = "Fake",
                Operation = "http://fake.com/fake#fake",
                AuthRef   = "fake"
            };

            //act
            var result = new FunctionDefinitionValidator(workflow).Validate(function);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.HaveCount(1)
            .And.Contain(e => e.PropertyName == nameof(FunctionDefinition.AuthRef));
        }
Example #2
0
 protected static WorkflowDefinition BuildWorkflow()
 {
     return(WorkflowDefinition.Create("MyWorkflow", "MyWorkflow", "1.0")
            .WithExecutionTimeout(timeout =>
                                  timeout.After(new TimeSpan(30, 2, 0, 0)))
            .StartsWith("inject", flow =>
                        flow.Inject(new { username = "******", password = "******" /*, scopes = new string[] { "api", "test" }*/ }))
            .Then("operation", flow =>
                  flow.Execute("fakeApiFunctionCall", action =>
     {
         action.Invoke(function =>
                       function.WithName("fakeFunction")
                       .ForOperation(new Uri("https://fake.com/swagger.json#fake")))
         .WithArgument("username", "${ .username }")
         .WithArgument("password", "${ .password }");
     })
                  .Execute("fakeEventTrigger", action =>
     {
         action
         .Consume(e =>
                  e.WithName("fakeEvent")
                  .WithSource(new Uri("https://fakesource.com"))
                  .WithType("fakeType"))
         .ThenProduce(e =>
                      e.WithName("otherEvent")
                      .WithSource(new Uri("https://fakesource.com"))
                      .WithType("fakeType"));
     }))
            .End()
            .Build());
 }
Example #3
0
        public void Validate_EventReference_TriggerEventConsumed_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .AddEvent(new EventDefinition()
            {
                Kind = EventKind.Consumed, Name = "fake"
            })
                           .StartsWith("fake", flow => flow.Callback())
                           .End()
                           .Build();
            var eventRef = new EventReference()
            {
                TriggerEvent = "fake"
            };

            //act
            var result = new EventReferenceValidator(workflow).Validate(eventRef);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(EventReference.TriggerEvent));
        }
Example #4
0
        public void Validate_Function_WithAutentication_ShouldWork()
        {
            //arrange
            var function = new FunctionDefinition()
            {
                Name      = "Fake",
                Operation = "http://fake.com/fake#fake",
                AuthRef   = "fake"
            };
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .AddBasicAuthentication("fake", auth => auth.LoadFromSecret("fake"))
                           .StartsWith("fake", flow =>
                                       flow.Execute(action =>
                                                    action.Invoke(function)))
                           .End()
                           .Build();


            //act
            var result = new FunctionDefinitionValidator(workflow).Validate(function);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.HaveCount(1)
            .And.Contain(e => e.PropertyName == nameof(FunctionDefinition.AuthRef));
        }
Example #5
0
        public void Validate_FunctionReference_SelectionSetNotEmpty_ShouldFail()
        {
            //arrange
            var functionName = "fake";
            var workflow     = WorkflowDefinition.Create("fake", "fake", "fake")
                               .AddFunction(function => function
                                            .WithName(functionName)
                                            .OfType(FunctionType.Rest))
                               .StartsWith("fake", flow => flow
                                           .Execute(action => action.Invoke(functionName)))
                               .End()
                               .Build();
            var functionRef = new FunctionReference()
            {
                RefName = functionName, SelectionSet = "{ id, name }"
            };

            //act
            var result = new FunctionReferenceValidator(workflow).Validate(functionRef);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(FunctionReference.SelectionSet));
        }
        public void Validate_CallbackState_EventNull_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Callback())
                           .End()
                           .Build();

            //act
            var result = this.WorkflowDefinitionValidator.Validate(workflow);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.ErrorCode == "States[0]" && e.ErrorMessage.Contains($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.Event)}"));
        }
Example #7
0
        public void Validate_InjectState_NoData_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Inject())
                           .End()
                           .Build();

            //act
            var result = this.WorkflowDefinitionValidator.Validate(workflow);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.ErrorCode.StartsWith($"{nameof(InjectStateDefinition)}.{nameof(InjectStateDefinition.Data)}"));
        }
        public void Validate_OperationState_NoActions_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Events())
                           .End()
                           .Build();
            var state = new OperationStateDefinition();

            //act
            var result = new OperationStateValidator(workflow).Validate(state);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(OperationStateDefinition.Actions));
        }
Example #9
0
        public void Validate_FunctionReference_NameNotSet_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Inject(new { }))
                           .End()
                           .Build();
            var functionRef = new FunctionReference();

            //act
            var result = new FunctionReferenceValidator(workflow).Validate(functionRef);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(FunctionReference.RefName));
        }
Example #10
0
        public void Validate_EventStateTrigger_NoEvents_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Events())
                           .End()
                           .Build();
            var state   = new EventStateDefinition();
            var trigger = new EventStateTriggerDefinition();

            //act
            var result = new EventStateTriggerDefinitionValidator(workflow, state).Validate(trigger);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(EventStateTriggerDefinition.Events));
        }
        public void Validate_Action_NoFunctionNorEvent_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Callback())
                           .End()
                           .Build();
            var action = new ActionDefinition();

            //act
            var result = new ActionDefinitionValidator(workflow).Validate(action);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.HaveCount(3)
            .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Event))
            .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Function))
            .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Subflow));
        }
Example #12
0
        public void Validate_EventReference_ResultEventNotSet_ShouldFail()
        {
            //arrange
            var workflow = WorkflowDefinition.Create("fake", "fake", "fake")
                           .StartsWith("fake", flow => flow.Callback())
                           .End()
                           .Build();
            var eventRef = new EventReference()
            {
                ProduceEvent = "fake"
            };

            //act
            var result = new EventReferenceValidator(workflow).Validate(eventRef);

            //assert
            result.Should()
            .NotBeNull();
            result.Errors.Should()
            .NotBeNullOrEmpty()
            .And.Contain(e => e.PropertyName == nameof(EventReference.ResultEvent));
        }