Skip to content

Commit

Permalink
Added some more gist tests , start is acting strange
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Nov 21, 2011
1 parent 3d5e553 commit fa33e2b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Core/API/Gist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public Gist(
cacheProvider,
authProvider) { }

public IEnumerable<Models.Gist> UserGists(string username)
public IEnumerable<Models.Gist> List(string username)
{
return base.Get<IEnumerable<Models.Gist>>(
string.Format(
"users/{0}/gists",
username),
"GET").Result;
}
public IEnumerable<Models.Gist> CurrentUserGists()
public IEnumerable<Models.Gist> List()
{
return base.Get<IEnumerable<Models.Gist>>(
string.Format(
Expand All @@ -31,14 +31,14 @@ public Gist(
"GET").Result;
}

public IEnumerable<Models.Gist> PublicGists()
public IEnumerable<Models.Gist> Public()
{
return base.Get<IEnumerable<Models.Gist>>(
"gists/public",
"GET").Result;
}

public IEnumerable<Models.Gist> StarredGists()
public IEnumerable<Models.Gist> Starred()
{
return base.Get<IEnumerable<Models.Gist>>(
"gists/starred",
Expand Down Expand Up @@ -72,7 +72,7 @@ public Models.Gist Edit(string id, Models.GistToCreateOrEdit gist)
gist).Result;
}

public void StarGist(string id)
public void Star(string id)
{
base.Get(
string.Format(
Expand All @@ -81,7 +81,7 @@ public void StarGist(string id)
"PUT");
}

public void UnstarGist(string id)
public void Unstar(string id)
{
base.Get(
string.Format(
Expand All @@ -90,7 +90,7 @@ public void UnstarGist(string id)
"DELETE");
}

public bool IsGistStarred(string id)
public bool HasStar(string id)
{
return base.Get(
string.Format(
Expand Down
4 changes: 3 additions & 1 deletion NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ Add pagination defaults to base api class
Continue to implement models to understand the needs of the base api class
Add attribute for an api method that needs authentication?
Add a simple parameterized string format for methods?
Add raw url helper methods - with content types?
Add raw url helper methods - with content types?

Check if 404 causes an exception..
57 changes: 57 additions & 0 deletions Tests/CoreTests/GistModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,63 @@ public void TestCreateEditAndDelete()

gistModel.Delete(editedGist.id);
}

[Test]
public void PublicGistsTest()
{
var gistModel = new GithubSharp.Core.API.Gist(
new GithubSharp.Plugins.LogProviders.NullLogger.NullLogger(true),
new GithubSharp.Plugins.CacheProviders.NullCacher.NullCacher(),
new GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
(TestSettings.Username, TestSettings.Password));

var publicGists = gistModel.Public();

Assert.IsNotNull(publicGists);
Assert.IsTrue(new List<GithubSharp.Core.Models.Gist>(publicGists).Count > 0);
}

[Test]
public void GistStarTest()
{
var gistModel = new GithubSharp.Core.API.Gist(
new GithubSharp.Plugins.LogProviders.NullLogger.NullLogger(true),
new GithubSharp.Plugins.CacheProviders.NullCacher.NullCacher(),
new GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
(TestSettings.Username, TestSettings.Password));


var gistFiles = new Dictionary<string,GithubSharp.Core.Models.GistFileForCreation>();
gistFiles.Add(
"fileName.txt",
new GithubSharp.Core.Models.GistFileForCreation
{
content = System.Guid.NewGuid().ToString()
});


var toCreate = new GithubSharp.Core.Models.GistToCreateOrEdit
{
description = "test gist",
@public = false,
files = gistFiles
};

var createdGist = gistModel.Create(toCreate);

Assert.IsFalse(gistModel.HasStar(createdGist.id));

gistModel.Star(createdGist.id);

Assert.IsTrue(gistModel.HasStar(createdGist.id));

gistModel.Unstar(createdGist.id);

Assert.IsFalse(gistModel.HasStar(createdGist.id));

gistModel.Delete(createdGist.id);
}

}
}

0 comments on commit fa33e2b

Please sign in to comment.