unit testing sharepoint maksim matsveyeu, 2012. what are we talking about +=+ microsoft fakes

7
Unit testing SharePoint Maksim Matsveyeu, 2012

Upload: darcy-flynn

Post on 03-Jan-2016

217 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Unit testing SharePoint Maksim Matsveyeu, 2012.  What are we talking about +=+ Microsoft Fakes

Unit testing SharePoint

Maksim Matsveyeu, 2012

Page 2: Unit testing SharePoint Maksim Matsveyeu, 2012.  What are we talking about +=+ Microsoft Fakes

www.scnsoft.com

What are we talking about

+ =+Microsoft Fakes

Page 3: Unit testing SharePoint Maksim Matsveyeu, 2012.  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?

Page 4: Unit testing SharePoint Maksim Matsveyeu, 2012.  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(); }

SPContext.Current = new SPContextFake();

ShimSPContext.CurrentGet = delegate() { return new

ShimSPContext(); };

ShimSPContext.CurrentGet = () => { return new

ShimSPContext(); };

ShimSPContext.CurrentGet = () => new ShimSPContext();

Page 5: Unit testing SharePoint Maksim Matsveyeu, 2012.  What are we talking about +=+ Microsoft Fakes

www.scnsoft.com

Demo

Page 6: Unit testing SharePoint Maksim Matsveyeu, 2012.  What are we talking about +=+ Microsoft Fakes

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?

Page 7: Unit testing SharePoint Maksim Matsveyeu, 2012.  What are we talking about +=+ Microsoft Fakes

www.scnsoft.com

Questions