Example #1
0
        public async Task <SettingsUpdaterResult> UpdateAsync(string environment, string service, SettingsUpdaterResult previousResult = null)
        {
            var request = Request.Get("_settings/versioned")
                          .WithAdditionalQueryParameter("service", service)
                          .WithAdditionalQueryParameter("environment", environment)
                          .WithAdditionalQueryParameter("currentVersion", previousResult?.Version)
                          .WithAdditionalQueryParameter("versionType", previousResult?.VersionType);

            var clusterResult = await singularClient.SendAsync(request).ConfigureAwait(false);

            var response = clusterResult.Response;
            var content  = await TryReadContentAsync(response).ConfigureAwait(false);

            if (response.Code == ResponseCode.NotModified)
            {
                if (previousResult == null)
                {
                    throw new Exception("Received unexpected 'NotModified' response from server although no current version was sent in request.");
                }
                return(new SettingsUpdaterResult(false, previousResult.Version, previousResult.VersionType, null));
            }
            if (response.Code == ResponseCode.Ok)
            {
                var settingsNodes        = JsonConfigurationParser.Parse(content);
                var versionedRawSettings = settingsBinder.Bind <VersionedSettings <SingularSettings> >(JsonConfigurationParser.Parse(content));
                if (versionedRawSettings?.Settings == null)
                {
                    throw new Exception($"Received unexpected empty settings. Content: {content}");
                }
                return(new SettingsUpdaterResult(true, versionedRawSettings.Version, versionedRawSettings.VersionType, settingsNodes[nameof(VersionedSettings <SingularSettings> .Settings)]));
            }

            var errorMessage = $"Failed to update idempotency settings from singular. Response code = {response.Code}.";

            if (!string.IsNullOrEmpty(content))
            {
                errorMessage += $" Error = {content}";
            }
            throw new Exception(errorMessage);
        }
        public void Should_bind_single_value_node_to_naked_type <T>(string rawValue, T expectedValue)
        {
            var tree = Value(rawValue);

            binder.Bind <T>(tree).Should().Be(expectedValue);
        }