c# - mocking collection behavior with Moq -


I have read through some discussions on the MUC consumer group and have failed to find an example and so far I have I'm unable to find the scenario that I have here and my question is:

  // Schedule over 6 periods = new list & lt; PaymentPlanPeriod & gt; () {New PaymentPlanPeriod (1000 m, args.MinDate.ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate.Value.AddMonths (1) .ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate. Value.AddMonths (2) .ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate.Value.AddMonths (3) .ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate.Value.AddMonths (4) .ToString ()), New PaymentPlanPeriod (1000m, args.MalDate.Value.AddMonths (5) .toString ())}; // is now correct with the Proxy Schedule Assistant. Setup (H = & gt; H. Gateplan Periods (This. ISNAi; string & gt; (), schedule);  

Then in my tests I use the term but the Mall _PaymentPlanHelper does not store the collection at any time, for use below see:

  public IEnumerable & Lt; PaymentPlanPeriod & gt; Duration {get (if (Kankululet expression ()) _PaymentPlanHelper.GetPlanPeriods (this.ToString (), _PaymentSchedule); return _PaymentSchedule;}}  

An overloaded method so that I GetPlanPeriods using my way to change the mocked object for which this type of list is:

  var schedule = new list & lt; PaymentPlanPeriod & gt; () {new PaymentPlanPeriod (1000 m, args .MinDate.ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate.Value.AddMonths (1) .ToString ()), new PaymentPlanPeriod (1000 m, args.MinDate.Value .AddMonths (2) .ToString () ), New PaymentPlanPeriod (1000m, args.MinDate.Value.AddMonths (3) .ToString ()), New PaymentPlanPeriod (1000m, ArgskMinDatekValuekAddMonths (4) KToString ()), new Pementpenliperiod (1000 meters, args. Mintdet. Valu.admonths (5) Kostring ())}; Assistant Ksetap (H = & gt; H. GetPlan Periods (This. Anyone; String & gt; ()). Returns (New list & payment; Payment period & gt; (Schedule); & lt; PaymentPlanPeriod & gt; Results = new _PaymentPlanHelper.GetPlanPeriods (this.ToString ());  

It works as expected, any sign will be horrible, unless you believe my architecture ... ...)

Thank you, Stephen

Setup-method is basically to set up some xpended behaviors. For example, setting up a mock-instance to return some values. For example, a configuration-duplicate:

  var configMock = new mock & lt; IConfiguration & gt; (); ConfigMock.Setup (c => c.etetetting ("title")). Returns ("Hello Word"); ConfigMock.Setup (c = & gt; c.GetSetting ("Answer")) returns ("42").  

This means, when you pass GetSetting-Method to "title" then the fake "Hello word" will come back. And when you pass the "answer" to the fake, it will return "42". You can configure wildcard by adding it. For example:

  var configMock = new fake & lt; IConfiguration & gt; (); ConfigMock.Setup (c => c.etetetting (this.isannie  ())). Returns ("Hello Word"); Now the fake GetSetting-method will come back for any call to string "Hello World" 

Now in your first case you set this fake in this way : Expect to call GetPlanPeriods with any string and this list. So with the second parameter you specify what list you want to expect. But you do not set up any Bahuwar for this call.

Afacks, you can decide something with logic. Like this:

  helper.Setup (c = & gt; c.GetPlanPeriods (It.IsAny & lt; string & gt; (), from it.IsAny & LT; list & lt; PaymentPlanPeriod & gt; ()) .Callback ((string s, list; payment peniproducts> gt = L) => (l.ed. (new paymentPailPieriod (1000m, RG mindedToostring ()); });  

In the second example, you can set the duplicate in this way: expect CallPrint Call GetPlanPeriods with any string, and then return to this list. Come back for any call from That's why it works. Thats.

I would normally recommend to design my API in such a way that you have other examples that prefer to return the converted archive instead of updating the collection passed. It is easy to use these methods and joke.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -