/// <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)); }
/// <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)); }
/// <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. <---"); }
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); }
/// <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); }
internal void InsertCustomer(MyCustomer customer) { var results = Bouncer.ForMessages(() => customer).Assert(); Util.PrintEntries(results); }
/// <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("-", " ")); }
/// <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) + "<<"); }