Example #1
0
        public void AunnCoo_RequireGuidToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                ThisGuid = Guid.NewGuid(), ThatGuid = Guid.NewGuid(), OtherInfo = Guid.NewGuid()
            };

            var context   = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member1   = context.GetValue("ThisGuid");
            var member2   = context.GetValue("ThatGuid");
            var member3   = context.GetValue("OtherInfo");
            var contract1 = member1.ExposeContract();
            var contract2 = member2.ExposeContract();
            var contract3 = member3.ExposeContract();

            var token1 = new ValueRequiredGuidToken(contract1);
            var token2 = new ValueRequiredGuidToken(contract2);
            var token3 = new ValueRequiredGuidToken(contract3);

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member1).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member2).IsSuccess.ShouldBeTrue();

            token3.Valid(context).IsSuccess.ShouldBeTrue();
            token3.Valid(member3).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Func_For_GenericFuncToken_And_ShouldBeValid()
        {
            var model = new AunnCoo {
                AunnClass = AunnEnum.One
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("AunnClass");
            var contract = member.ExposeContract();
            Func <AunnEnum, CustomVerifyResult> condition = obj =>
            {
                if (obj is AunnEnum a && a == AunnEnum.One)
                {
                    return new CustomVerifyResult {
                               VerifyResult = true
                    }
                }
                ;
                return(new CustomVerifyResult {
                    VerifyResult = false
                });
            };

            var token = new ValueFuncToken <AunnEnum>(contract, condition);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
Example #3
0
        public void AunnCoo_Discount_Nullable_ScalePrecisionToken_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                NullableDiscount = 123.456778M
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("NullableDiscount");
            var contract = member.ExposeContract();

            var token = new ValueScalePrecisionToken(contract, 2, 4);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();

            model = new AunnCoo {
                NullableDiscount = 12.3414M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("NullableDiscount");

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();

            model = new AunnCoo {
                NullableDiscount = 12.344M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("NullableDiscount");

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();

            model = new AunnCoo {
                NullableDiscount = 1.344M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("NullableDiscount");

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();

            model = new AunnCoo {
                NullableDiscount = 156.3M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("NullableDiscount");

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();

            model = new AunnCoo {
                NullableDiscount = 65.430M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("NullableDiscount");

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_String_GenericStringEnumToken_Test()
        {
            var model = new AunnCoo {
                Name = "One"
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();

            var token1 = new ValueStringEnumToken <AunnEnum>(contract, false);
            var token2 = new ValueStringEnumToken <AunnEnum>(contract, true);

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member).IsSuccess.ShouldBeTrue();

            model.Name = "one";
            context    = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member     = context.GetValue("Name");

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeFalse();
            token2.Valid(member).IsSuccess.ShouldBeFalse();
        }
Example #5
0
        public void AunnCoo_RequireBooleanToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                IsThisOk = true, IsThatOk = true, OtherInfo = true
            };

            var context   = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member1   = context.GetValue("IsThisOk");
            var member2   = context.GetValue("IsThatOk");
            var member3   = context.GetValue("OtherInfo");
            var contract1 = member1.ExposeContract();
            var contract2 = member2.ExposeContract();
            var contract3 = member3.ExposeContract();

            var token1 = new ValueRequiredBooleanToken(contract1);
            var token2 = new ValueRequiredBooleanToken(contract2);
            var token3 = new ValueRequiredBooleanToken(contract3);

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member1).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member2).IsSuccess.ShouldBeTrue();

            token3.Valid(context).IsSuccess.ShouldBeTrue();
            token3.Valid(member3).IsSuccess.ShouldBeTrue();
        }
Example #6
0
        public void AunnCoo_String_For_NotEmptyToken_And_ShouldBeValid()
        {
            var model = new AunnCoo();

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();

            var token = new ValueNotEmptyToken(contract);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_Null_For_NullToken_And_ShouldBeValid()
        {
            var model = new AunnCoo();

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("OtherInfo");
            var contract = member.ExposeContract();

            var token = new ValueNullToken(contract);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Array_For_EmptyToken_And_ShouldBeValid()
        {
            var model = new AunnCoo {
                Career = new string[0]
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Career");
            var contract = member.ExposeContract();

            var token = new ValueEmptyToken(contract);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Regex_RegexExprToken_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                Name = "AlicE"
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();

            var token = new ValueRegularExpressionToken(contract, new Regex(@"^(Al)\w+(e)$"));

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
Example #10
0
        public void AunnCoo_ValueType_For_GreaterThanToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                Age = 10
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Age");
            var contract = member.ExposeContract();

            var token = new ValueGreaterThanToken(contract, 10);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_String_MaxLimitedToken_And_ShouldBeIsvalid()
        {
            var model = new AunnCoo {
                Name = "Hello"
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();

            var token = new ValueMaxLengthLimitedToken(contract, 4);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_Enum_For_EnumToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                AunnClass = AunnEnum.One
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("AunnClass");
            var contract = member.ExposeContract();

            var token = new ValueEnumToken(contract, typeof(AunnEnum2));

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_UndefinedEnum_For_GenericEnumToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                AunnClass = (AunnEnum)100
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("AunnClass");
            var contract = member.ExposeContract();

            var token = new ValueEnumToken <AunnEnum2>(contract);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
Example #14
0
        public void AunnCoo_DefaultValue_For_NotEmptyToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                Age = 10
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Age");
            var contract = member.ExposeContract();

            var token = new ValueNotEmptyToken(contract);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Object_For_GenericEqualToken_And_ShouldBeValid()
        {
            var model = new AunnCoo {
                OtherInfo = Haha
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("OtherInfo");
            var contract = member.ExposeContract();

            var token = new ValueEqualToken <object>(contract, Haha, null);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_ValueType_For_GenericEqualToken_And_ShouldBeValid()
        {
            var model = new AunnCoo {
                Age = 10
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Age");
            var contract = member.ExposeContract();

            var token = new ValueEqualToken <int>(contract, 10, null);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_RegexFunc_GenericRegexExprToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                Name = "Alice", AunnRegexExpression = @"^(Al)\w+(e)$"
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();
            Func <AunnCoo, Regex> expression = obj => new Regex(obj.AunnRegexExpression);

            var token = new ValueRegularExpressionToken <AunnCoo>(contract, expression);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
Example #18
0
        public void AunnCoo_Array_For_AllToken_And_ShouldBeValid()
        {
            var model = new AunnCoo
            {
                Career = new[] { "Nice", "Normal", "New" }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Career");
            var contract = member.ExposeContract();
            Func <object, bool> condition = obj => obj is string str && str.StartsWith("N");

            var token = new ValueAllToken(contract, condition);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Array_For_GenericAnyToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo
            {
                Career = new[] { "Nice", "Good", "Hello" }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Career");
            var contract = member.ExposeContract();
            Func <object, bool> condition = obj => obj is string str && str.EndsWith("N");

            var token = new ValueAnyToken <string[], string>(contract, condition);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
Example #20
0
        public void AunnCoo_List_For_NotEmptyToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                Tags = new List <string> {
                    "Nice", "Good", "Hello"
                }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Tags");
            var contract = member.ExposeContract();

            var token = new ValueNotEmptyToken(contract);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
Example #21
0
        public void AunnCoo_One_For_NotInToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo
            {
                Name = "N"
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Name");
            var contract = member.ExposeContract();

            var token = new ValueNotInToken(contract, new List <object> {
                "Nice", "Duo", "Long", "N"
            });

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
Example #22
0
        public void AunnCoo_List_For_GenericAllToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo
            {
                Tags = new List <string> {
                    "Nice", "Normal", "New"
                }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Tags");
            var contract = member.ExposeContract();
            Func <object, bool> condition = obj => obj is string str && str.EndsWith("N");

            var token = new ValueAllToken <List <string>, string>(contract, condition);

            token.Valid(context).IsSuccess.ShouldBeFalse();
            token.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_Int_For_RangeToken_And_ShouldBeValid()
        {
            var model = new AunnCoo {
                Age = 10
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Age");
            var contract = member.ExposeContract();

            var token1 = new ValueRangeToken(contract, 9, 11, RangeOptions.OpenInterval);
            var token2 = new ValueRangeToken(contract, 9, 10, RangeOptions.CloseInterval);

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_Char_For_RangeToken_And_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                C = 'b'
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("C");
            var contract = member.ExposeContract();

            var token1 = new ValueRangeToken(contract, 'b', 'c', RangeOptions.OpenInterval);
            var token2 = new ValueRangeToken(contract, 'a', 'a', RangeOptions.CloseInterval);

            token1.Valid(context).IsSuccess.ShouldBeFalse();
            token1.Valid(member).IsSuccess.ShouldBeFalse();

            token2.Valid(context).IsSuccess.ShouldBeFalse();
            token2.Valid(member).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_List_For_AnyToken_And_ShouldBeValid()
        {
            var model = new AunnCoo
            {
                Tags = new List <string> {
                    "Nice", "Good", "Hello"
                }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Tags");
            var contract = member.ExposeContract();
            Func <object, bool> condition = obj => obj is string str && str.StartsWith("N");

            var token = new ValueAnyToken(contract, condition);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
Example #26
0
        public void AunnCoo_Discount_ScalePrecisionToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                Discount = 12.34M
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Discount");
            var contract = member.ExposeContract();

            var token = new ValueScalePrecisionToken(contract, 2, 4);

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();

            model = new AunnCoo {
                Discount = 2.34M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("Discount");

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();

            model = new AunnCoo {
                Discount = -2.34M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("Discount");

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();

            model = new AunnCoo {
                Discount = 0.34M
            };
            context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            member  = context.GetValue("Discount");

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
Example #27
0
        public void AunnCoo_List_For_GenericNotInToken_And_ShouldBeValid()
        {
            var model = new AunnCoo
            {
                Tags = new List <string> {
                    "Nice", "Normal", "New"
                }
            };

            var context  = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member   = context.GetValue("Tags");
            var contract = member.ExposeContract();

            var token = new ValueNotInToken <List <string>, string>(contract, new List <string> {
                "Bad", "Duo", "Long"
            });

            token.Valid(context).IsSuccess.ShouldBeTrue();
            token.Valid(member).IsSuccess.ShouldBeTrue();
        }
        public void AunnCoo_GenericRequireTypesToken_1_N_ShouldBeInvalid()
        {
            var model = new AunnCoo {
                AunnClass = AunnEnum.One, AunnType = typeof(string)
            };

            var context   = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member1   = context.GetValue("AunnClass");
            var member2   = context.GetValue("AunnType");
            var contract1 = member1.ExposeContract();
            var contract2 = member2.ExposeContract();

            var token1 = new ValueRequiredTypesToken <string, AunnEnum2>(contract1);
            var token2 = new ValueRequiredTypesToken <AunnEnum, AunnEnum2>(contract2);

            token1.Valid(context).IsSuccess.ShouldBeFalse();
            token1.Valid(member1).IsSuccess.ShouldBeFalse();

            token2.Valid(context).IsSuccess.ShouldBeFalse();
            token2.Valid(member2).IsSuccess.ShouldBeFalse();
        }
        public void AunnCoo_RequireTypeToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                AunnClass = AunnEnum.One, AunnType = typeof(string)
            };

            var context   = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member1   = context.GetValue("AunnClass");
            var member2   = context.GetValue("AunnType");
            var contract1 = member1.ExposeContract();
            var contract2 = member2.ExposeContract();

            var token1 = new ValueRequiredTypeToken(contract1, typeof(AunnEnum));
            var token2 = new ValueRequiredTypeToken(contract2, typeof(string));

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member1).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member2).IsSuccess.ShouldBeTrue();
        }
Example #30
0
        public void AunnCoo_RequireNumericToken_ShouldBeValid()
        {
            var model = new AunnCoo {
                Age = 10, OtherInfo = 20
            };

            var context   = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model);
            var member1   = context.GetValue("Age");
            var member2   = context.GetValue("OtherInfo");
            var contract1 = member1.ExposeContract();
            var contract2 = member2.ExposeContract();

            var token1 = new ValueRequiredNumericToken(contract1);
            var token2 = new ValueRequiredNumericToken(contract2);

            token1.Valid(context).IsSuccess.ShouldBeTrue();
            token1.Valid(member1).IsSuccess.ShouldBeTrue();

            token2.Valid(context).IsSuccess.ShouldBeTrue();
            token2.Valid(member2).IsSuccess.ShouldBeTrue();
        }