private void RunSubCheck(SubCheck subCheck, string responseText, CheckResult result)
        {
            switch (subCheck.Type.Identifier)
            {
            case nameof(SubChecks.ResponseContains):
                var responseContainsOptions = subCheck.GetOptions <ResponseContains>();
                var text = responseContainsOptions.Text;
                if (responseText.Contains(text))
                {
                    _logger.Info($"Response contains '{text}'");
                }
                else
                {
                    throw new SubCheckException($"Response does not contain '{text}'");
                }
                break;

            case nameof(SubChecks.JsonProperty):
                var jsonPropertyOptions = subCheck.GetOptions <JsonProperty>();
                var fieldName           = jsonPropertyOptions.FieldName;
                var exists        = jsonPropertyOptions.Exists;
                var valueContains = jsonPropertyOptions.Value;
                var obj           = JObject.Parse(responseText);
                var value         = obj.SelectToken(fieldName)?.ToString();
                if (value == null && exists)
                {
                    throw new SubCheckException($"Field '{fieldName}' does not exist");
                }
                else if (value != null && !exists)
                {
                    throw new SubCheckException($"Field '{fieldName}' exists");
                }
                if (value != null)
                {
                    if (!string.IsNullOrWhiteSpace(valueContains))
                    {
                        if (value.Contains(valueContains))
                        {
                            _logger.Info($"Field '{fieldName}' contains '{valueContains}'");
                        }
                        else
                        {
                            throw new SubCheckException($"Field '{fieldName}' does not contain '{valueContains}'");
                        }
                    }
                }
                break;

            default:
                _logger.Warn($"Unknown sub-check type {subCheck.TypeID} - ignoring");
                break;
            }
        }
Example #2
0
        private void RunSubCheck(SubCheck subCheck, string responseText, CheckResult result)
        {
            switch (subCheck.TypeID)
            {
            case (int)SubChecks.ResponseContains:
                string text = subCheck.Options[((int)ResponseContains.Text).ToString()];
                if (responseText.Contains(text))
                {
                    _logger.Info($"Response contains '{text}'");
                }
                else
                {
                    throw new SubCheckException($"Response does not contain '{text}'");
                }
                break;

            case (int)SubChecks.JSONProperty:
                string fieldName     = subCheck.Options[((int)JSONProperty.FieldName).ToString()];
                bool   exists        = subCheck.Options[((int)JSONProperty.Exists).ToString()];
                string valueContains = subCheck.Options[((int)JSONProperty.ValueContains).ToString()];
                var    obj           = JObject.Parse(responseText);
                var    value         = obj.SelectToken(fieldName)?.ToString();
                if (value == null && exists)
                {
                    throw new SubCheckException($"Field '{fieldName}' does not exist");
                }
                else if (value != null && !exists)
                {
                    throw new SubCheckException($"Field '{fieldName}' exists");
                }
                if (value != null)
                {
                    if (!string.IsNullOrWhiteSpace(valueContains))
                    {
                        if (value.Contains(valueContains))
                        {
                            _logger.Info($"Field '{fieldName}' contains '{valueContains}'");
                        }
                        else
                        {
                            throw new SubCheckException($"Field '{fieldName}' does not contain '{valueContains}'");
                        }
                    }
                }
                break;

            default:
                _logger.Warn($"Unknown sub-check type {subCheck.TypeID} - ignoring");
                break;
            }
        }
Example #3
0
        private void RunSubCheck(SubCheck subCheck, JArray jsonResult, CheckResult checkResult)
        {
            switch (subCheck.TypeID)
            {
            case (int)SubCheckType.FieldEqualTo:
                string fieldName     = subCheck.Options[((int)FieldEqualTo.FieldName).ToString()];
                bool   exists        = subCheck.Options[((int)FieldEqualTo.Exists).ToString()];
                var    actualValue   = GetFieldValue(fieldName, exists, jsonResult);
                string expectedValue = subCheck.Options[((int)FieldEqualTo.Value).ToString()];
                VerifyAreEquals(expectedValue, actualValue, fieldName);
                break;

            case (int)SubCheckType.FieldNotEqualTo:
                fieldName     = subCheck.Options[((int)FieldNotEqualTo.FieldName).ToString()];
                exists        = subCheck.Options[((int)FieldNotEqualTo.Exists).ToString()];
                actualValue   = GetFieldValue(fieldName, exists, jsonResult);
                expectedValue = subCheck.Options[((int)FieldNotEqualTo.Value).ToString()];
                VerifyAreNotEquals(expectedValue, actualValue, fieldName);
                break;

            case (int)SubCheckType.FieldGreaterThan:
                fieldName     = subCheck.Options[((int)FieldGreaterThan.FieldName).ToString()];
                exists        = subCheck.Options[((int)FieldGreaterThan.Exists).ToString()];
                actualValue   = GetFieldValue(fieldName, exists, jsonResult);
                expectedValue = subCheck.Options[((int)FieldGreaterThan.Value).ToString()];
                VerifyIsGreaterThan(expectedValue, actualValue, fieldName);
                break;

            case (int)SubCheckType.FieldLessThan:
                fieldName     = subCheck.Options[((int)FieldLessThan.FieldName).ToString()];
                exists        = subCheck.Options[((int)FieldLessThan.Exists).ToString()];
                actualValue   = GetFieldValue(fieldName, exists, jsonResult);
                expectedValue = subCheck.Options[((int)FieldLessThan.Value).ToString()];
                VerifyIsLessThan(expectedValue, actualValue, fieldName);
                break;

            default:
                _logger.Warn($"Unknown sub-check type {subCheck.TypeID} - ignoring");
                break;
            }
        }
        private void RunSubCheck(SubCheck subCheck, JArray jsonResult, CheckResult checkResult)
        {
            switch (subCheck.Type.Identifier)
            {
            case nameof(SubChecks.FieldEqualTo):
            case nameof(SubChecks.FieldNotEqualTo):
            case nameof(SubChecks.FieldGreaterThan):
            case nameof(SubChecks.FieldLessThan):
                var fieldCompareOptions = subCheck.GetOptions <FieldCompare>();
                var fieldName           = fieldCompareOptions.FieldName;
                var exists        = fieldCompareOptions.Exists;
                var actualValue   = GetFieldValue(fieldName, exists, jsonResult);
                var expectedValue = fieldCompareOptions.Value;
                switch (subCheck.Type.Identifier)
                {
                case nameof(SubChecks.FieldEqualTo):
                    VerifyAreEquals(expectedValue, actualValue, fieldName);
                    break;

                case nameof(SubChecks.FieldNotEqualTo):
                    VerifyAreNotEquals(expectedValue, actualValue, fieldName);
                    break;

                case nameof(SubChecks.FieldGreaterThan):
                    VerifyIsGreaterThan(expectedValue, actualValue, fieldName);
                    break;

                case nameof(SubChecks.FieldLessThan):
                    VerifyIsLessThan(expectedValue, actualValue, fieldName);
                    break;
                }
                break;

            default:
                _logger.Warn($"Unknown sub-check type {subCheck.TypeID} - ignoring");
                break;
            }
        }