Skip to content
Browse files

base api should be good to go, added some more tests and a basic auth…

…provider
  • Loading branch information...
1 parent 7ccdb56 commit cae915532ee4b8367e1ea6a38bf598b3badc68ae @erikzaadi committed
Showing with 576 additions and 144 deletions.
  1. +3 −2 Core/Base/JsonConverter.cs
  2. +7 −2 Core/Core.csproj
  3. +52 −0 Core/GithubError.cs
  4. +13 −2 Core/GithubRequest.cs
  5. +14 −10 Core/{GithubRequestWithInput.cs → GithubRequestWithInputAndReturnType.cs}
  6. +4 −5 Core/GithubRequestWithReturnType.cs
  7. +4 −0 Core/GithubResponse.cs
  8. +20 −0 Core/Models/BasicUser.cs
  9. +16 −0 Core/Models/ChangeStatus.cs
  10. +59 −59 Core/Models/Commit.cs
  11. +17 −0 Core/Models/Fork.cs
  12. +47 −0 Core/Models/Gist.cs
  13. +19 −0 Core/Models/History.cs
  14. +9 −0 GithubSharp.sln
  15. +0 −1 Plugins/AuthProviders/NullAuthProvider/NullAuthProvider.csproj
  16. +27 −0 Plugins/AuthProviders/UserPasswordAuthProvider/AssemblyInfo.cs
  17. +12 −0 Plugins/AuthProviders/UserPasswordAuthProvider/MyClass.cs
  18. +76 −0 Plugins/AuthProviders/UserPasswordAuthProvider/UserPasswordAuthProvider.cs
  19. +45 −0 Plugins/AuthProviders/UserPasswordAuthProvider/UserPasswordAuthProvider.csproj
  20. +2 −4 Plugins/CacheProviders/ApplicationCacher/ApplicationCacher.csproj
  21. +0 −1 Plugins/CacheProviders/NullCacher/NullCacher.csproj
  22. +2 −4 Plugins/CacheProviders/WebCache/WebCache.csproj
  23. +0 −1 Plugins/LogProviders/NullLogger/NullLogger.csproj
  24. +3 −6 Plugins/LogProviders/SimpleLogProvider/SimpleLogProvider.csproj
  25. +16 −25 Samples/MvcSample/MvcApplication/MvcApplication.csproj
  26. +11 −18 Samples/MvcSample/MvcUI/MvcUI.csproj
  27. +6 −3 Tests/CoreTests/CoreTests.csproj
  28. +76 −1 Tests/CoreTests/GithubRequestTest.cs
  29. +16 −0 Tests/CoreTests/TestSettings.cs
