/// <summary> /// Post the provided API Test to the QViz Instance /// </summary> /// <param name="apitest">API Test as JSON Object</param> public void PostAPITest(TestCaseAPI apitest) { var apiClient = new APIClient(_baseURL); apiClient.Headers.Add(new KeyValue("Content-Type", "application/json")); apiClient.Headers.Add(new KeyValue("Authorization", "Bearer " + _user.access_token)); apiClient.Headers.Add(new KeyValue("userId", _user.userId)); apiClient.Body = apitest; apiClient.Post <object>("/api/APITestcases"); _lastResponse = apiClient.Response.Content; if (!apiClient.Response.IsSuccessful) { throw apiClient.GetError(); } }
public void PostAPITestcase() { try { _qvizClient.Authenticate(QVizUser, QVizPassword); var project = _qvizClient.GetProject(QVizProject); var testTags = new List <Tag> { new Tag { tagId = null, tagName = "TestTag1" }, new Tag { tagId = null, tagName = "TestTag2" } }; /// Test PAI List <TestAPI> listTestAPI = new List <TestAPI>(); #region API header APIHeaderValue apiHeaderValue = new APIHeaderValue { headerValueId = null, key = "ContentType", value = "application/json" }; APIHeader header = new APIHeader { headerValueId = null, headerValue = apiHeaderValue, apiId = null, apiHeaderId = null, srNo = 1, }; List <APIHeader> headers = new List <APIHeader> { header }; #endregion #region API Query APIQueryValue apiQueryValue = new APIQueryValue { queryValueId = null, key = "projectId", value = "12334", }; APIQuery query = new APIQuery { queryValueId = null, queryValue = apiQueryValue, apiId = null, apiQueryId = null, srNo = 1, }; List <APIQuery> queries = new List <APIQuery> { query }; APIBodyValue apiBodyValue = new APIBodyValue { bodyValueId = null, jsonString = "{ id=\"100\", name=\"Cars\"}", }; APIBody body = new APIBody { srNo = 1, apiBodyId = null, bodyValueId = null, apiId = null, bodyValue = apiBodyValue, }; #endregion API api = new API { apiId = null, uri = "/Products", method = "GET", expectedHTTPStatus = 200, expectedJSONResult = "[{ id=\"100\", name=\"Cars\"}]", apiHeaders = headers, apiQueries = queries, apiBody = body, moduleId = null, subModuleId = null, apiTags = null, testAPIs = null, }; var testAPI = new TestAPI { srNo = 1, testAPIId = null, testCaseId = null, apiId = null, api = api, }; List <TestAPI> apis = new List <TestAPI> { testAPI }; // Test case TestCaseAPI apiTC = new TestCaseAPI { testCaseId = null, projectId = project.projectId, moduleId = modules.FirstOrDefault().moduleId, subModuleId = subModules.FirstOrDefault().subModuleId, description = "Demo API Test case " + DateTime.Now.Ticks, isAutomated = false, priority = "P1", severity = "1", expectedResult = "Demo API TC expected result", testCaseTypeId = testcaseTypes.FirstOrDefault(f => f.name.ToLower() == "api").testCaseTypeId, testToolID = "DemoTool1", testTags = testTags, testAPIs = apis, module = null, subModule = null, }; _qvizClient.PostAPITest(apiTC); string response = _qvizClient.LastResponse(); QVizResponseObject <TestCaseAPI> qVizResponse = JsonConvert.DeserializeObject <QVizResponseObject <TestCaseAPI> >(response); Assert.AreEqual("Test case created successfully", qVizResponse.Message); } catch (Exception error) { Assert.Fail(error.Message); } }