Пример #1
0
        public Task AddUserToGroup(string groupId, string userId)
        {
            if (Users.Count == 0)
            {
                throw new ArgumentException($"no users were preconfigured. Call 'PreConfigureUserInMock' to do so.");
            }

            if (!Users.Any(u => u.Id.Equals(userId)))
            {
                throw new ArgumentException($"user with id {userId} was not preconfigured. Call 'PreConfigureUserInMock' to do so.");
            }
            var user = Users.First(u => u.Id.Equals(userId));

            if (!UsersInGroup.ContainsKey(groupId))
            {
                UsersInGroup.Add(groupId, new List <string>()
                {
                    userId
                });
            }
            else
            {
                var group = UsersInGroup.First(g => g.Key.Equals(groupId));

                if (!group.Value.Any(id => id.Equals(userId)))
                {
                    ;
                }
                {
                    group.Value.Add(userId);
                }
            }
            return(Task.CompletedTask);
        }
Пример #2
0
        public Task RemoveUserFromGroup(string groupId, string userId)
        {
            var user = Users.First(u => u.Id.Equals(userId));

            if (UsersInGroup.ContainsKey(groupId))
            {
                if (UsersInGroup[groupId].Exists(u => u.Equals(userId)))
                {
                    UsersInGroup[groupId].Remove(user.Id);
                    return(Task.CompletedTask);
                }
                throw new ArgumentException("user does not exists");
            }
            throw new ArgumentException("group does not exists");
        }