Exemplo n.º 1
0
        public void GivenAnExpressionWithMultipleArgumentsForIsNull_ThenItReturnsTrueIfAnyArgumentIsNull()
        {
            var protocol = ProtocolFactory.CreateTest();

            protocol.Sections.First().Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "isnull(1, 'text', null)"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();

            Assert.Equal(0, dataset.Issues.Count);
        }
Exemplo n.º 2
0
        public void GivenExpressionWithNullCoalescingForUnknownValue_ThenItIsNullInsteadOfThrowing()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "isnull([invalid?])"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();

            Assert.Equal(0, dataset.Issues.Count);
        }
Exemplo n.º 3
0
        public void GivenExternalValue_WhenInvalid_ThenAddError()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "this > 5"
            });

            var dataset = new DataSet(protocol);

            dataset.AddValue("a", 1);
            dataset.Calculate();

            Assert.Equal(1, dataset.Issues.Count(x => x.Item.Reference == "a" && x.Severity == IssueSeverity.ValidationError));
            Assert.Equal(1, dataset.Issues.Count);
        }
Exemplo n.º 4
0
        public void GivenDataSetWithMissingData_ThenTheyAreDetectedWhenCalculating()
        {
            var protocol = ProtocolFactory.CreateTest();

            protocol.Sections.First().Values.Add(new ValueDescriptor {
                Reference = "a"
            });
            protocol.Sections.First().Values.Add(new ValueDescriptor {
                Reference = "b", CalculatedValueExpression = "a * 2"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();

            // Value for "a" is required to calculate "b" but it has not been provided
            Assert.Equal(1, dataset.Issues.Count);
        }
Exemplo n.º 5
0
        public void GivenValue_WhenAlertedAndInvalid_ThenThereAreIssuesForBoth()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", WarningIfExpression = "this > 3", ValidIfExpression = "this < 5"
            });

            var dataset = new DataSet(protocol);

            dataset.AddValue("a", 6);
            dataset.Calculate();

            Assert.Equal(1, dataset.Issues.Count(x => x.Severity == IssueSeverity.ValidationError));
            Assert.Equal(1, dataset.Issues.Count(x => x.Severity == IssueSeverity.Warning));
            Assert.Equal(2, dataset.Issues.Count);
        }
Exemplo n.º 6
0
        public void WhenValuesHaveCalculatedOrLiteralDefaults_ThenTheyAreCalculatedAndCanBeRead()
        {
            var protocol = ProtocolFactory.CreateTest();

            protocol.Sections.First().Values.Add(new ValueDescriptor {
                Reference = "Literal", DefaultValueExpression = "2"
            });
            protocol.Sections.First().Values.Add(new ValueDescriptor {
                Reference = "LiteralExpression", DefaultValueExpression = "2 + 2"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();

            Assert.Equal(2.0, Convert.ToDouble(dataset["Literal"].Value));
            Assert.Equal(4.0, Convert.ToDouble(dataset["LiteralExpression"].Value));
        }
Exemplo n.º 7
0
        public void GivenExpressionWithRequired_ThenItIsTrueIfValueExists()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "required"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();
            Assert.Equal(1, dataset.Issues.Count);

            dataset = new DataSet(protocol);
            dataset.AddValue("a", 1);
            dataset.Calculate();
            Assert.Equal(0, dataset.Issues.Count);
        }
Exemplo n.º 8
0
        public void GivenExpressionWithThisKeyword_ThenItIsSynonimOfCurrentValueId()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "this == 1 and this == a"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "b", ValidIfExpression = "this == 2 and this == b"
            });

            var dataset = new DataSet(protocol);

            dataset.AddValue("a", 1);
            dataset.AddValue("b", 2);
            dataset.Calculate();

            Assert.Equal(0, dataset.Issues.Count);
        }
Exemplo n.º 9
0
        public void GivenValidationWithDependencies_ThenItIsCalculatedCorrectly(int a, int b)
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "b", ValidIfExpression = "this < a"
            });

            var dataset = new DataSet(protocol);

            dataset.AddValue("a", a);
            dataset.AddValue("b", b);
            dataset.Calculate();

            Assert.Equal(b < a ? 0 : 1, dataset.Issues.Count);
        }
Exemplo n.º 10
0
        public void GivenInvalidExternalValuesAndDependantCalculatedValue_ThenDependantValueIsNotCalculated()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "this < 5"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "b", CalculatedValueExpression = "a * 2", ValidIfExpression = "this < 10"
            });

            var dataset = new DataSet(protocol);

            dataset.AddValue("a", 5);
            dataset.Calculate();

            Assert.Equal(1, dataset.Issues.Count(x => x.Item.Reference == "a" && x.Severity == IssueSeverity.ValidationError));
            Assert.Equal(1, dataset.Issues.Count);
        }
Exemplo n.º 11
0
        public void WhenStoreValidValue_ThenItCanBeRead()
        {
            var protocol = ProtocolFactory.CreateTest();
            var a        = new ValueDescriptor {
                Reference = "a"
            };
            var b = new ValueDescriptor {
                Reference = "b"
            };

            protocol.Sections.First().Values.Add(a);
            protocol.Sections.First().Values.Add(b);

            var dataset = new DataSet(protocol);

            dataset.AddValue(a, 1.0);
            dataset.AddValue("b", 2.0);
            dataset.Calculate();

            Assert.Equal(1.0, Convert.ToDouble(dataset["a"].Value));
            Assert.Equal(2.0, Convert.ToDouble(dataset["b"].Value));
        }
Exemplo n.º 12
0
        public void GivenCalculatedValueWithValidation_ThenValidationIsApplied()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", ValidIfExpression = "this < 5"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "b", CalculatedValueExpression = "a * 2", ValidIfExpression = "this < 6"
            });

            // 4 is valid for a but it will fail validation for b. Another test will ensure that validation for
            // b is not even evaluated if validation for a isn't passed.
            var dataset = new DataSet(protocol);

            dataset.AddValue("a", 4);
            dataset.Calculate();

            Assert.Equal(1, dataset.Issues.Count(x => x.Item.Reference == "b" && x.Severity == IssueSeverity.ValidationError));
            Assert.Equal(1, dataset.Issues.Count);
        }
Exemplo n.º 13
0
        public void WhenCalculatedValueDependsOnValuesWithDefault_ThenItIsCalculatedCorrectly()
        {
            var protocol = ProtocolFactory.CreateTest();
            var section  = protocol.Sections.First();

            section.Values.Add(new ValueDescriptor {
                Reference = "a", DefaultValueExpression = "2"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "b", DefaultValueExpression = "2 + 2"
            });
            section.Values.Add(new ValueDescriptor {
                Reference = "c", CalculatedValueExpression = "a + b"
            });

            var dataset = new DataSet(protocol);

            dataset.Calculate();

            Assert.Equal(2.0, Convert.ToDouble(dataset["a"].Value));
            Assert.Equal(4.0, Convert.ToDouble(dataset["b"].Value));
            Assert.Equal(6.0, Convert.ToDouble(dataset["c"].Value));
        }