Last post Dec 03, 2014 07:26 AM by billcrawley
Member
202 Points
552 Posts
Dec 03, 2014 07:16 AM|billcrawley|LINK
HI all,
I had a set of unit tests that was working originally because they were written against a specific class i.e.
protected List<SWReportItem> _results; protected override void Because_of() { base.Because_of(); _results = _service.GetSWNewJoiners(1); } [TestMethod] public void then_the_pre_rdr_charge_Basis_is_populated() { _results.ForEach(c => c.PreRDRChargeBasis.ShouldEqual("PreRDRChargeBasis")); }
This worked fine as _service.GetSWNewJoiners(1) returned a list<SWReportItem>
As the code has been re-factored this method now returns a list of interfaces.
And ultimately gets populated with :
List<ICurrentSelectionProviderReportItem> result = new List<ICurrentSelectionProviderReportItem>(); SWReportItem reportItem = null; foreach (BasePensionReportItem item in newJoinerSelections) { reportItem = new SWReportItem(item); PopulateItem(reportItem); result.Add(reportItem); } return result;
So as you can see ultimately the interface has been populated with a typeof(SWReportItem)
normally I might do something like:
var castObject = _result.Where(c => c.GetType() == typeof(SWReportItem)).Cast<SWReportItem>().ToList());
However in this scenario I haven't got the Where clause available to me, as I would have then performed the test against my variable.
I thought then that I could do something like:
_results.ForEach(c => c.GetType() == typeof(SWReportItem).GetMember("PreRDRChargeBasis").ShouldEqual("PreRDRChargeBasis"));
but it still complains. How should I re-write my test
Dec 03, 2014 07:26 AM|billcrawley|LINK
[TestMethod] public void then_the_pre_rdr_charge_Basis_is_populated() { foreach (SWReportItem reportItem in _results) { reportItem.PreRDRChargeBasis.ShouldEqual("PreRDRChargeBasis"); } }
Member
202 Points
552 Posts
unit testing against an interface.
Dec 03, 2014 07:16 AM|billcrawley|LINK
HI all,
I had a set of unit tests that was working originally because they were written against a specific class i.e.
This worked fine as _service.GetSWNewJoiners(1) returned a list<SWReportItem>
As the code has been re-factored this method now returns a list of interfaces.
And ultimately gets populated with :
So as you can see ultimately the interface has been populated with a typeof(SWReportItem)
normally I might do something like:
However in this scenario I haven't got the Where clause available to me, as I would have then performed the test against my variable.
I thought then that I could do something like:
but it still complains. How should I re-write my test
Member
202 Points
552 Posts
Re: unit testing against an interface.
Dec 03, 2014 07:26 AM|billcrawley|LINK