private void SetUp(object sender, PreWebTestEventArgs e)
 {
     try
     {
         MTApiFunctionalities mtApi = new MTApiFunctionalities();
         JObject userInfo           = mtApi.GenerateUserInfo();
         username = userInfo["username"].ToString();
         password = userInfo["password"].ToString();
         email    = userInfo["email"].ToString();
         HttpWebResponse httpResCreate = mtApi.CreateUser(mtUrl, username, password, email);
         httpResCreate.Close();
         HttpWebResponse httpResLogin      = mtApi.LoginUser(mtUrl, username, password);
         JObject         jsonResponseLogin = mtApi.JsonParseHttpRes(httpResLogin);
         userId = jsonResponseLogin["id"].ToString();
         httpResLogin.Close();
         HttpWebResponse httpResAdminLogin      = mtApi.LoginUser(mtUrl, adminUsername, adminPassword);
         JObject         jsonResponseAdminLogin = mtApi.JsonParseHttpRes(httpResAdminLogin);
         adminLoginToken = jsonResponseAdminLogin["token"].ToString();
         httpResAdminLogin.Close();
     }
     catch (WebException webExc)
     {
         Stop();                           // Stop test on exception
         Outcome           = Outcome.Fail; // Fail web test due to exception
         this.PostWebTest += TearDown;     // Add TearDown to make sure if user exists, it gets deleted
     }
 }
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            MTApiFunctionalities mtApi             = new MTApiFunctionalities();
            WebTestRequest       requestDeleteUser = new WebTestRequest(mtUrl + mtApi.accountApiRoute + "/" + userId);

            requestDeleteUser.Method = "DELETE";
            requestDeleteUser.Headers.Add(new WebTestRequestHeader("Authorization", ("Bearer " + adminLoginToken)));
            yield return(requestDeleteUser);

            requestDeleteUser = null;
        }
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            MTApiFunctionalities mtApi        = new MTApiFunctionalities();
            WebTestRequest       requestLogin = new WebTestRequest(mtUrl + mtApi.loginApiRoute);

            requestLogin.Method = "POST";
            StringHttpBody requestLoginBody = new StringHttpBody();

            requestLoginBody.ContentType         = "application/json";
            requestLoginBody.InsertByteOrderMark = false;
            requestLoginBody.BodyString          = "{ \"userName\" : \"" + username + "\" , \"password\" : \"" + password + "\"}";
            requestLogin.Body = requestLoginBody;
            yield return(requestLogin);

            requestLogin = null;
        }
예제 #4
0
 public void SetUp(object sender, PreWebTestEventArgs e)
 {
     try
     {
         MTApiFunctionalities mtApi = new MTApiFunctionalities();
         JObject userInfo           = mtApi.GenerateUserInfo();
         username = userInfo["username"].ToString();
         password = userInfo["password"].ToString();
         email    = userInfo["email"].ToString();
     }
     catch (WebException webExc)
     {
         Stop();                 // Stop test on exception
         Outcome = Outcome.Fail; // Fail web test due to exception
     }
 }
예제 #5
0
        private void TearDown(object sender, PostWebTestEventArgs e)
        {
            MTApiFunctionalities mtApi        = new MTApiFunctionalities();
            HttpWebResponse      httpResLogin = mtApi.LoginUser(mtUrl, username, password);
            JObject jsonResponse = mtApi.JsonParseHttpRes(httpResLogin);
            string  userId       = jsonResponse["id"].ToString();

            httpResLogin.Close();
            HttpWebResponse httpResAdminLogin      = mtApi.LoginUser(mtUrl, adminUsername, adminPassword); // Login as admin to get admin token to delete user
            JObject         jsonResponseAdminLogin = mtApi.JsonParseHttpRes(httpResAdminLogin);
            string          adminLoginToken        = jsonResponseAdminLogin["token"].ToString();

            httpResAdminLogin.Close();
            HttpWebResponse httpResDel = mtApi.DeleteUser(mtUrl, userId, adminLoginToken);

            httpResDel.Close();
        }
        public override IEnumerator <WebTestRequest> GetRequestEnumerator()
        {
            MTApiFunctionalities mtApi = new MTApiFunctionalities();
            WebTestRequest       requestChangePassword = new WebTestRequest(mtUrl + mtApi.accountApiRoute);

            requestChangePassword.Method = "PUT";
            requestChangePassword.Headers.Add(new WebTestRequestHeader("Authorization", ("Bearer " + userLoginToken)));
            StringHttpBody requestChangePasswordBody = new StringHttpBody();

            requestChangePasswordBody.ContentType         = "application/json";
            requestChangePasswordBody.InsertByteOrderMark = false;
            newPassword = mtApi.GenerateNewPassword();
            requestChangePasswordBody.BodyString = "{ \"password\" : \"" + password + "\" , \"newPassword\" : \"" + newPassword + "\" }";
            requestChangePassword.Body           = requestChangePasswordBody;
            yield return(requestChangePassword);

            requestChangePassword = null;
        }
        private void TearDown(object sender, PostWebTestEventArgs e)
        {
            MTApiFunctionalities mtApi = new MTApiFunctionalities();

            if (string.IsNullOrEmpty(userId)) // When SetUp fails and didn't save userId
            {
                HttpWebResponse httpResLogin = mtApi.LoginUser(mtUrl, username, password);
                JObject         jsonResponse = mtApi.JsonParseHttpRes(httpResLogin);
                userId = jsonResponse["id"].ToString();
                httpResLogin.Close();
            }
            HttpWebResponse httpResAdminLogin      = mtApi.LoginUser(mtUrl, adminUsername, adminPassword); // Login as admin to get admin token to delete user
            JObject         jsonResponseAdminLogin = mtApi.JsonParseHttpRes(httpResAdminLogin);

            adminLoginToken = jsonResponseAdminLogin["token"].ToString();
            httpResAdminLogin.Close();
            HttpWebResponse httpResDel = mtApi.DeleteUser(mtUrl, userId, adminLoginToken);

            httpResDel.Close();
        }
 private void SetUp(object sender, PreWebTestEventArgs e)
 {
     try
     {
         MTApiFunctionalities mtApi = new MTApiFunctionalities();
         JObject userInfo           = mtApi.GenerateUserInfo();
         username = userInfo["username"].ToString();
         password = userInfo["password"].ToString();
         email    = userInfo["email"].ToString();
         HttpWebResponse httpResCreate = mtApi.CreateUser(mtUrl, username, password, email);
         JObject         jsonResponse  = mtApi.JsonParseHttpRes(httpResCreate);
         userId = jsonResponse["id"].ToString();
         httpResCreate.Close();
     }
     catch (WebException webExc)
     {
         Stop();                 // Stop test on exception
         Outcome = Outcome.Fail; // Fail web test due to exception
     }
 }