public void JoinPrivateCommunity() { context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); var usr2 = User.FromUsername(context, "testusr2"); var ose = MasterCatalogue.OpenSearchEngine; var parameters = new NameValueCollection(); try { context.StartImpersonation(usr1.Id); ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-private-1"); Role role = Role.FromIdentifier(context, RoleTep.MEMBER); //check how many communities user can see var communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; IOpenSearchResultCollection osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); context.EndImpersonation(); context.StartImpersonation(usr2.Id); //add user in community community.SetUserAsTemporaryMember(usr1); Assert.True(community.IsUserPending(usr1.Id)); context.EndImpersonation(); context.StartImpersonation(usr1.Id); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC + 1, osr.TotalResults); //check visibility is private + pending var items = osr.Items; bool isprivate = false, isVisibilityPending = false, ispublic = false; foreach (var item in items) { if (item.Title.Text == "community-private-1") { foreach (var cat in item.Categories) { if (cat.Name == "visibility") { if (cat.Label == "hidden") { isprivate = true; } else if (cat.Label == "public") { ispublic = true; } } else if (cat.Name == "status" && cat.Label == "pending") { isVisibilityPending = true; } } } } Assert.True(isprivate); Assert.True(isVisibilityPending); Assert.False(ispublic); //usr1 validates community.TryJoinCurrentUser(); Assert.True(community.IsUserPending(usr1.Id)); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC + 1, osr.TotalResults); //remove from community community.RemoveUser(usr1); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }