Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verify all attachments #54

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions integration-test-sdk-net60/AttachmentResourcesTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RestSharp;
using RestSharp;
using Smartsheet.Api;
using Smartsheet.Api.Models;

Expand Down Expand Up @@ -89,6 +89,7 @@ private long AttachFileAndUrlToSheet(SmartsheetClient smartsheet, long sheetId)
Assert.IsTrue(attachment.AttachmentType == AttachmentType.FILE);
Assert.IsTrue(attachment.Name == "TestFile.txt");

VerifyAttachmentContent(smartsheet, sheetId, attachment);

return attachment.Id.Value;
}
Expand All @@ -103,6 +104,8 @@ private long AttachFileAndUrlToRow(SmartsheetClient smartsheet, long sheetId)
Assert.IsTrue(attachment.AttachmentType == AttachmentType.FILE);
Assert.IsTrue(attachment.Name == "TestFile.txt");

VerifyAttachmentContent(smartsheet, sheetId, attachment);

Attachment attachToResource = new Attachment.CreateAttachmentBuilder("http://www.bing.com", AttachmentType.LINK).Build();
attachment = smartsheet.SheetResources.RowResources.AttachmentResources.AttachUrl(sheetId, rowId, attachToResource);
Assert.IsTrue(attachment.Url == "http://www.bing.com");
Expand All @@ -119,15 +122,7 @@ private long AttachFileAndUrlToComment(SmartsheetClient smartsheet, long sheetId
Assert.IsTrue(attachment.AttachmentType == AttachmentType.FILE);
Assert.IsTrue(attachment.Name == "TestFile.txt");

attachment = smartsheet.SheetResources.AttachmentResources.GetAttachment(sheetId, attachment.Id.Value);

var request = new RestRequest(attachment.Url);

var attachmentContent = new RestClient(attachment.Url).Get(request).Content;

var fileContents = File.ReadAllText(path);

Assert.AreEqual(attachmentContent, fileContents);
VerifyAttachmentContent(smartsheet, sheetId, attachment);

Attachment attachToResource = new Attachment.CreateAttachmentBuilder("http://www.google.com", AttachmentType.LINK).Build();
attachment = smartsheet.SheetResources.CommentResources.AttachmentResources.AttachUrl(sheetId, commentId, attachToResource);
Expand All @@ -148,5 +143,18 @@ private static long CreateSheet(SmartsheetClient smartsheet)
Assert.IsTrue(createdSheet.Columns[1].Title == "col 2");
return createdSheet.Id.Value;
}

private void VerifyAttachmentContent(SmartsheetClient smartsheet, long sheetId, Attachment attachment)
{
attachment = smartsheet.SheetResources.AttachmentResources.GetAttachment(sheetId, attachment.Id.Value);

var request = new RestRequest(attachment.Url);

var attachmentContent = new RestClient(attachment.Url).Get(request).Content;

var fileContents = File.ReadAllText(path);

Assert.AreEqual(fileContents, attachmentContent);
}
}
}
Loading