c# - Testing using RHinomock -


i have class test tricky test using rhinomock unlike normal classes bacause constructor injected dependency not single interface array of interface objects. please me set stuff write test using rhinomock.

namespace clinicaladvantage.domain.userappsettings {     using system;     using system.collections.generic;     using system.linq;      using newtonsoft.json.linq;      public class agg : iagg     {         private readonly isource[] sources;          public agg(isource[] sources)         {             this.sources = sources;          }          public jobject getall()         {             var obj = new jobject();             foreach (var source in this.sources)             {                 var token = source.getcurr();                 if (token != null)                 {                     obj.add(new jproperty(source.name, token));                 }             }              return obj;         } } 

isource interface has 2 implementations. getall() iterates thro each implementated class object , calls getcurr method in each of object , aggregates result. have stub getcurr method return standard jtoken. unable create mock of class agg or stub of isource.

public interface isource     {         string name { get; }          bool enabled { get; }          jtoken getcurr();       } 

}

something might work:

[testclass] public class aggtest {     private isource isource;     private agg agg;      [testinitialize]     public void setup()     {         isource = mockrepository.generatemock<isource>();         agg = new agg(new [isource]);     }      [testmethod]     public void getall()     {         isource.stub(x => x.getcurr()).             return(new jtoken());          var jobject = agg.getall();          assert.isnotnull(jobject);         // assertion jproperty objects in jobject         // don't know syntax     } } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -