예제 #1
0
        public void CreateAccount()
        {
            AnnotateResult result    = new AnnotateResult();
            string         webResult = "";
            long           epoch     = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            WebClient      client    = new WebClient();

            string apiKey = annotateApi.GenerateAnnotateKey("createAccount.php", username, epoch);

            string createString = AnnotateURL + "/annotate/php/createAccount.php?" +
                                  "api-user={0}" +          //Annotate admin user name (see web config)
                                  "&api-requesttime={1}" +  //UNIX timestamp
                                  "&api-annotateuser={2}" + //the current user (reviewer)
                                  "&api-auth={3}" +         //Annotate admin auth key
                                  "&licensed=0 " +
                                  "&firstname={4}" +        //User's first name
                                  "&lastname={5}";          //User's last name

            createString = string.Format(createString,
                                         ApiUser,
                                         epoch,
                                         username,
                                         apiKey,
                                         first,
                                         last
                                         );
            webResult = client.DownloadString(createString);

            //downgrade user to unlicensed if not OSBLE admin
            if (OsbleUserAdmin == false)
            {
                apiKey = annotateApi.GenerateAnnotateKey("updateAccount.php", username, epoch);

                string updateString = AnnotateURL + "/annotate/php/updateAccount.php?" +
                                      "api-user={0}" +          //Annotate admin user name (see web config)
                                      "&api-requesttime={1}" +  //UNIX timestamp
                                      "&api-annotateuser={2}" + //the current user (reviewer)
                                      "&api-auth={3}" +         //Annotate admin auth key
                                      "&licensed=0 ";
                updateString = string.Format(updateString,
                                             ApiUser,
                                             epoch,
                                             username,
                                             apiKey
                                             );
                try
                {
                    webResult         = client.DownloadString(updateString);
                    result.RawMessage = webResult;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            result.RawMessage = webResult;

            Assert.AreEqual(webResult.Substring(0, 2), "OK");
        }