Example #1
0
        public async Task ShouldSendDeployResourceAndGetResponseAsExpected()
        {
            // given
            var expectedResponse = new DeployWorkflowResponse {
                Key = 1
            };

            expectedResponse.Workflows.Add(new WorkflowMetadata
            {
                BpmnProcessId = "process",
                ResourceName  = _demoProcessPath,
                Version       = 1,
                WorkflowKey   = 2
            });

            TestService.AddRequestHandler(typeof(DeployWorkflowRequest), request => expectedResponse);

            // when
            var deployWorkflowResponse = await ZeebeClient.NewDeployCommand()
                                         .AddResourceFile(_demoProcessPath)
                                         .Send();

            // then
            Assert.AreEqual(1, deployWorkflowResponse.Key);
            Assert.AreEqual(1, deployWorkflowResponse.Workflows.Count);

            var workflowMetadata = deployWorkflowResponse.Workflows[0];

            Assert.AreEqual("process", workflowMetadata.BpmnProcessId);
            Assert.AreEqual(1, workflowMetadata.Version);
            Assert.AreEqual(_demoProcessPath, workflowMetadata.ResourceName);
            Assert.AreEqual(2, workflowMetadata.WorkflowKey);
        }
Example #2
0
        public async Task ShouldSendDeployResourceStringUtf8AsExpected()
        {
            // given
            var expectedRequest = new DeployWorkflowRequest
            {
                Workflows =
                {
                    new WorkflowRequestObject
                    {
                        Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
                        Name       = _demoProcessPath,
                        Type       = WorkflowRequestObject.Types.ResourceType.File
                    }
                }
            };

            // when
            var fileContent = File.ReadAllText(_demoProcessPath);
            await ZeebeClient.NewDeployCommand()
            .AddResourceStringUtf8(fileContent, _demoProcessPath)
            .Send();

            // then
            var actualRequest = TestService.Requests[0];

            Assert.AreEqual(expectedRequest, actualRequest);
        }
Example #3
0
        public async Task ShouldSendDeployResourceStringAsExpected()
        {
            // given
            var expectedRequest = new DeployProcessRequest
            {
                Processes =
                {
                    new ProcessRequestObject
                    {
                        Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
                        Name       = _demoProcessPath,
                    }
                }
            };

            // when
            var fileContent = File.ReadAllText(_demoProcessPath);
            await ZeebeClient.NewDeployCommand()
            .AddResourceString(fileContent, Encoding.UTF8, _demoProcessPath)
            .Send();

            // then
            var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];

            Assert.AreEqual(expectedRequest, actualRequest);
        }
Example #4
0
        public async Task ShouldSendMultipleDeployResourceAsExpected()
        {
            // given
            var expectedRequest = new DeployWorkflowRequest
            {
                Workflows =
                {
                    new WorkflowRequestObject
                    {
                        Definition = ByteString.FromStream(File.OpenRead(DemoProcessPath)),
                        Name       = DemoProcessPath,
                        Type       = WorkflowRequestObject.Types.ResourceType.File
                    },
                    new WorkflowRequestObject
                    {
                        Definition = ByteString.FromStream(File.OpenRead(DemoProcessPath)),
                        Name       = DemoProcessPath,
                        Type       = WorkflowRequestObject.Types.ResourceType.File
                    }
                }
            };

            // when
            await ZeebeClient.NewDeployCommand()
            .AddResourceFile(DemoProcessPath)
            .AddResourceStream(File.OpenRead(DemoProcessPath), DemoProcessPath)
            .Send();

            // then
            var actualRequest = TestService.Requests[0];

            Assert.AreEqual(expectedRequest, actualRequest);
        }
Example #5
0
        public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected()
        {
            // given
            var expectedResponse = new DeployProcessResponse {
                Key = 1
            };

            expectedResponse.Processes.Add(new ProcessMetadata
            {
                BpmnProcessId        = "process",
                ResourceName         = _demoProcessPath,
                Version              = 1,
                ProcessDefinitionKey = 2
            });
            expectedResponse.Processes.Add(new ProcessMetadata
            {
                BpmnProcessId        = "process2",
                ResourceName         = _demoProcessPath,
                Version              = 1,
                ProcessDefinitionKey = 3
            });

            TestService.AddRequestHandler(typeof(DeployProcessRequest), request => expectedResponse);

            // when
            var fileContent           = File.ReadAllText(_demoProcessPath);
            var deployProcessResponse = await ZeebeClient.NewDeployCommand()
                                        .AddResourceFile(_demoProcessPath)
                                        .AddResourceString(fileContent, Encoding.UTF8, _demoProcessPath)
                                        .Send();

            // then
            Assert.AreEqual(1, deployProcessResponse.Key);
            Assert.AreEqual(2, deployProcessResponse.Processes.Count);

            var processMetadata = deployProcessResponse.Processes[0];

            Assert.AreEqual("process", processMetadata.BpmnProcessId);
            Assert.AreEqual(1, processMetadata.Version);
            Assert.AreEqual(_demoProcessPath, processMetadata.ResourceName);
            Assert.AreEqual(2, processMetadata.ProcessDefinitionKey);

            var processMetadata2 = deployProcessResponse.Processes[1];

            Assert.AreEqual("process2", processMetadata2.BpmnProcessId);
            Assert.AreEqual(1, processMetadata2.Version);
            Assert.AreEqual(_demoProcessPath, processMetadata2.ResourceName);
            Assert.AreEqual(3, processMetadata2.ProcessDefinitionKey);
        }
Example #6
0
        public void ShouldCancelRequest()
        {
            // given

            // when
            var task = ZeebeClient
                       .NewDeployCommand()
                       .AddResourceFile(_demoProcessPath)
                       .Send(new CancellationTokenSource(TimeSpan.Zero).Token);
            var aggregateException = Assert.Throws <AggregateException>(() => task.Wait());
            var rpcException       = (RpcException)aggregateException.InnerExceptions[0];

            // then
            Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode);
        }
        public void ShouldTimeoutRequest()
        {
            // given

            // when
            var task = ZeebeClient
                       .NewDeployCommand()
                       .AddResourceFile(_demoProcessPath)
                       .Send(TimeSpan.Zero);
            var aggregateException = Assert.Throws <AggregateException>(() => task.Wait());
            var rpcException       = (RpcException)aggregateException.InnerExceptions[0];

            // then
            Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode);
        }