コード例 #1
0
        public async Task Throw_Exception_On_Unsuccessful_Response()
        {
            //arrange - set up a successful response w/ check data in the expected JSON format
            var stubHandler = new StubHttpClientHandler();

            stubHandler.EnqueueResponse(new HttpResponseMessage(HttpStatusCode.InternalServerError));

            //act
            var service = new HealthTrayService(new HttpClient(stubHandler));
            await service.GetChecks();
        }
コード例 #2
0
        public async Task Return_Checks()
        {
            //arrange - set up a successful response w/ check data in the expected JSON format
            var stubHandler = new StubHttpClientHandler();

            stubHandler.EnqueueResponse(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{ \"checks\": [ { \"last_ping\": \"2017-01-04T13:24:39.903464+00:00\", \"ping_url\": \"https://hchk.io/662ebe36-ecab-48db-afe3-e20029cb71e6\", \"next_ping\": \"2017-01-04T14:24:39.903464+00:00\", \"grace\": 900, \"name\": \"Api test 1\", \"n_pings\": 1, \"tags\": \"foo\", \"pause_url\": \"https://healthchecks.io/api/v1/checks/662ebe36-ecab-48db-afe3-e20029cb71e6/pause\", \"timeout\": 3600, \"status\": \"up\", \"update_url\": \"https://healthchecks.io/api/v1/checks/662ebe36-ecab-48db-afe3-e20029cb71e6\" }, { \"last_ping\": null, \"ping_url\": \"https://hchk.io/9d17c61f-5c4f-4cab-b517-11e6b2679ced\", \"next_ping\": null, \"grace\": 3600, \"name\": \"Api test 2\", \"n_pings\": 0, \"tags\": \"bar baz\", \"pause_url\": \"https://healthchecks.io/api/v1/checks/9d17c61f-5c4f-4cab-b517-11e6b2679ced/pause\", \"tz\": \"UTC\", \"schedule\": \"0/10 * * * *\", \"status\": \"new\", \"update_url\": \"https://healthchecks.io/api/v1/checks/9d17c61f-5c4f-4cab-b517-11e6b2679ced\" } ] }")
            });

            //act
            var service = new HealthTrayService(new HttpClient(stubHandler));
            var checks  = await service.GetChecks();

            //assert
            Assert.AreEqual(2, checks.Count);
        }
コード例 #3
0
        /// <summary>
        /// Start up the application using the live Healthchecks service (for release).
        /// </summary>
        private static void StartupWithLiveService(AppConfig config)
        {
            var apiUrl     = config.Get <string>("healthchecks-api-url");
            var apiKeySalt = config.Get <string>("healthtray-salt");

            IHealthTrayService service = null;
            bool goToSettings          = false;

            if (string.IsNullOrWhiteSpace(apiUrl) || string.IsNullOrWhiteSpace(apiKeySalt))
            {
                service = new StubHealthTrayService(new List <Check>());
                if (MessageBox.Show("It looks like you haven't set an API URL and/or key yet. Enter one now?", "First run?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    goToSettings = true;
                }
            }
            else
            {
                try
                {
                    var apiKey = Crypto.Decrypt(config.Get <string>("healthchecks-api-key"), apiKeySalt);
                    service = new HealthTrayService(apiUrl, apiKey);
                }
                catch
                {
                    service      = new StubHealthTrayService(new List <Check>());
                    goToSettings = true; //settings page should inform user about the decryption error
                }
            }

            var dashboard = new DashboardWindow(service, config);

            dashboard.Show();

            if (goToSettings)
            {
                new ShowSettingsCommand().Execute(null);
            }
        }