Ejemplo n.º 1
0
        public static String createUserTest(Client client)
        {
            // create a test user
            User user = new User();
            user.userName = "******";
            user.externalId = "mcrooke";
            user.displayName = "Mr Matt Crooke";

            // set the user names
            user.name = new Name();
            user.name.givenName = "Matt";
            user.name.familyName = "Crooke";
            user.name.formatted = "Mr Matt Crooke";

            // set the user emails
            PluralAttribute email = new PluralAttribute();
            email.primary = true;
            email.value = "*****@*****.**";
            PluralAttribute[] emails = new PluralAttribute[] { email };
            user.emails = emails;

            // send the request to create the user
            HttpWebResponse response = client.createUser(user);

            // verify the response code indicates success
            //int status =  response.getStatusCode();
            //assert(status == 201);

            // retrieve the location of the user
            //String location = response.getHeaders().getFirst("Location");	    

            // build a nide reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // get the user object from the response
                user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("created user - " + user.externalId + " as " + user.id);
                return user.id;
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be created, error returned - " + error.code + " " + error.description);
                return null;
            }

            /*
            // get the response stream to read the user
            Stream stream = response.GetResponseStream();

            // create a user deserializer
            XmlSerializer deserializer = new XmlSerializer(typeof(User));

            // retrieve the returned user entry
            user = (User)deserializer.Deserialize(stream);

            // retrieve the id of the user
            String id = user.id;

            Console.WriteLine("created user - " + user.externalId + " as " + user.id);

            return id;
            */
        }
Ejemplo n.º 2
0
        public static void updateUserTest(Client client, String uid)
        {
            // send the request to retrieve the user
            HttpWebResponse response = client.retrieveUser(uid);

            // build a node reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // verify the response code indicates success
                //int status =  response.getStatusCode();
                //assert(status == 200);

                /*
                // get the response stream to read the user
                Stream stream = response.GetResponseStream();

                // create a user deserializer
                XmlSerializer deserializer = new XmlSerializer(typeof(User));

                // retrieve the returned user entry
                User user = (User)deserializer.Deserialize(stream);
                */

                // get the user object from the response
                User user = client.getUserFromResponse(xmlNodeReader);

                // update the users name
                user.name.givenName = "Matthew";
                user.name.familyName = "Crooke";
                user.nickName = "Matt";
                user.name.formatted = "Mr Matthew Crooke";

                // update the users groups            
                PluralAttribute group = new PluralAttribute();
                group.value = "gid=nerds,ou=groups,dc=hackerypokery,dc=com";
                PluralAttribute[] memberOfs = new PluralAttribute[] { group };
                user.memberOf = memberOfs;

                // send the request to update the user
                response = client.updateUser(user);

                // verify the response code indicates success
                //status =  response.getStatusCode();
                //assert(status == 200);

                /*
                // get the response stream to update user
                stream = response.GetResponseStream();

                // retrieve the returned user entry
                user = (User)deserializer.Deserialize(stream);
                */

                // build a node reader from the response
                xmlNodeReader = client.buildReaderFromResponse(response);

                // get the user object from the response
                user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("updated user - " + user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be updated, error returned - " + error.code + " " + error.description);
            }           
        }
Ejemplo n.º 3
0
        public static void deleteUserTest(Client client, String uid)
        {
            // send the request to delete the user
            HttpWebResponse response = client.deleteUser(uid);

            try
            {
                // verify the response code indicates success
                if(HttpStatusCode.OK.Equals(response.StatusCode))
                {
                    Console.WriteLine("deleted user - " + uid);
                }
                else
                {
                    Console.WriteLine("user was not deleted - " + uid);
                }
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // build a node reader from the response
                XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be deleted, error returned - " + error.code + " " + error.description);
            }
        }
Ejemplo n.º 4
0
        public static void retrieveUserTest(Client client, String uid)
        {
            // send the request to retrieve the user
            HttpWebResponse response = client.retrieveUser(uid);

            // build a node reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // get the user object from the response
                User user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("retrieved user - " + user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be retrieved, error returned - " + error.code + " " + error.description);
            }
        }