コード例 #1
0
 /// <summary>
 /// This method does already know, that calling GetTheName will fail,
 /// but it does not check for customer to have a name set.
 /// </summary>
 /// <param name="customer"></param>
 internal void WriteCustomerProperties(MyCustomer customer)
 {
     Console.WriteLine(
         "calling customer {0} with Id {1}",
         GetTheName(customer),
         FormatTheId(customer));
 }
コード例 #2
0
        /// <summary>
        /// We need to use the type MySaveCustomer in order to correctly resolve type inference for
        /// Bouncer.ForCheckData(() => customer).Assert();
        /// </summary>
        /// <param name="customer">this customer type does have rule-attributes attached to its properties</param>
        internal new void WriteCustomerProperties(MyCustomer customer)
        {
            Bouncer.ForCheckData(() => customer).Assert();

            Console.WriteLine(
                "calling customer {0} with Id {1}",
                GetTheName(customer),
                FormatTheId(customer));
        }
コード例 #3
0
        /// <summary>
        /// This time we will not prevent executing the method code, but
        /// just collect the violated rules and print them to the console.
        /// The rule is a custom one that checks for a specific string inside
        /// a specific property. You might reuse such logic by inheriting
        /// from RuleBase and initialize the CheckExpression inside the
        /// constructor.
        /// </summary>
        /// <param name="customer"></param>
        internal void CheckCustomerWithCustomRule(MyCustomer customer)
        {
            var results = Bouncer
                          .ForMessages(() => customer)
                          .Assert(new RuleBase <MyCustomer, object>
            {
                Message         = "Sven cannot enter this method",
                CheckExpression = (x, y) => x.FullName != "Sven"
            });

            Util.PrintEntries(results);
            Console.WriteLine("---> ForMessages did return the validation results, but  <---");
            Console.WriteLine("--->   did not cause any exception. So \"customer Sven\"   <---");
            Console.WriteLine("--->   did enter the method  and did execute all code.   <---");
        }
コード例 #4
0
        public void CheckCustomerWithWithMethodAttributes(string customerId, int amount, MyCustomer theCustomer)
        {
            Bouncer
            .ForCheckData(() => customerId)
            .ForCheckData(() => amount)
            .ForCheckData(() => theCustomer)
            .Assert();

            var results = Bouncer
                          .ForMessages(() => customerId)
                          .ForMessages(() => amount)
                          .ForMessages(() => theCustomer)
                          .Assert();

            Util.PrintEntries(results);
        }
コード例 #5
0
        /// <summary>
        /// This time we will not prevent executing the method code, but
        /// just collect the violated rules and print them to the console.
        /// </summary>
        /// <param name="customer"></param>
        internal void CheckCustomerProperties(MyCustomer customer)
        {
            var results = Bouncer.ForMessages(() => customer).Assert();

            Util.PrintEntries(results);
        }
コード例 #6
0
        internal void InsertCustomer(MyCustomer customer)
        {
            var results = Bouncer.ForMessages(() => customer).Assert();

            Util.PrintEntries(results);
        }
コード例 #7
0
 /// <summary>
 /// This is called from CallCustomer - both business components "MyBusinessComponent"
 /// and "MySaveBusinessComponent" do call this method.
 /// </summary>
 /// <param name="customer">the customer to get the name from</param>
 /// <returns>the string-processed name property</returns>
 protected static string GetTheName(MyCustomer customer)
 {
     return(customer.FullName.Replace("-", " "));
 }
コード例 #8
0
 /// <summary>
 /// This is called from CallCustomer - both business components "MyBusinessComponent"
 /// and "MySaveBusinessComponent" do call this method.
 /// </summary>
 /// <param name="customer">the customer to get the id from</param>
 /// <returns>a formatted id</returns>
 protected static string FormatTheId(MyCustomer customer)
 {
     return(">>" + customer.InternalId.ToString().Replace("-", string.Empty) + "<<");
 }