示例#1
0
        public PeakyTestExecutionTests(ITestOutputHelper output)
        {
            disposables.Add(LogEvents.Subscribe(e => output.WriteLine(e.ToLogString())));

            var peakyService = new PeakyService(
                targets => targets
                .Add("production",
                     "widgetapi",
                     new Uri("http://widgets.com"),
                     dependencies => dependencies.Register <HttpClient>(() =>
            {
                return(new FakeHttpClient(msg => new HttpResponseMessage(HttpStatusCode.OK)));
            }))
                .Add("production",
                     "sprocketapi",
                     new Uri("http://widgets.com"),
                     dependencies => dependencies.Register <HttpClient>(() =>
            {
                return(new FakeHttpClient(msg => new HttpResponseMessage(HttpStatusCode.OK)));
            })));

            disposables.Add(peakyService);

            apiClient = peakyService.CreateHttpClient();
        }
示例#2
0
        public async Task Dependencies_can_be_declared_that_are_specific_to_environment_and_application()
        {
            var api = new PeakyService(
                targets => targets
                .Add("production",
                     "widgets",
                     new Uri("http://widgets.com"),
                     t => t.Register <HttpClient>(() => new FakeHttpClient(_ => new HttpResponseMessage(HttpStatusCode.OK))
            {
                BaseAddress = new Uri("http://widgets.com")
            }))
                .Add("staging",
                     "widgets",
                     new Uri("http://staging.widgets.com"),
                     t => t.Register <HttpClient>(() => new FakeHttpClient(_ => new HttpResponseMessage(HttpStatusCode.GatewayTimeout))
            {
                BaseAddress = new Uri("http://staging.widgets.com")
            })))
                      .CreateHttpClient();

            // try production, which should be reachable
            var response = api.GetAsync("http://blammo.com/tests/production/widgets/is_reachable");
            await response.ShouldSucceedAsync();

            // then staging, which should not be reachable
            response = api.GetAsync("http://blammo.com/tests/staging/widgets/is_reachable");
            await response.ShouldFailWithAsync(HttpStatusCode.InternalServerError);
        }
示例#3
0
        private HttpClient CreatePeakyClient(Action <IServiceCollection> configureServices = null)
        {
            var peakyService = new PeakyService(
                targets => targets
                .Add("production",
                     "widgetapi",
                     new Uri("http://widgets.com"),
                     dependencies => dependencies.Register <HttpClient>(() =>
            {
                return(new FakeHttpClient(msg => new HttpResponseMessage(HttpStatusCode.OK)));
            }))
                .Add("staging",
                     "widgetapi",
                     new Uri("http://widgets.com"),
                     dependencies => dependencies.Register <HttpClient>(() =>
            {
                return(new FakeHttpClient(msg => new HttpResponseMessage(HttpStatusCode.OK)));
            })),
                configureServices: configureServices);

            var httpClient = peakyService.CreateHttpClient();

            disposables.Add(httpClient);
            disposables.Add(peakyService);

            return(httpClient);
        }
示例#4
0
 public SensorErrorTests()
 {
     registry     = new SensorRegistry();
     peakyService = new PeakyService(
         configureServices: s => s.AddSingleton(registry));
     apiClient  = peakyService.CreateHttpClient();
     sensorName = Any.AlphanumericString(10, 20);
 }
示例#5
0
        public SensorRoutingTests()
        {
            registry = new SensorRegistry(DiagnosticSensor.DiscoverSensors());

            var peaky = new PeakyService(configureServices: s => s.AddSingleton(registry));

            apiClient = peaky.CreateHttpClient();

            sensorName = Any.AlphanumericString(10, 20);
        }
示例#6
0
        public SensorAuthorizationTests()
        {
            peakyService = new PeakyService(
                configureServices: services => services
                .AddPeakySensors(context =>
            {
                authorize?.Invoke(context);
            }));

            apiClient = peakyService.CreateHttpClient();
        }
示例#7
0
        public void HttpClient_is_configured_by_default_using_TestTarget_BaseAddress()
        {
            var api = new PeakyService(targets => targets.Add("production", "widgetapi", new Uri("http://localhost:42")));

            var response = api.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi/HttpClient_BaseAddress").Result;

            var message = response.Content.ReadAsStringAsync().Result;

            response.ShouldSucceed();

            message.Should().Contain("BaseAddress = http://localhost:42");
        }
示例#8
0
        public async Task When_a_test_cannot_be_instantiated_due_to_missing_dependencies_then_calling_the_error_test_returns_500_with_details()
        {
            var api = new PeakyService(targets => targets.Add("production", "widgetapi", new Uri("http://localhost:81")));

            var response = await api.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi/unsatisfiable_dependencies_test");

            var message = await response.Content.ReadAsStringAsync();

            response.ShouldFailWith(HttpStatusCode.InternalServerError);

            message.Should()
            .Contain(
                "\"ClassName\":\"System.InvalidOperationException\",\"Message\":\"No service for type 'System.Collections.Generic.List`1[System.Collections.Generic.KeyValuePair`2[System.Nullable`1[System.DateTimeOffset],System.Collections.Generic.HashSet`1[System.Guid]]]' has been registered.\"");
        }
        private HttpClient CreateApiClient(TestApplicabilityCheck applies)
        {
            var testApi = new PeakyService(targets =>
                                           targets.Add("staging",
                                                       "widgetapi",
                                                       new Uri("http://staging.widgets.com"),
                                                       dependencies =>
                                                       dependencies
                                                       .Register(() => applies)),
                                           testTypes: new[] { typeof(TestsConstrainedToTarget) });

            disposables.Add(testApi);

            return(testApi.CreateHttpClient());
        }
