/// <summary> /// Validates a created sheet against the input parameters to the CreateSheet method /// </summary> /// <param name="expected">Input parameters into the CreateSheet method</param> /// <param name="actual">Output from the CreateSheet method</param> public static void CreateSheetValidation(CreateSmartSheetRequestObject expected, SmartSheetResponseResult actual) { Assert.AreEqual(expected.Name, actual.Name, "Sheet name is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns.Count, actual.Columns.Count, "Sheet column count is different between input parameters and createSheet response."); // Making the assumption that the columns are created in the order they were listed. Assert.AreEqual(expected.Columns[0].Title, actual.Columns[0].Title, "Sheet column title is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns[0].Type, actual.Columns[0].Type, "Sheet column type is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns[0].Symbol, actual.Columns[0].Symbol, "Sheet column symbol is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns[1].Title, actual.Columns[1].Title, "Sheet column title is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns[1].Type, actual.Columns[1].Type, "Sheet column type is different between input parameters and createSheet response."); Assert.AreEqual(expected.Columns[1].Primary, actual.Columns[1].Primary, "Sheet column primary is different between input parameters and createSheet response."); }
public void CreateSheet_ValidateContents() { SmartSheetRestClient client = new SmartSheetRestClient(); // Set up SmartSheet request object CreateSmartSheetRequestObject sheet = new CreateSmartSheetRequestObject(); sheet.Name = "Kevin Test Sheet"; sheet.Columns.Add(new CreateSmartSheetRequestColumn { Title = "favorite", Type = ColumnTypes.CHECKBOX.ToString(), Symbol = "STAR" }); sheet.Columns.Add(new CreateSmartSheetRequestColumn { Title = "Primary Column", Type = ColumnTypes.TEXT_NUMBER.ToString(), Primary = true }); // Create the SmartSheet SmartSheetResponse <SmartSheetCreateResponse> createResponse = client.CreateSheet(sheet).Result; // Verify that the create request was successful Assert.AreEqual(HttpStatusCode.OK, createResponse.StatusCode, "Create sheet returned a non-200 response."); VerificationHelpers.CreateSheetValidation(sheet, createResponse.Content.Result); // Get Sheet from endpoint and compare data // I noticed that there are instances where the Read would return NotFound, but in my investigation of these instances, the sheet was created eventually. // Adding this retry as a quick fix. Normally I would investigate this further to see if there were better ways to handle this. SmartSheetResponse <SmartSheetResponseResult> readResponse = null; for (int i = 0; i < 3; i++) { readResponse = client.ReadSheet(createResponse.Content.Result.Id).Result; if (readResponse.StatusCode == HttpStatusCode.OK) { break; } Thread.Sleep(1000); } // Verify that the read request was successful Assert.AreEqual(HttpStatusCode.OK, readResponse.StatusCode, $"Read response for sheet {createResponse.Content.Result.Id.ToString()} returned a non-200 response."); VerificationHelpers.CompareCreatedVsRead(createResponse.Content.Result, readResponse.Content); }
/// <summary> /// Creates a sheet by calling the CreateSheet endpoint with the requested sheet data /// </summary> /// <param name="sheetToCreate">Representation of the sheet the user wants to create.</param> /// <returns>Response object containing StatusCode, Content (on OK status code) and Error Message (on non-OK status codes)</returns> public async Task <SmartSheetResponse <SmartSheetCreateResponse> > CreateSheet(CreateSmartSheetRequestObject sheetToCreate) { HttpContent content = new StringContent(JsonConvert.SerializeObject(sheetToCreate), Encoding.UTF8, "application/json"); var response = await HttpClient.PostAsync("sheets", content); string responseContent = await response.Content.ReadAsStringAsync(); SmartSheetResponse <SmartSheetCreateResponse> sheetResponse = new SmartSheetResponse <SmartSheetCreateResponse> { StatusCode = response.StatusCode, Content = response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <SmartSheetCreateResponse>(responseContent) : null, Error = response.StatusCode != HttpStatusCode.OK ? responseContent : null }; return(sheetResponse); }