Exemplo n.º 1
0
        public async Task RunActivity_RetriesForCompleted(
            [Values(OrchestrationRuntimeStatus.Canceled, OrchestrationRuntimeStatus.Failed, OrchestrationRuntimeStatus.Terminated, OrchestrationRuntimeStatus.Completed)] OrchestrationRuntimeStatus runtimeStatus)
        {
            var data       = CreatePushData("test", "test");
            var instanceId = CreateInstanceId(data);

            _mockDurableClient.CreateCheckStatusResponse(Arg.Any <HttpRequestMessage>(), instanceId).Returns(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(string.Empty)
            });

            var status = new DurableOrchestrationStatus
            {
                RuntimeStatus = runtimeStatus
            };

            _mockDurableClient.GetStatusAsync(instanceId).Returns(Task.FromResult(status));

            var request = new HttpRequestMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(data), System.Text.Encoding.UTF8, "application/json"),
            };

            var result = await RepositoryValidatorEndpoint.RepositoryValidatorTrigger(request, _mockDurableClient, Substitute.For <ILogger>());

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
            await _mockDurableClient.Received().StartNewAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <object>());
        }
Exemplo n.º 2
0
        public async Task RunActivity_ValidatesTrigger()
        {
            var content    = CreatePushData("by-pinja", "repository-validator-testing");
            var instanceId = CreateInstanceId(content);

            _mockDurableClient.StartNewAsync(Arg.Any <string>(), Arg.Any <object>()).Returns(Task.FromResult(instanceId));
            _mockDurableClient.GetStatusAsync(Arg.Any <string>()).Returns(Task.FromResult <DurableOrchestrationStatus>(null));

            _mockDurableClient.CreateCheckStatusResponse(Arg.Any <HttpRequestMessage>(), instanceId).Returns(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(string.Empty)
            });

            var request = new HttpRequestMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(content), System.Text.Encoding.UTF8, "application/json"),
            };

            var result = await RepositoryValidatorEndpoint.RepositoryValidatorTrigger(request, _mockDurableClient, Substitute.For <ILogger>());

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
            await _mockDurableClient.Received().StartNewAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <object>());

            _mockDurableClient.Received().CreateCheckStatusResponse(Arg.Any <HttpRequestMessage>(), instanceId);
        }
Exemplo n.º 3
0
        public async Task RunActivity_InvalidJsonThrowsError()
        {
            var invalidObjects = new dynamic[] {
                new
                {
                    repository = new
                    {
                        name  = "repository-validator-testing",
                        owner = "test"
                    }
                },
                new
                {
                    repository = new
                    {
                        name = "repository-validator-testing"
                    }
                },
                new
                {
                    repository = new
                    {
                        name  = "repository-validator-testing",
                        owner = (object)null
                    }
                },
                new
                {
                    repository = new
                    {
                        owner = new
                        {
                            login = "******"
                        }
                    }
                }
            };

            foreach (var dynamic in invalidObjects)
            {
                var request = new HttpRequestMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(dynamic), System.Text.Encoding.UTF8, "application/json"),
                };

                var result = await RepositoryValidatorEndpoint.RepositoryValidatorTrigger(request, _mockDurableClient, Substitute.For <ILogger>());

                Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
                await _mockDurableClient.DidNotReceive().StartNewAsync(Arg.Any <string>(), Arg.Any <object>());

                _mockDurableClient.DidNotReceive().CreateCheckStatusResponse(Arg.Any <HttpRequestMessage>(), Arg.Any <string>());
            }
        }