本文整理汇总了C#中ApiConnection.Post方法的典型用法代码示例。如果您正苦于以下问题:C# ApiConnection.Post方法的具体用法?C# ApiConnection.Post怎么用?C# ApiConnection.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiConnection
的用法示例。
在下文中一共展示了ApiConnection.Post方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override async Task Execute(string[] parameters, IResponse response)
{
if (parameters.Length < 5)
{
await response.Send($"I don't understand '{string.Join(" ", parameters.Select(x => "[" + x + "]"))}'.");
return;
}
var repo = parameters[1];
var issueNumberString = parameters[2];
var from = parameters[3];
var to = parameters[4];
string accessToken;
if (!TryGetCredential("github-accesstoken", out accessToken))
{
await response.Send("I couldnt find a github access token in your credentials. If you add one I will be able to create the pull request on your behalf. Does it sound good? Here are the instructions https://github.com/Particular/Housekeeping/wiki/Generate-GitHub-access-token-for-PBot");
return;
}
var client = GitHubClientBuilder.Build(accessToken);
var apiConnection = new ApiConnection(client.Connection);
int issueNumber;
if (!int.TryParse(issueNumberString, out issueNumber))
{
await response.Send("Issue number should be a valid number dude!");
return;
}
try
{
var result = await apiConnection.Post<PullRequest>(ApiUrls.PullRequests("Particular", repo), new ConvertedPullRequest
{
Issue = issueNumber.ToString(),
Head = from,
Base = to
}, null, "application/json");
await response.Send($"Issue {issueNumber} has been converted into a pull request {result.HtmlUrl}.");
}
catch (NotFoundException)
{
response.Send("Sorry, GitHub could not find the issue or repository you are talking about.").ConfigureAwait(false).GetAwaiter().GetResult();
}
catch (ApiValidationException ex)
{
const string errorMessage = "Sorry, your request was rejected by GitHub as invalid.";
response.Send(string.Join(Environment.NewLine, errorMessage, ex.GetExtendedErrorMessage())).ConfigureAwait(false).GetAwaiter().GetResult();
}
}
示例2: EnsuresArgumentsNotNull
public async Task EnsuresArgumentsNotNull()
{
var postUri = new Uri("", UriKind.Relative);
var connection = new ApiConnection(Substitute.For<IConnection>());
// 1 parameter overload
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post(null));
// 2 parameter overload
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(null, new object()));
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(postUri, null));
// 3 parameters
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(null, new MemoryStream(), "anAccept", "some-content-type"));
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(postUri, null, "anAccept", "some-content-type"));
}
示例3: MakesUploadRequest
public async Task MakesUploadRequest()
{
var uploadUrl = new Uri("anything", UriKind.Relative);
IApiResponse<string> response = new ApiResponse<string>(new Response(), "the response");
var connection = Substitute.For<IConnection>();
connection.Post<string>(Args.Uri, Arg.Any<Stream>(), Args.String, Args.String)
.Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
var rawData = new MemoryStream();
await apiConnection.Post<string>(uploadUrl, rawData, "accepts", "content-type");
connection.Received().Post<string>(uploadUrl, rawData, "accepts", "content-type");
}
示例4: MakesPostRequestWithSuppliedData
public async Task MakesPostRequestWithSuppliedData()
{
var postUri = new Uri("anything", UriKind.Relative);
var sentData = new object();
IApiResponse<object> response = new ApiResponse<object>(new Response(), new object());
var connection = Substitute.For<IConnection>();
connection.Post<object>(Args.Uri, Args.Object, null, null).Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
var data = await apiConnection.Post<object>(postUri, sentData);
Assert.Same(data, response.Body);
connection.Received().Post<object>(postUri, sentData, null, null);
}
示例5: MakesPostRequestWithoutData
public async Task MakesPostRequestWithoutData()
{
var postUri = new Uri("anything", UriKind.Relative);
var statusCode = HttpStatusCode.Accepted;
var connection = Substitute.For<IConnection>();
connection.Post(Args.Uri).Returns(Task.FromResult(statusCode));
var apiConnection = new ApiConnection(connection);
await apiConnection.Post(postUri);
connection.Received().Post(postUri);
}