Hi
I try to fake the getitems method on a list i the sharepoint clientcontext. For some reason its always returning no elements. Can someone put me in the right direction?
ClientContext context = Isolate.Fake.NextInstance<ClientContext>();
List list = Isolate.Fake.Instance<List>();
ListItem fakeListItem = Isolate.Fake.Instance<ListItem>();
List<ListItem> listItems =
new
List<ListItem> { fakeListItem, fakeListItem, fakeListItem };
Isolate.WhenCalled(() => list.GetItems(
null
)).WillReturnCollectionValuesOf(listItems);
Isolate.WhenCalled(() => context.Web.Lists.GetByTitle(
string
.Empty)).WillReturn(list);
Isolate.WhenCalled(() => context.Load(list)).IgnoreCall();
Isolate.WhenCalled(() => context.ExecuteQuery()).IgnoreCall();
// Act
var cut =
new
ClassUnderTest();
int
itemsCount = cut.GetListItemsCount(
string
.Empty,
string
.Empty);
Here itemsCount returns always 0 elements. Am I using a wrong context/instance?
GetListItemsCount is doing the following
using
(ClientContext clientContext =
new
ClientContext(siteUrl))
{
List theList = clientContext.Web.Lists.GetByTitle(listTitle);
CamlQuery q = CamlQuery.CreateAllItemsQuery();
var items = theList.GetItems(q);
clientContext.Load(theList);
clientContext.Load(items);
clientContext.ExecuteQuery();
return
items.Count;
}
Nothing special so far.