Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

SharePoint UserProfileValueCollection.Count property

0 votes
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 Jun 26, 2008 by tarangnpatel (160 points)

1 Answer

+2 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 Jun 27, 2008 by doron (26,680 points)
...