public void users_can_be_added_to_a_group() { _userGroup.AddUser(_user1); _userGroup.AddUser(_user2); Session.Save(_userGroup); Flush(); Assert.IsTrue(_user1.UserGroups.Contains(_userGroup)); Assert.IsTrue(_user2.UserGroups.Contains(_userGroup)); Clear(); var retrievedGroup = Session.Get <UserGroup>(_userGroup.Id); Assert.IsTrue(retrievedGroup.Users.Contains(_user1)); Assert.IsTrue(retrievedGroup.Users.Contains(_user2)); }
/// <summary> /// Tries to load a User Group based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; UserGroup result = null; switch (targetType.FullName) { case UserGroup: result = new UserGroup(); // Get the members of the Group IEnumerable <INode> members = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyMember))); foreach (INode member in members) { String username, password; ConfigurationLoader.GetUsernameAndPassword(g, member, true, out username, out password); if (username != null && password != null) { result.AddUser(new NetworkCredential(username, password)); } else { throw new DotNetRdfConfigurationException("Unable to load the User identified by the Node '" + member.ToString() + "' as there does not appear to be a valid username and password specified for this User either via the dnr:user and dnr:password properties or via a dnr:credentials property"); } } // Get the allow list for the Group IEnumerable <INode> allowed = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAllow))); foreach (INode allow in allowed) { Object temp = ConfigurationLoader.LoadObject(g, allow); if (temp is IPermission) { result.AddAllowedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + allow.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } // Get the deny list for the Group IEnumerable <INode> denied = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDeny))); foreach (INode deny in denied) { Object temp = ConfigurationLoader.LoadObject(g, deny); if (temp is IPermission) { result.AddDeniedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + deny.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } // Does the User Group require authentication? result.AllowGuests = !ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyRequiresAuthentication)), true); // Is there a permission model specified? String mode = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyPermissionModel))); if (mode != null) { result.PermissionModel = (PermissionModel)Enum.Parse(typeof(PermissionModel), mode); } break; } obj = result; return(result != null); }