示例#1
0
        public void OrRequirementChildrenSerializesCorrectly()
        {
            var trueFalseOr = new OrRequirement(trueRequirement, falseRequirement);
            var json        = System.Text.Json.JsonSerializer.Serialize(trueFalseOr);

            // Check the JSON string to make sure the derived requirement is serialized correctly
            // via OrRequirement.children
            var position = -1;

            for (var i = 0; i < trueFalseOr.Children.Length; i++)
            {
                position = json.IndexOf(trueRequirement.Marker, position + 1);
                Assert.True(position > 0);
            }

            // Make sure we don't support deserialization - it's not needed and can be dangerous.
            Assert.Throws <NotSupportedException>(() => System.Text.Json.JsonSerializer.Deserialize <OrRequirement>(json));
        }
示例#2
0
        public void OrRequirementBehavesCorrectly()
        {
            var trueFalseOr = new OrRequirement(trueRequirement, falseRequirement);

            Assert.Equal(OperatorType.Or, trueFalseOr.Operator);
            Assert.True(trueFalseOr.Evaluate(this.context, null));
            Assert.Equal(2, trueFalseOr.Children.Length);

            var falseTrueOr = new OrRequirement(falseRequirement, trueRequirement);

            Assert.Equal(OperatorType.Or, falseTrueOr.Operator);
            Assert.True(falseTrueOr.Evaluate(this.context, null));
            Assert.Equal(2, trueFalseOr.Children.Length);

            var allFalseOr = new OrRequirement(falseRequirement, falseRequirement);

            Assert.Equal(OperatorType.Or, allFalseOr.Operator);
            Assert.False(allFalseOr.Evaluate(this.context, null));
            Assert.Equal(2, trueFalseOr.Children.Length);
        }