Example #1
0
        public JsonResult EBooleanModelSearch(string Query)
        {
            try {
                List <EQUESTION> Result = BooleanModel.EnglishSearch(Query);

                var JsonRes = Result.Select(Q => new {
                    Question = Q.VALUE,
                    Answer   = Q.ANSWER,
                    Rank     = 1
                });

                return(Json(JsonRes, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                var line = GetLineNumber(e);

                var JsonRes = new
                {
                    Message       = e.Message,
                    innerExeption = e.InnerException.Message,
                    factor3       = e.Data.ToString(),
                    factor4       = e.InnerException.ToString(),
                    line          = line
                };

                return(Json(JsonRes, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public BooleanModel Digitals()
        {
            var boolModel = new BooleanModel
            {
                DigitalInput01 = _r.Next(100) <= 20,
                DigitalInput02 = _r.Next(100) <= 20,
                DigitalInput03 = _r.Next(100) <= 20,
                DigitalInput04 = _r.Next(100) <= 20,
                DigitalInput05 = _r.Next(100) <= 20,
                DigitalInput06 = _r.Next(100) <= 20,
                DigitalInput07 = _r.Next(100) <= 20,
                DigitalInput08 = _r.Next(100) <= 20,
                DigitalInput09 = _r.Next(100) <= 20,
                DigitalInput10 = _r.Next(100) <= 20,
                DigitalInput11 = _r.Next(100) <= 20,
                DigitalInput12 = _r.Next(100) <= 20,
                DigitalInput13 = _r.Next(100) <= 20,
                DigitalInput14 = _r.Next(100) <= 20,
                DigitalInput15 = _r.Next(100) <= 20,
                DigitalInput16 = _r.Next(100) <= 20,
                DigitalInput17 = _r.Next(100) <= 20,
                DigitalInput18 = _r.Next(100) <= 20,
                DigitalInput19 = _r.Next(100) <= 20,
                DigitalInput20 = _r.Next(100) <= 20
            };

            return(boolModel);
        }
        /// <summary>
        /// Add double model
        /// </summary>
        /// <param name="context"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ContextModel AddBoolean(this ContextModel context, string key, bool value)
        {
            var element = new BooleanModel(value);

            context.AddItem(key, element);
            return(context);
        }
    public void ExpectedFalse_ActualFalse()
    {
        var vm = new BooleanModel {WannaTrue = false};

        var validations = vm.Validate(vm.WannaFalse, _wannaFalse);
        validations.Print(_output);

        Assert.Empty(validations);
    }
    public void ExpectedFalse_ActualTrue()
    {
        var vm = new BooleanModel {WannaFalse = true};

        var validations = vm.Validate(vm.WannaFalse, _wannaFalse);
        validations.Print(_output);

        Assert.Collection(validations, v =>
                              v.ErrorMessage = "Unchecked is required");
    }
Example #6
0
        public async Task <TResult> CallApiMethod <TResult>(ApiMethod method, IEnumerable <JsonConverter> converters = null)
            where TResult : class
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("WykopClient");
            }
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var apiRequestUrl = BuildApiRequestUrl(method);

            using (var request = new HttpRequestMessage(method.HttpMethod, apiRequestUrl.ToString()))
            {
                AuthSignature signature;
                AddRequestHeader(request);

                if (method.HttpMethod == HttpMethod.Get)
                {
                    signature = new AuthSignature(_appSecret, request.RequestUri);
                }
                else if (method.HttpMethod == HttpMethod.Post)
                {
                    signature       = new AuthSignature(_appSecret, request.RequestUri, method.PostParameters);
                    request.Content = BuilPostContent(method);
                }
                else
                {
                    throw new UnsupportedHttpMethodException("Http method {method.HttpMethod} is not supported");
                }

                var hash = signature.FetchSignature();
                request.Headers.Add("apisign", hash);

                using (var response = await _client.SendAsync(request, CancellationToken.None).ConfigureAwait(false))
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        throw new InvalidResponseException("Response is not success. ", 0);
                    }

                    var stringResponse = response.Content.ReadAsStringAsync().Result;
                    var responseType   = CheckResponseType(stringResponse, response);
                    ValidateErrors(stringResponse);

                    switch (responseType)
                    {
                    case ResponseType.Unsupported:
                    case ResponseType.Json:
                        break;

                    case ResponseType.Html:
                        return((dynamic) new HtmlResponse()
                        {
                            Html = stringResponse
                        });

                    case ResponseType.ValueArray:
                        // API is incosistent - return array with boolean,
                        // but i don't know is that the only one behaviour
                        var booleanResult = new BooleanModel();
                        booleanResult.Success = stringResponse.Contains("true") ? true : false;
                        return((dynamic)booleanResult);
                    }

                    using (var reader = new JsonTextReader(new StringReader(stringResponse)))
                    {
                        var serializer = CreateSerializer(converters);
                        var result     = serializer.Deserialize <TResult>(reader);

                        return(result);
                    }
                }
            }
        }