unit testing sharepoint maksim matsveyeu, 2012. what are we talking about +=+ microsoft fakes
TRANSCRIPT
Unit testing SharePoint
Maksim Matsveyeu, 2012
www.scnsoft.com
What are we talking about
+ =+Microsoft Fakes
www.scnsoft.com
Challenge
public List<DTO> GetLists() { return SPContext.Current.Web .Lists .OfType<SPList>() .Select(list => new DTO { Title = list.Title }) .ToList(); }
How to unit test this?
www.scnsoft.com
Challenge
public List<DTO> GetLists() { return SPContext.Current.Web .Lists .OfType<SPList>() .Select(list => new DTO { Title = list.Title }) .ToList(); }
SPContext.Current = new SPContextFake();
ShimSPContext.CurrentGet = delegate() { return new
ShimSPContext(); };
ShimSPContext.CurrentGet = () => { return new
ShimSPContext(); };
ShimSPContext.CurrentGet = () => new ShimSPContext();
www.scnsoft.com
Demo
www.scnsoft.com
Conclusion
Looking forward to new releases of VS 11• We’re using beta. Why?
Because it’s betta than nothing. ©
• Is Pex gone?
• Should we really write all behaviors ourselves?
www.scnsoft.com
Questions