示例#10
0
        public async Task When_a_test_cannot_be_instantiated_due_to_missing_dependencies_then_the_URL_is_still_displayed()
        {
            var api = new PeakyService(targets => targets.Add("production", "widgetapi", new Uri("http://localhost:81")));

            var response = await api.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi");

            response.ShouldSucceed();

            var testList = await response.AsTestList();

            testList.Tests
            .Should()
            .Contain(o =>
                     o.Url == "http://blammo.com/tests/production/widgetapi/unsatisfiable_dependencies_test");
        }
示例#11
0
        public void Target_environment_is_available_by_declaring_a_dependency_on_Target_when_no_resolver_is_specified()
        {
            var api = new PeakyService(targets => targets.Add("staging", "widgetapi", new Uri("http://localhost:81")));

            var response = api.CreateHttpClient().GetAsync("http://blammo.com/tests/staging/widgetapi/get_target").Result;

            response.ShouldSucceed(HttpStatusCode.OK);

            var result = response.Content.ReadAsStringAsync().Result;

            string environment = JsonConvert.DeserializeObject <dynamic>(result)
                                 .ReturnValue
                                 .Environment;

            environment.Should().Be("staging");
        }
示例#12
0
        public PeakyTestDiscoveryTests(ITestOutputHelper output)
        {
            disposables.Add(LogEvents.Subscribe(e => output.WriteLine(e.ToLogString())));

            var peakyService = new PeakyService(
                targets =>
                targets.Add("staging", "widgetapi", new Uri("http://staging.widgets.com"))
                .Add("production", "widgetapi", new Uri("http://widgets.com"))
                .Add("staging", "sprocketapi", new Uri("http://staging.sprockets.com"))
                .Add("production", "sprocketapi", new Uri("http://sprockets.com")));

            apiClient = peakyService.CreateHttpClient();

            disposables.Add(apiClient);
            disposables.Add(peakyService);
        }
示例#13
0
        public ServiceWarmupTests(ITestOutputHelper output)
        {
            disposables.Add(LogEvents.Subscribe(e => output.WriteLine(e.ToLogString())));

            peakyService = new PeakyService(
                targets => targets
                .Add("production",
                     "widgetapi",
                     new Uri("http://widgets.com"),
                     dependencies => dependencies.UseServiceWarmup <TestWarmup>())
                );

            disposables.Add(peakyService);

            disposables.Add(Disposable.Create(TestWarmup.ResetCount));
        }
示例#14
0
        public void When_HttpClient_BaseAddress_is_not_set_in_dependency_registration_then_it_is_set_to_the_test_target_configured_value()
        {
            var api = new PeakyService(targets =>
                                       targets
                                       .Add("production", "widgetapi", new Uri("http://bing.com"),
                                            dependencies => dependencies.Register(() => new HttpClient())));

            var response = api.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi/HttpClient_BaseAddress").Result;

            var message = response.Content.ReadAsStringAsync().Result;

            Console.WriteLine(message);

            response.ShouldSucceed();

            message.Should().Contain("BaseAddress = http://bing.com");
        }
示例#15
0
        public async Task When_HttpClient_BaseAddress_is_set_in_dependency_registration_then_it_is_not_overridden()
        {
            var api = new PeakyService(targets =>
                                       targets
                                       .Add("production", "widgetapi", new Uri("http://google.com"),
                                            dependencies => dependencies.Register(() => new HttpClient
            {
                BaseAddress = new Uri("http://bing.com")
            })));

            var response = await api.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi/HttpClient_BaseAddress");

            var message = await response.Content.ReadAsStringAsync();

            Console.WriteLine(message);

            response.ShouldSucceed();

            message.Should().Contain("BaseAddress = http://bing.com");
        }
示例#16
0
        public async Task Specific_tests_can_be_routed_using_the_testTypes_argument()
        {
            var api = new PeakyService(targets =>
                                       targets.Add("production",
                                                   "widgetapi",
                                                   new Uri("http://widgets.com")),
                                       testTypes: new[] { typeof(WidgetApiTests) });

            var response = api.CreateHttpClient().GetAsync("http://blammo.com/tests/").Result;

            response.ShouldSucceed();

            var testList = await response.AsTestList();

            testList.Tests
            .Should()
            .Contain(o =>
                     o.Url.Contains("widgetapi_only_test"));
            testList.Tests
            .Should()
            .NotContain(o =>
                        o.Url.Contains("passing_test_returns_object"));
        }
示例#17
0
        public async Task Dependencies_added_to_ServiceProvider_are_resolvable_by_Peaky()
        {
            var peaky = new PeakyService(
                configureTargets: targets => targets.Add("production", "widgetapi", new Uri("http://blammo.com")),
                configureServices: services =>
                services.AddTransient <IList <string> >(c =>
                                                        new List <string>
            {
                "one",
                "two",
                "three"
            }),
                testTypes: new[] { typeof(TestWithDependencyOn <IList <string> >) });

            var response = await peaky.CreateHttpClient().GetAsync("http://blammo.com/tests/production/widgetapi/dependency_test");

            var testResult = await response.AsTestResult();

            JsonConvert.DeserializeObject <string[]>(testResult.ReturnValue.ToString()).Should()
            .BeEquivalentTo("one",
                            "two",
                            "three");
        }
示例#18
0
 public TelemetryMonitorTests()
 {
     peakyService = new PeakyService(targets => targets.Add("staging", "widgetapi", new Uri("http://staging.widgets.com")));
     apiClient    = peakyService.CreateHttpClient();
 }