Пример #1
0
        public void ServiceInstanceIsMarkedAsDown_MonitoringEndpointReturnsSuccessMessage_ServiceInstanceIsMarkedAsUp()
        {
            var configuration = new Configuration.Configuration();

            configuration.Endpoints.Add(new Configuration.RoutingEndpoint
            {
                Id        = "service1",
                Instances = new Configuration.Instances
                {
                    Instance = new System.Collections.Generic.List <Configuration.Instance>
                    {
                        new Configuration.Instance
                        {
                            Status = ApiGateway.Configuration.InstanceStatuses.Down,
                            Url    = "http://service1.com/requestPath"
                        }
                    }
                },
                HealthCheck = new Configuration.HealthCheckConfiguration
                {
                    MonitoringPath = "/status",
                    ResponseShouldContainString = "OK"
                }
            });

            // Arrange
            Func <Configuration.Configuration> configurationGen = () => {
                return(configuration);
            };

            var  logMock = new Mock <ILog>();
            ILog logger  = logMock.Object;

            var responseHandler = new FakeResponseHandler();

            responseHandler.AddFakeResponseGenerator(new System.Uri("http://service1.com/status"), () =>
            {
                var r     = new HttpResponseMessage(HttpStatusCode.OK);
                r.Content = new StringContent("Service is OK.");

                return(r);
            });

            // Act
            var serviceProbe = new ServiceProbe(httpClientMessageHandler: responseHandler);

            serviceProbe.Initialize(configurationGen, logger);
            serviceProbe.TestEndpoint(configuration.Endpoints.First());

            // Assert
            Assert.AreEqual(Configuration.InstanceStatuses.Up, configuration.Endpoints.First().Instances.Instance.First().Status);
        }
Пример #2
0
            private FakeResponseHandler PrepareHttpMessageHandler()
            {
                var responseHandler = new FakeResponseHandler();

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://instance1.service1.com/requestPath"), () =>
                {
                    var r     = new HttpResponseMessage(HttpStatusCode.OK);
                    r.Content = new StringContent("Hello world from service1 instance 1");

                    return(r);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service2.com/requestPath"), () =>
                {
                    var responseFromService2     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService2.Content = new StringContent(SuccessfulResponseContentFromService2);

                    return(responseFromService2);
                });

                return(responseHandler);
            }
Пример #3
0
            private HttpMessageHandler PrepareHttpMessageHandler()
            {
                var responseHandler = new FakeResponseHandler();

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service1.com/requestPath"), () =>
                {
                    var responseFromService1     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService1.Content = new StringContent("Hello world from service1");

                    return(responseFromService1);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service2.com/requestPath"), () =>
                {
                    var responseFromService2     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService2.Content = new StringContent(SuccessfulResponseContentFromService2);

                    return(responseFromService2);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service3.com/1/2/3"), () =>
                {
                    var responseFromService3     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService3.Content = new StringContent("Hello world from service3");

                    return(responseFromService3);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service4.com/requestPath"), () =>
                {
                    var responseFromService4     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService4.Content = new StringContent(SuccessfulResponseContentFromService4);

                    return(responseFromService4);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service5.com/requestPath"), () =>
                {
                    var responseFromService5     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService5.Content = new StringContent(SuccessfulResponseContentFromService5);

                    return(responseFromService5);
                });

                responseHandler.AddFakeResponseGenerator(new System.Uri("http://service6.com/requestPath/someSubPath"), () =>
                {
                    var responseFromService6     = new HttpResponseMessage(HttpStatusCode.OK);
                    responseFromService6.Content = new StringContent(SuccessfulResponseContentFromService6);

                    return(responseFromService6);
                });

                return(responseHandler);
            }