chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
+1 vote
Hello,

I am mocking UserProfileValueCollection object in SharePoint. And trying to get Count property expected value using TypeMock. Somehow I am not able to get Count value when UserProfileValueCollection.Count is get.

In SharePoint UserProfileValueCollection class has been derived from System.Collections.CollectionBase abstract class, which is having get only Count property.

MSDN: http://msdn.microsoft.com/en-us/library ... ction.aspx
http://msdn.microsoft.com/en-us/library ... nbase.aspx


Productioncode:

UserProfileValueCollection UserProfileValue = profile["propertyName"];
ArrayList m_return = new ArrayList();

for (int i = 0; i <UserProfileValue.Count; i++)
{
m_return.Add(this.UserProfileValue[i]);
}

TestCode :

MockManager.Init();

// SPSite
Mock mockSPSiteAll = MockManager.Mock(typeof(SPSite));
MockObject mockSPSite = MockManager.MockObject(typeof(SPSite));
SPSite spSite = mockSPSite.Object as SPSite;
// ServerContext
Mock mockServerContextAll = MockManager.Mock(typeof(ServerContext));
MockObject mockServerContectObj = MockManager.MockObject(typeof(ServerContext));
ServerContext serverContect = mockServerContectObj.Object as ServerContext;
mockServerContextAll.AlwaysReturn("GetContext", serverContect);
// UserProfile
Mock mockUserProfAll = MockManager.Mock(typeof(Microsoft.Office.Server.UserProfiles.UserProfile));
MockObject mockUserProf = MockManager.MockObject(typeof(Microsoft.Office.Server.UserProfiles.UserProfile));
Microsoft.Office.Server.UserProfiles.UserProfile userProf = mockUserProf.Object as Microsoft.Office.Server.UserProfiles.UserProfile;
// UserProfileManager
Mock mockUserProfMgrAll = MockManager.Mock(typeof(UserProfileManager));
MockObject mockUserProfMgr = MockManager.MockObject(typeof(UserProfileManager));
UserProfileManager userProfMgr = mockUserProfMgr.Object as UserProfileManager;
// UserProfileValueCollection
Mock mockUserProfValCollAll = MockManager.Mock(typeof(UserProfileValueCollection));
MockObject mockUserProfValCollObj = MockManager.MockObject(typeof(UserProfileValueCollection));
UserProfileValueCollection userProfValColl = mockUserProfValCollObj.Object as UserProfileValueCollection;

// Property
MockObject mockPropertyObj = MockManager.MockObject(typeof(Property));
Property property = mockPropertyObj.Object as Property;

mockUserProfMgr.AlwaysReturn("GetUserProfile", userProf);
mockUserProfAll.ExpectGetIndexAlways(userProfValColl).Args("Instruments");
object[] values = new object[2];
values[0] = "Value";
values[1] = "Value";
mockUserProfValCollObj.ExpectGetAlways("Value", values);
mockUserProfValCollObj.ExpectGetAlways("Count", 2);
mockUserProfValCollObj.ExpectGetAlways("Property", property);
mockPropertyObj.ExpectGetAlways("IsMultivalued", true);
mockPropertyObj.ExpectGetAlways("IsUserEditable", true);
mockPropertyObj.ExpectGetAlways("Name", "Instruments");
mockUserProfValCollObj.ExpectGetAlways("Privacy", Privacy.Private);

// Production Code is called from here

MockManager.Verify();
asked by tarangnpatel (650 points)

1 Answer

0 votes
Hi Tarang,

I just wanted to let you know that I'll be looking into this issue and get back to you on email to follow up.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...