Thank you for the questions.
About your first question, I can say that you should cover everything your method is supposed to do. For example:
- Your method is called "CreateNewSite" and it returns a GUID. In this case it is recommended to test if the returned GUID is correct, according to the arguments passed and further it is also good to check if the inner called method "
site.AllWebs.Add" has been called with the correct arguments. However, which one is better or more suitable in your case will depend on what is the exact purpose of the "CreateNewSite" and what side effects you want to cover.
About your second question, I will say testing void methods can be tricky. For further information, I suggest checking this thread
. However, to test if item["Title"] has been set correctly you may need to extract the SPListItem item as a class property, like this:
AddSplistItemToList(SPWeb web, Guid listId, String listItemTitle)
(!(listId == Guid.Empty || listId == Guid.Empty ||
SPList list = web.Lists[listId];
item = list.Items.Add();
] = listItemTitle;
Having it like that, you will be able to assert against its value. In other words, you will be able to do something similar to this:
var someSPWeb = Mock.Create<SPWeb>();
var anyGUID =
var anyListItemTitle =
var myClass =
myClass.AddSplistItemToList(someSPWeb, anyGUID, anyListItemTitle);
I hope my answers help.
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums
, or our JustTrace