public void GithubRequestWithInput() { var gistFiles = new Dictionary <string, GithubSharp.Core.Models.GistFileForCreation> { { "fileName.txt", new Core.Models.GistFileForCreation { content = "bla bla" } } }; var gistToCreate = new Core.Models.GistToCreateOrEdit { @public = true, description = "testGist", files = gistFiles }; var baseGithubRequest = new Core.GithubRequestWithInputAndReturnType <GithubSharp.Core.Models.GistToCreateOrEdit, GithubSharp.Core.Models.Gist>( new Plugins.LogProviders.NullLogger.NullLogger(true), new Plugins.CacheProviders.NullCacher.NullCacher(), new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider (TestSettings.Username, TestSettings.Password), "gists", GithubSharpHttpVerbs.Post, gistToCreate ); GithubSharp.Core.IGithubResponseWithReturnType <GithubSharp.Core.Models.Gist> response = null; try { response = baseGithubRequest.GetResponseWithReturnType(); } catch (Exception err) { if (err is GithubSharp.Core.GithubException) { var githuberr = err as GithubSharp.Core.GithubException; Assert.Fail("StatusCode : {0}, StatusText : {1}, Message : {2}", githuberr.StatusCode, githuberr.StatusText, githuberr.GithubErrorResult.message); return; } Assert.Fail(err.Message); return; } Assert.IsNotNull(response.Result); Assert.AreEqual(response.Result.description, gistToCreate.description); Assert.AreEqual(response.Result.files["fileName.txt"].content, gistToCreate.files["fileName.txt"].content); //Let's clean up var gistDeleteRequest = new Core.GithubRequest( new Plugins.LogProviders.NullLogger.NullLogger(true), new Plugins.CacheProviders.NullCacher.NullCacher(), new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider (TestSettings.Username, TestSettings.Password), string.Format("gists/{0}", response.Result.id), GithubSharpHttpVerbs.Delete ); var deleteResult = gistDeleteRequest.GetResponse(); Assert.IsNotNull(deleteResult); Assert.AreEqual(deleteResult.StatusCode, 204); }
public void GithubRequestWithInput() { var gistFiles = new Dictionary<string, GithubSharp.Core.Models.GistFileForCreation> { { "fileName.txt", new Core.Models.GistFileForCreation { content = "bla bla" } } }; var gistToCreate = new Core.Models.GistToCreateOrEdit { @public = true, description = "testGist", files = gistFiles }; var baseGithubRequest = new Core.GithubRequestWithInputAndReturnType <GithubSharp.Core.Models.GistToCreateOrEdit, GithubSharp.Core.Models.Gist>( new Plugins.LogProviders.NullLogger.NullLogger(true), new Plugins.CacheProviders.NullCacher.NullCacher(), new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider (TestSettings.Username, TestSettings.Password), "gists", GithubSharpHttpVerbs.Post, gistToCreate ); GithubSharp.Core.IGithubResponseWithReturnType<GithubSharp.Core.Models.Gist> response = null; try { response = baseGithubRequest.GetResponseWithReturnType(); } catch (Exception err) { if (err is GithubSharp.Core.GithubException) { var githuberr = err as GithubSharp.Core.GithubException; Assert.Fail("StatusCode : {0}, StatusText : {1}, Message : {2}", githuberr.StatusCode, githuberr.StatusText, githuberr.GithubErrorResult.message); return; } Assert.Fail(err.Message); return; } Assert.IsNotNull(response.Result); Assert.AreEqual(response.Result.description, gistToCreate.description); Assert.AreEqual(response.Result.files["fileName.txt"].content, gistToCreate.files["fileName.txt"].content); //Let's clean up var gistDeleteRequest = new Core.GithubRequest( new Plugins.LogProviders.NullLogger.NullLogger(true), new Plugins.CacheProviders.NullCacher.NullCacher(), new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider (TestSettings.Username, TestSettings.Password), string.Format("gists/{0}", response.Result.id), GithubSharpHttpVerbs.Delete ); var deleteResult = gistDeleteRequest.GetResponse(); Assert.IsNotNull(deleteResult); Assert.AreEqual(deleteResult.StatusCode, 204); }