View
5 Core/Base/JsonConverter.cs
@@ -23,9 +23,10 @@ internal static string ToJson<T> (this T Obj)
return ServiceStack.Text.JsonSerializer.SerializeToString<T>(Obj);
}
- internal static void ToJsonStream<T>(this T Obj, Stream toWrite)
+ internal static byte[] ToJsonBytes<T>(this T TObj)
{
- ServiceStack.Text.JsonSerializer.SerializeToStream(Obj, toWrite);
+ var jsonString = ToJson<T>(TObj);
+ return System.Text.Encoding.UTF8.GetBytes(jsonString);
}
/// <summary>
View
9 Core/Core.csproj
@@ -101,13 +101,18 @@
<Compile Include="Services\ILogProvider.cs" />
<Compile Include="GithubRequest.cs" />
<Compile Include="GithubResponse.cs" />
- <Compile Include="GithubErrorResponse.cs" />
<Compile Include="Services\IAuthProvider.cs" />
<Compile Include="GithubAuthenticationException.cs" />
<Compile Include="GithubFailedResponse.cs" />
<Compile Include="GithubRequestWithBinaryFileToSend.cs" />
<Compile Include="GithubRequestWithReturnType.cs" />
- <Compile Include="GithubRequestWithInput.cs" />
+ <Compile Include="Models\Gist.cs" />
+ <Compile Include="Models\Fork.cs" />
+ <Compile Include="Models\BasicUser.cs" />
+ <Compile Include="Models\History.cs" />
+ <Compile Include="Models\ChangeStatus.cs" />
+ <Compile Include="GithubRequestWithInputAndReturnType.cs" />
+ <Compile Include="GithubError.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
View
52 Core/GithubError.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+
+namespace GithubSharp.Core
+{
+ public class GithubError : Exception
+ {
+ public GithubError(System.Net.HttpWebResponse response, string uri)
+ :base(string.Format("Github error when retrieving {0}", uri))
+ {
+ var responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
+ GithubErrorResult = GithubSharp.Core.Base.JsonConverter.FromJson<GithubErrorModel>(responseString);
+ StatusCode = (int)response.StatusCode;
+ StatusText = response.StatusDescription;
+ }
+
+ public GithubErrorModel GithubErrorResult { get;set;}
+ public int StatusCode { get;set;}
+ public string StatusText { get;set;}
+ }
+
+ public class GithubErrorModel
+ {
+ public string message {
+ get;
+ set;
+ }
+ public IEnumerable<GithubErrorDetails> errors {
+ get;
+ set;
+ }
+ }
+
+ public class GithubErrorDetails
+ {
+ public string Resource {
+ get;
+ set;
+ }
+
+ public string Field {
+ get;
+ set;
+ }
+
+ public string Code {
+ get;
+ set;
+ }
+ }
+}
+
View
15 Core/GithubRequest.cs
@@ -13,6 +13,7 @@ public interface IGithubRequest
Core.Services.ICacheProvider CacheProvider {get;set;}
int? PagingRequestAmount {get;set;}
int? PagingCurrentPage {get;set;}
+ System.Net.HttpWebRequest PrepareWebRequest(System.Net.HttpWebRequest webRequest);
}
@@ -159,15 +160,18 @@ public virtual IGithubResponse GetResponse ()
webRequest = PrepareWebRequest(authResult.WebRequest);
+
try
{
- var response = webRequest.GetResponse();
+ var response = webRequest.GetResponse() as System.Net.HttpWebResponse;
var responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
var responseToReturn = new GithubResponse
{
RateLimitLimit = int.Parse(response.Headers["X-RateLimit-Limit"]),
RateLimitRemaining = int.Parse(response.Headers["X-RateLimit-Remaining"]),
- Response = responseString
+ Response = responseString,
+ StatusCode = (int)response.StatusCode,
+ StatusText = response.StatusDescription
};
if (!string.IsNullOrEmpty(response.Headers.Get("Link")))
{
@@ -181,6 +185,13 @@ public virtual IGithubResponse GetResponse ()
}
catch (Exception error)
{
+ if (error is System.Net.WebException)
+ {
+ var webError = error as System.Net.WebException;
+ var githubException = new GithubError(webError.Response as System.Net.HttpWebResponse, uri);
+ if (LogProvider.HandleAndReturnIfToThrowError(githubException))
+ throw githubException;
+ }
if (LogProvider.HandleAndReturnIfToThrowError(error))
throw;
return new GithubFailedResponse(uri);
View
24 Core/GithubRequestWithInput.cs → Core/GithubRequestWithInputAndReturnType.cs
@@ -3,9 +3,10 @@
namespace GithubSharp.Core
{
- public class GithubRequestWithInput<TInputType> : GithubRequest
+ public class GithubRequestWithInputAndReturnType<TInputType,TReturnType> : GithubRequestWithReturnType<TReturnType>
+ where TReturnType : class
{
- public GithubRequestWithInput (
+ public GithubRequestWithInputAndReturnType (
ILogProvider logProvider,
ICacheProvider cacheProvider,
IAuthProvider authProvider,
@@ -18,8 +19,7 @@ public class GithubRequestWithInput<TInputType> : GithubRequest
{
ModelToSend = input;
}
-
- public GithubRequestWithInput (
+ public GithubRequestWithInputAndReturnType (
ILogProvider logProvider,
ICacheProvider cacheProvider,
IAuthProvider authProvider,
@@ -37,16 +37,20 @@ public class GithubRequestWithInput<TInputType> : GithubRequest
public TInputType ModelToSend { get;set;}
+
public override System.Net.HttpWebRequest PrepareWebRequest (System.Net.HttpWebRequest webRequest)
{
- var toReturn = base.PrepareWebRequest (webRequest);
-
-
- GithubSharp.Core.Base.JsonConverter.ToJsonStream<TInputType>
- (ModelToSend, toReturn.GetRequestStream());
+ webRequest.ContentType = "application/json"; //TODO Needed?
+ webRequest.MediaType = "UTF-8";
+ var bytes = GithubSharp.Core.Base.JsonConverter.ToJsonBytes<TInputType>
+ (ModelToSend);
+ webRequest.ContentLength = bytes.Length;
+ var stream = webRequest.GetRequestStream();
+ stream.Write(bytes, 0, bytes.Length);
+ stream.Close();
- return toReturn;
+ return webRequest;
}
}
}
View
9 Core/GithubRequestWithReturnType.cs
@@ -13,6 +13,7 @@ public class GithubRequestWithReturnType<TReturnType> : GithubRequest
: base(logProvider, cacheProvider, authProvider, path)
{
}
+
public GithubRequestWithReturnType (Core.Services.ILogProvider logProvider,
Core.Services.ICacheProvider cacheProvider,
Core.Services.IAuthProvider authProvider,
@@ -32,7 +33,6 @@ private new IGithubResponse GetResponse()
return null;
}
-
public IGithubResponseWithReturnType<TReturnType> GetResponseWithReturnType()
{
var baseResult = base.GetResponse();
@@ -49,10 +49,8 @@ public IGithubResponseWithReturnType<TReturnType> GetResponseWithReturnType()
try
{
- baseWithReturnType.Result = ServiceStack.Text.JsonSerializer
- .DeserializeFromString<TReturnType>(baseWithReturnType.Response);
-// baseWithReturnType.Result = JsonConverter
-// .FromJson<TReturnType>(baseWithReturnType.Response);
+ baseWithReturnType.Result = JsonConverter
+ .FromJson<TReturnType>(baseWithReturnType.Response);
}
catch (Exception error)
{
@@ -62,6 +60,7 @@ public IGithubResponseWithReturnType<TReturnType> GetResponseWithReturnType()
return baseWithReturnType;
}
+
}
}
View
4 Core/GithubResponse.cs
@@ -11,6 +11,8 @@ public interface IGithubResponse
string LinkPrevious { get; set; }
string LinkFirst { get; set; }
string LinkLast { get; set; }
+ int? StatusCode {get;set;}
+ string StatusText {get;set;}
}
public interface IGithubResponseWithReturnType<TResultType> : IGithubResponse
@@ -28,6 +30,8 @@ public class GithubResponse : IGithubResponse
public string LinkPrevious { get; set; }
public string LinkFirst { get; set; }
public string LinkLast { get; set; }
+ public int? StatusCode {get;set;}
+ public string StatusText {get;set;}
}
public class GithubResponseWithReturnType<TResultType> : GithubResponse, IGithubResponseWithReturnType<TResultType>
View
20 Core/Models/BasicUser.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace GithubSharp.Core.Models
+{
+ [Serializable]
+ public class BasicUser
+ {
+ public BasicUser ()
+ {
+ }
+
+ public string login { get; set; }
+ public int id { get; set; }
+ public string avatar_url { get; set; }
+ public string gravatar_id { get; set; }
+ public string url { get; set; }
+
+ }
+}
+
View
16 Core/Models/ChangeStatus.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace GithubSharp.Core.Models
+{
+ [Serializable]
+ public class ChangeStatus
+ {
+ public ChangeStatus ()
+ {
+ }
+ public int deletions { get; set; }
+ public int additions { get; set; }
+ public int total { get; set; }
+ }
+}
+
View
118 Core/Models/Commit.cs
@@ -1,59 +1,59 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-
-namespace GithubSharp.Core.Models
-{
- public class Commit
- {
- public List<CommmitParent> parents { get; set; }
-
- public Person author { get; set; }
-
- public string url { get; set; }
-
- public string sha { get; set; }
-
- public string message { get; set; }
-
- public CommmitParent tree { get; set; }
-
- public Person committer { get; set; }
- }
-
- public class CommmitParent
- {
- public string sha { get; set; }
-
- public string url { get; set; }
- }
-
- public class Person
- {
- public string name { get; set; }
-
- public DateTime date { get; set; }
-
- public string email { get; set; }
- }
-
- [DataContract]
- public class SingleFileCommit : Commit
- {
- [DataMember(Name = "added")]
- public IEnumerable<SingleFileCommitFileReference> Added { get; set; }
-
- [DataMember(Name = "removed")]
- public IEnumerable<SingleFileCommitFileReference> Removed { get; set; }
-
- [DataMember(Name = "modified")]
- public IEnumerable<SingleFileCommitFileReference> Modified { get; set; }
- }
-
- [DataContract]
- public class SingleFileCommitFileReference
- {
- [DataMember(Name = "filename")]
- public string Filename { get; set; }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Runtime.Serialization;
+
+namespace GithubSharp.Core.Models
+{
+ public class Commit
+ {
+ public List<CommmitParent> parents { get; set; }
+
+ public Person author { get; set; }
+
+ public string url { get; set; }
+
+ public string sha { get; set; }
+
+ public string message { get; set; }
+
+ public CommmitParent tree { get; set; }
+
+ public Person committer { get; set; }
+ }
+
+ public class CommmitParent
+ {
+ public string sha { get; set; }
+
+ public string url { get; set; }
+ }
+
+ public class Person
+ {
+ public string name { get; set; }
+
+ public DateTime date { get; set; }
+
+ public string email { get; set; }
+ }
+
+ [DataContract]
+ public class SingleFileCommit : Commit
+ {
+ [DataMember(Name = "added")]
+ public IEnumerable<SingleFileCommitFileReference> Added { get; set; }
+
+ [DataMember(Name = "removed")]
+ public IEnumerable<SingleFileCommitFileReference> Removed { get; set; }
+
+ [DataMember(Name = "modified")]
+ public IEnumerable<SingleFileCommitFileReference> Modified { get; set; }
+ }
+
+ [DataContract]
+ public class SingleFileCommitFileReference
+ {
+ [DataMember(Name = "filename")]
+ public string Filename { get; set; }
+ }
+}
View
17 Core/Models/Fork.cs
@@ -0,0 +1,17 @@
+using System;
+
+namespace GithubSharp.Core.Models
+{
+ [Serializable]
+ public class Fork
+ {
+ public Fork ()
+ {
+ }
+
+ public BasicUser user {get;set;}
+ public string url { get; set; }
+ public DateTime created_at { get; set; }
+ }
+}
+
View
47 Core/Models/Gist.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+
+namespace GithubSharp.Core.Models
+{
+ [Serializable]
+ public class Gist
+ {
+ public string url { get; set; }
+ public string id { get; set; }
+ public string description { get; set; }
+ public bool @public { get; set; }
+ public BasicUser user { get; set; }
+ public Dictionary<string, GistFile> files { get; set; }
+ public int comments { get; set; }
+ public string html_url { get; set; }
+ public string git_pull_url { get; set; }
+ public string git_push_url { get; set; }
+ public DateTime created_at { get; set; }
+ public List<Fork> forks { get; set; }
+ public List<History> history { get; set; }
+ }
+
+ [Serializable]
+ public class GistFile
+ {
+ public int size { get; set; }
+ public string filename { get; set; }
+ public string raw_url { get; set; }
+ public string content { get; set; }
+ }
+
+ [Serializable]
+ public class GistToCreate
+ {
+ public string description { get; set;}
+ public bool @public { get;set;}
+ public Dictionary <string, GistFileForCreation> files { get;set;}
+ }
+
+ [Serializable]
+ public class GistFileForCreation
+ {
+ public string content {get;set;}
+ }
+}
+
View
19 Core/Models/History.cs
@@ -0,0 +1,19 @@
+using System;
+
+namespace GithubSharp.Core.Models
+{
+ [Serializable]
+ public class History
+ {
+ public History ()
+ {
+ }
+ public string url { get; set; }
+ public string version { get; set; }
+ public BasicUser user { get; set; }
+ public ChangeStatus change_status { get; set; }
+ public DateTime committed_at { get; set; }
+
+ }
+}
+
View
9 GithubSharp.sln
@@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AuthProviders", "AuthProvid
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NullAuthProvider", "Plugins\AuthProviders\NullAuthProvider\NullAuthProvider.csproj", "{3C916941-003B-480E-9981-2B9FEFFBF447}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPasswordAuthProvider", "Plugins\AuthProviders\UserPasswordAuthProvider\UserPasswordAuthProvider.csproj", "{61EFFFA9-0713-47CA-95D9-193E16BBA3B9}"
+EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{524A0064-011B-46A9-BC3D-A6ECC6E81C44}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MvcSample", "MvcSample", "{214EE669-3ED2-4A03-A9B9-1F71B4257FA6}"
@@ -99,6 +101,12 @@ Global
{5EB1DF0E-EDBD-44EB-8A63-070F13A5D0EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EB1DF0E-EDBD-44EB-8A63-070F13A5D0EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EB1DF0E-EDBD-44EB-8A63-070F13A5D0EE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Default|Any CPU.ActiveCfg = Debug|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Default|Any CPU.Build.0 = Debug|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9}.Release|Any CPU.Build.0 = Release|Any CPU
{A4F37523-CA27-4966-9BC1-51B74F77BE70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4F37523-CA27-4966-9BC1-51B74F77BE70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4F37523-CA27-4966-9BC1-51B74F77BE70}.Default|Any CPU.ActiveCfg = Debug|Any CPU
@@ -129,6 +137,7 @@ Global
{26AB1C43-34F7-446C-A514-EB0E38730631} = {D8F2FC78-7E9E-4F07-86BB-0E0DE31049E9}
{A4F37523-CA27-4966-9BC1-51B74F77BE70} = {D8F2FC78-7E9E-4F07-86BB-0E0DE31049E9}
{3C916941-003B-480E-9981-2B9FEFFBF447} = {E1213B1F-0CD6-4619-83DC-D7070269F5ED}
+ {61EFFFA9-0713-47CA-95D9-193E16BBA3B9} = {E1213B1F-0CD6-4619-83DC-D7070269F5ED}
{214EE669-3ED2-4A03-A9B9-1F71B4257FA6} = {524A0064-011B-46A9-BC3D-A6ECC6E81C44}
{38C76F61-476B-4821-A054-E5FC54F9EDA5} = {524A0064-011B-46A9-BC3D-A6ECC6E81C44}
{308EBC64-BFA7-40E3-9855-20099B94C665} = {214EE669-3ED2-4A03-A9B9-1F71B4257FA6}
View
1 Plugins/AuthProviders/NullAuthProvider/NullAuthProvider.csproj
@@ -9,7 +9,6 @@
<OutputType>Library</OutputType>
<RootNamespace>GithubSharp.Plugins.AuthProviders.NullAuthProvider</RootNamespace>
<AssemblyName>GithubSharp.Plugins.AuthProviders.NullAuthProvider</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
27 Plugins/AuthProviders/UserPasswordAuthProvider/AssemblyInfo.cs
@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("UserPasswordAuthProvider")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("erikz")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
View
12 Plugins/AuthProviders/UserPasswordAuthProvider/MyClass.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace UserPasswordAuthProvider
+{
+ public class MyClass
+ {
+ public MyClass ()
+ {
+ }
+ }
+}
+
View
76 Plugins/AuthProviders/UserPasswordAuthProvider/UserPasswordAuthProvider.cs
@@ -0,0 +1,76 @@
+using System;
+
+namespace GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider
+{
+ public class UserPasswordAuthProvider : GithubSharp.Core.Services.IAuthProvider
+ {
+ public string User {
+ get;
+ set;
+ }
+ public string Password {
+ get;
+ set;
+ }
+
+ public UserPasswordAuthProvider (string Token)
+ {
+ this.RestoreFromToken(Token);
+ }
+
+ public UserPasswordAuthProvider (string user, string password)
+ {
+ User = user;
+ Password = password;
+ }
+
+ public GithubSharp.Core.Services.IAuthResponse Login ()
+ {
+ //Make a request to test the login?
+ return new GithubSharp.Core.Services.AuthResponse
+ {
+ Success = true
+ };
+ }
+
+ public GithubSharp.Core.Services.IAuthResponse Logout ()
+ {
+ return new GithubSharp.Core.Services.AuthResponse
+ {
+ Success = true
+ };
+ }
+
+ public GithubSharp.Core.Services.IAuthPreRequestResponse PreRequestAuth (
+ GithubSharp.Core.IGithubRequest githubRequest,
+ System.Net.HttpWebRequest webRequest)
+ {
+ var authInfo = string.Format("{0}:{1}",User, Password);
+ authInfo = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(authInfo));
+ webRequest.Headers["Authorization"] = "Basic " + authInfo;
+ return new GithubSharp.Core.Services.AuthPreRequestResponse
+ {
+ Success = true,
+ WebRequest = webRequest
+ };
+ }
+
+ public string PrepareUri(string uri)
+ {
+ return uri;
+ }
+
+ public string GetToken ()
+ {
+ //TODO : Hash details here?
+ return string.Empty;
+ }
+
+ public void RestoreFromToken (string token)
+ {
+ //TODO : Unhash details here?
+ }
+
+ }
+}
+
View
45 Plugins/AuthProviders/UserPasswordAuthProvider/UserPasswordAuthProvider.csproj
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{61EFFFA9-0713-47CA-95D9-193E16BBA3B9}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider</RootNamespace>
+ <AssemblyName>GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="UserPasswordAuthProvider.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\Core\Core.csproj">
+ <Project>{59C24364-8C00-46AD-9CE6-1D5630656DF9}</Project>
+ <Name>Core</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
View
6 Plugins/CacheProviders/ApplicationCacher/ApplicationCacher.csproj
@@ -53,11 +53,9 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Web" />
- <Reference Include="System.Data.DataSetExtensions">
- </Reference>
+ <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
- <Reference Include="System.Core">
- </Reference>
+ <Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
View
1 Plugins/CacheProviders/NullCacher/NullCacher.csproj
@@ -9,7 +9,6 @@
<OutputType>Library</OutputType>
<RootNamespace>GithubSharp.Plugins.CacheProviders.NullCacher</RootNamespace>
<AssemblyName>GithubSharp.Plugins.CacheProviders.NullCacher</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
6 Plugins/CacheProviders/WebCache/WebCache.csproj
@@ -52,11 +52,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="System.Core">
- </Reference>
+ <Reference Include="System.Core" />
<Reference Include="System.Data" />
- <Reference Include="System.Data.DataSetExtensions">
- </Reference>
+ <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
View
1 Plugins/LogProviders/NullLogger/NullLogger.csproj
@@ -9,7 +9,6 @@
<OutputType>Library</OutputType>
<RootNamespace>GithubSharp.Plugins.LogProviders.NullLogger</RootNamespace>
<AssemblyName>GithubSharp.Plugins.LogProviders.NullLogger</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
9 Plugins/LogProviders/SimpleLogProvider/SimpleLogProvider.csproj
@@ -53,12 +53,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="System.Core">
- </Reference>
- <Reference Include="System.Xml.Linq">
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- </Reference>
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
View
41 Samples/MvcSample/MvcApplication/MvcApplication.csproj
@@ -10,7 +10,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GithubSharp.MvcSample.MvcApplication</RootNamespace>
<AssemblyName>GithubSharp.MvcSample.MvcApplication</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -31,44 +30,36 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Web.Extensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Web.Abstractions" />
+ <Reference Include="System.Web.Routing" />
+ <Reference Include="System.Web.Helpers">
<HintPath>..\..\..\Libs\mvc\System.Web.Helpers.dll</HintPath>
</Reference>
- <Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.Mvc">
<HintPath>..\..\..\Libs\mvc\System.Web.Mvc.dll</HintPath>
</Reference>
- <Reference Include="System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.Razor">
<HintPath>..\..\..\Libs\mvc\System.Web.Razor.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages.Deployment">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages.Razor">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Data" />
- <Reference Include="System.Web" />
- <Reference Include="System.Web.Extensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Web.Abstractions" />
- <Reference Include="System.Web.Routing" />
- <Reference Include="Munq.MVC3, Version=3.0.4095.22954, Culture=neutral, PublicKeyToken=null">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="Munq.MVC3">
<HintPath>..\..\..\Libs\munq\Munq.MVC3.dll</HintPath>
</Reference>
- <Reference Include="Munq.IocContainer, Version=3.0.4095.22954, Culture=neutral, PublicKeyToken=null">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="Munq.IocContainer">
<HintPath>..\..\..\Libs\munq\Munq.IocContainer.dll</HintPath>
</Reference>
</ItemGroup>
View
29 Samples/MvcSample/MvcUI/MvcUI.csproj
@@ -12,7 +12,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MvcSample.MvcUI</RootNamespace>
<AssemblyName>MvcSample.MvcUI</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -33,35 +32,29 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Web.Abstractions" />
+ <Reference Include="System.Web.Extensions" />
+ <Reference Include="System.Web.Routing" />
+ <Reference Include="System.Web.Mvc">
<HintPath>..\..\..\Libs\mvc\System.Web.Mvc.dll</HintPath>
</Reference>
- <Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.Helpers">
<HintPath>..\..\..\Libs\mvc\System.Web.Helpers.dll</HintPath>
</Reference>
- <Reference Include="System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.Razor">
<HintPath>..\..\..\Libs\mvc\System.Web.Razor.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages.Deployment">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.dll</HintPath>
</Reference>
- <Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Web.WebPages.Razor">
<HintPath>..\..\..\Libs\mvc\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Web" />
- <Reference Include="System.Web.Abstractions" />
- <Reference Include="System.Web.Extensions" />
- <Reference Include="System.Web.Routing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
View
9 Tests/CoreTests/CoreTests.csproj
@@ -9,7 +9,6 @@
<OutputType>Library</OutputType>
<RootNamespace>CoreTests</RootNamespace>
<AssemblyName>CoreTests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -31,13 +30,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="nunit.framework">
<HintPath>..\..\Libs\nunit\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GithubRequestTest.cs" />
+ <Compile Include="TestSettings.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -57,5 +56,9 @@
<Project>{3C916941-003B-480E-9981-2B9FEFFBF447}</Project>
<Name>NullAuthProvider</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Plugins\AuthProviders\UserPasswordAuthProvider\UserPasswordAuthProvider.csproj">
+ <Project>{61EFFFA9-0713-47CA-95D9-193E16BBA3B9}</Project>
+ <Name>UserPasswordAuthProvider</Name>
+ </ProjectReference>
</ItemGroup>
</Project>
View
77 Tests/CoreTests/GithubRequestTest.cs
@@ -1,5 +1,6 @@
using System;
using NUnit.Framework;
+using System.Collections.Generic;
namespace CoreTests
{
@@ -66,9 +67,83 @@ public void GithubRequestWithType()
Assert.IsNotNull(commit.Result.committer.date);
Assert.IsNotNull(commit.Result.author.name);
Assert.IsNotNull(commit.Result.message);
- Assert.IsNotNull(commit.Result.parents);
+ Assert.IsNotNull(commit.Result.parents);
+ Assert.IsTrue(commit.Result.parents.Count > 0);
Assert.IsNotNull(commit.Result.tree.sha);
}
+ [Test]
+ public void GithubRequestWithInput()
+ {
+ var gistFiles = new Dictionary<string,GithubSharp.Core.Models.GistFileForCreation>();
+ gistFiles.Add(
+ "fileName.txt",
+ new GithubSharp.Core.Models.GistFileForCreation
+ {
+ content = "bla bla"
+ });
+
+ var gistToCreate = new GithubSharp.Core.Models.GistToCreate
+ {
+ @public = true,
+ description = "testGist",
+ files = gistFiles
+ };
+ var baseGithubRequest = new GithubSharp.Core.GithubRequestWithInputAndReturnType
+ <GithubSharp.Core.Models.GistToCreate, GithubSharp.Core.Models.Gist>(
+ new GithubSharp.Plugins.LogProviders.NullLogger.NullLogger(true),
+ new GithubSharp.Plugins.CacheProviders.NullCacher.NullCacher(),
+ new GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
+ (TestSettings.Username, TestSettings.Password),
+ "gists",
+ "POST",
+ gistToCreate
+ );
+
+ GithubSharp.Core.IGithubResponseWithReturnType<GithubSharp.Core.Models.Gist> response = null;
+
+ try
+ {
+ response = baseGithubRequest.GetResponseWithReturnType();
+ }
+ catch (Exception err)
+ {
+ if (err is GithubSharp.Core.GithubError)
+ {
+ var githuberr = err as GithubSharp.Core.GithubError;
+ Assert.Fail("StatusCode : {0}, StatusText : {1}, Message : {2}",
+ githuberr.StatusCode, githuberr.StatusText, githuberr.GithubErrorResult.message);
+ return;
+ }
+ else
+ {
+ 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 GithubSharp.Core.GithubRequest(
+ new GithubSharp.Plugins.LogProviders.NullLogger.NullLogger(true),
+ new GithubSharp.Plugins.CacheProviders.NullCacher.NullCacher(),
+ new GithubSharp.Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
+ (TestSettings.Username, TestSettings.Password),
+ string.Format("gists/{0}", response.Result.id),
+ "DELETE"
+
+ );
+
+ var deleteResult = gistDeleteRequest.GetResponse();
+
+
+ Assert.IsNotNull(deleteResult);
+
+ Assert.AreEqual(deleteResult.StatusCode, 204);
+
+ }
}
}
View
16 Tests/CoreTests/TestSettings.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace CoreTests
+{
+ public class TestSettings
+ {
+ public static string Username {
+ get { return "erikzaadi";} //change to your user
+ }
+
+ public static string Password {
+ get { return "No, I won't put my password here"; } //change to your password
+ }
+ }
+}
+

0 comments on commit cae9155

Please sign in to comment.
Something went wrong with that request. Please try again.