Exemplo n.º 1
0
        public async Task<ColorScheme> GetByHex(string hex, ColorSchemeMode? mode = null) {
            if (!hexColorRegex.IsMatch(hex)) {
                throw new ArgumentException("hex is not valid", "hex");
            }

            if (hex.StartsWith("#")) {
                hex = hex.Substring(1);
            }

            var uriBuilder = new Common.UriBuilder(ColorConfiguration.Current.BaseUrl);
            uriBuilder.AppendPathPart("scheme");
            uriBuilder.AppendQueryPart("hex", hex.ToUpper());

            if (mode.HasValue) {
                uriBuilder.AppendQueryPart("mode", mode.ToString().ToLower());
            }

            using (var client = new HttpClient()) {
                var responseMessage = await client.GetAsync(uriBuilder.StringUri);
                if (!responseMessage.IsSuccessStatusCode) {
                    throw new HttpRequestException(responseMessage.ReasonPhrase);
                }

                var body = await responseMessage.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<ColorScheme>(body);
            }
        }
Exemplo n.º 2
0
        public async Task<ColorScheme> GetByCmyk(int c, int m, int y, int k, ColorSchemeMode? mode = null) {
            if (c < 0 | m < 0 | y < 0 | k < 0) {
                throw new ArgumentException("cmyk cannot be less than zero");
            }

            var uriBuilder = new Common.UriBuilder(ColorConfiguration.Current.BaseUrl);
            uriBuilder.AppendPathPart("scheme");
            uriBuilder.AppendQueryPart("cmyk", string.Format("cmyk({0},{1},{2},{3})", c, m, y, k));

            if (mode.HasValue) {
                uriBuilder.AppendQueryPart("mode", mode.ToString().ToLower());
            }

            using (var client = new HttpClient()) {
                var responseMessage = await client.GetAsync(uriBuilder.StringUri);
                if (!responseMessage.IsSuccessStatusCode) {
                    throw new HttpRequestException(responseMessage.ReasonPhrase);
                }

                var body = await responseMessage.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<ColorScheme>(body);
            }
        }
Exemplo n.º 3
0
 public void Should_succeed_when_mode_is_in_range(ColorSchemeMode value)
 {
     this.validator.ShouldNotHaveValidationErrorFor(cs => cs.mode, value);
 }
Exemplo n.º 4
0
 public void Should_fail_when_mode_is_out_of_range(ColorSchemeMode value)
 {
     this.validator.ShouldHaveValidationErrorFor(cs => cs.mode, value);
 }