Hello, I have some questions about unit testing with Justmock.
I have this very simple method (Share Point code):
Code:
1 question.public
Guid CreateNewSite(String siteUrl,
string
newSite)
{
if
(!(
string
.IsNullOrEmpty(newSite) ||
string
.IsNullOrEmpty(siteUrl)))
{
using
(SPSite site =
new
SPSite(siteUrl))
{
if
(!site.AllWebs.Names.Contains(newSite))
{
return
site.AllWebs.Add(newSite, newSite,
"New Website"
, 1033,
"STS#1"
,
true
,
false
).ID;
}
}
}
return
Guid.Empty;
}
Is it ok, that I test the methods return (Guid). I mean I test the contract of the method "CreateNewSite". If the site that should be created not exist, and the parameters are not empty, the new site will be created and a Guid != Guid.Empty will be returned. Otherwise return Guid.Emtpy.
Or should I test, that the method site.AllWebs.Add(newSite, newSite, "New Website", 1033, "STS#1", true, false).ID; was called with the right parameters?
2 question.
How can I unit test the void methods (interaction testing) with Justmock.
For example this code:
public
void
AddSplistItemToList(SPWeb web, Guid listId, String listItemTitle)
{
if
(!(listId == Guid.Empty || listId == Guid.Empty ||
string
.IsNullOrEmpty(listItemTitle)))
{
SPList list = web.Lists[listId];
SPListItem item = list.Items.Add();
item[
"Title"
] = listItemTitle;
item.Update();
}
}
Because the AddSplistItemToList is void, I want to test, that item["Title"] would set correctly (value from listItemTitle parameter). How I can test and fake this with Justmock?I hope my questions are not too confused :)