Share via


Evolution of a hand rolled fake - part 2B

While the last version I showed is very flexible I have experimented a little more. Why would you ever have a public getter on the fake handler properties? Maybe if you had a fake that needed to wrap existing fake behavior but this is probably pretty rare. So this is what it would look like with no public getters. Again this is just to declutter the fake API surface.

  1: public class FakeTheInterface : ITheInterface
 2: {
 3:     private Action<int> doSomething;
 4:  
 5:     private Func<int, int, int> computeSomething;
 6:  
 7:     public Action<int> DoSomething
 8:     {
 9:         set { this.doSomething = value; }
 10:     }
 11:  
 12:     public Func<int, int, int> ComputeSomething
 13:     {
 14:         set { this.computeSomething = value; }
 15:     }
 16:  
 17:     void ITheInterface.DoSomething(int x)
 18:     {
 19:         Assert.IsNotNull(this.doSomething, "Unexpected call to DoSomething");
 20:         this.doSomething(x);
 21:     }
 22:  
 23:     int ITheInterface.ComputeSomething(int a, int b)
 24:     {
 25:         Assert.IsNotNull(
 26:             this.computeSomething, "Unexpected call to ComputeSomething");
 27:         return this.computeSomething(a, b);
 28:     }
 29: }

Comments

  • Anonymous
    July 02, 2012
    The comment has been removed