Merge pull request #483 from octokit/shiftkey/testing-releases-betterer

tests around uploading assets
This commit is contained in:
Brendan Forster
2014-05-17 11:48:20 +10:00
4 changed files with 71 additions and 0 deletions
@@ -56,4 +56,57 @@ public class ReleasesClientTests
Helper.DeleteRepo(_repository);
}
}
public class TheUploadAssetMethod : IDisposable
{
readonly IReleasesClient _releaseClient;
readonly Repository _repository;
readonly string _repositoryOwner;
readonly string _repositoryName;
readonly GitHubClient _github;
public TheUploadAssetMethod()
{
_github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_releaseClient = _github.Release;
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_repositoryOwner = _repository.Owner.Login;
_repositoryName = _repository.Name;
}
[IntegrationTest]
public async Task CanUploadAndRetrieveAnAsset()
{
var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
var release = await _releaseClient.CreateRelease(_repositoryOwner, _repositoryName, releaseWithNoUpdate);
var stream = Helper.LoadFixture("hello-world.txt");
var newAsset = new ReleaseAssetUpload
{
ContentType = "text/plain", FileName = "hello-world.txt", RawData = stream
};
var result = await _releaseClient.UploadAsset(release, newAsset);
Assert.True(result.Id > 0);
var assets = await _releaseClient.GetAssets(_repositoryOwner, _repositoryName, release.Id);
Assert.Equal(1, assets.Count);
var asset = assets[0];
Assert.Equal(result.Id, asset.Id);
Assert.NotNull(asset.Url);
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}
}
+14
View File
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http.Headers;
using System.Reflection;
namespace Octokit.Tests.Integration
{
@@ -57,5 +59,17 @@ namespace Octokit.Tests.Integration
{
return string.Concat(name, "-", DateTime.UtcNow.ToString("yyyyMMddhhmmssfff"));
}
public static Stream LoadFixture(string fileName)
{
var key = "Octokit.Tests.Integration.fixtures." + fileName;
var stream = typeof(Helper).Assembly.GetManifestResourceStream(key);
if (stream == null)
{
throw new InvalidOperationException(
"The file '" + fileName + "' was not found as an embedded resource in the assembly. Failing the test...");
}
return stream;
}
}
}
@@ -116,6 +116,9 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="fixtures\hello-world.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -0,0 +1 @@
This is a plain text file.