This project has moved and is read-only. For the latest updates, please go here.
This page describes how to use SharepointCommon with unit testing and TDD.

Mock objects

Mock QueryWeb and QueryList with Moq

// create QueryWeb moq
var moqQueryWeb = new Mock<IQueryWeb>();

// create QueryList moq
var moqQueryList = new Mock<IQueryList<Item>>(MockBehavior.Strict);

// setup GetByName method to return moq
moqQueryWeb.Setup(m => m.GetByName<Item>(It.IsAny<string>()))

// TODO: perform additional setup on moqQueryList

IQueryWeb queryWeb = moqQueryWeb.Object;
IQueryList<Item> queryList = queryWeb.GetByName<Item>("Test");

// start using queryWeb and queryList

Last edited Jan 1, 2014 at 10:13 PM by devi_ous, version 4


No comments yet.