New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

No Title

46 Views
Copy Code Show/Hide Line Numbers
/// <summary>
    /// THIS CLASS CAN'T BE TESTED LIKE CRAZY SINCE IT'S CLOSED
    /// IE THE NESTED CLOSURE PREVENTS YOU FROM INJECTING MOCK
    /// FOOS TO MAKE SURE THAT PROCESSMESSAGE WORKS LIKE IT
    /// SHOULD.
    /// 
    /// INSTEAD THE CLASS PUTS AN API ONTOP OF THE "RAW" UNDERLAYING
    /// CODE
    /// 
    /// "DSL"
    /// </summary>
    public class FooManager : IFooManager
    {
        public FooManager()
        {
            this.Model = new FooModel();
        }
 
        private FooModel Model { get; set; }
 
        public void Configure(Action<IFooCommands> closure)
        {
            var commands =
                new FooCommands();
 
            closure(commands);
 
            this.Model.Foos.Concat(commands.GetFoos());
        }
 
        public void ProcessMessage(ref Message message)
        {
            this.Model.ProcessMessage(ref message);
        }
    }
 
    /// <summary>
    /// THIS CLASS CAN BE TESTED LIKE CRAZY
    /// "SEMANTIC MODEL"
    /// </summary>
    public class FooModel
    {
        public FooModel()
        {
            this.Foos = new List<IFoo>();
        }
 
        public IList<IFoo> Foos { get; set; }
 
        public void ProcessMessage(ref Message message)
        {
            var id = message.LParam.ToInt32();
 
            var foo = 
                this.Foos.Where(f => f.Id == id).SingleOrDefault();
 
            if (foo != null)
            {
                foo.Callback.Invoke(foo);
            }
        }
    }
by TheCodeJunkie
  November 03, 2009 @ 2:20pm

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate