mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 04:40:54 +00:00
Enable DataContractJsonSerializer and apply to GitHubSerializer strategy
This commit is contained in:
@@ -132,6 +132,44 @@ namespace Octokit.Tests.Http
|
||||
|
||||
Assert.Null(response.BodyAsObject);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void PerformsDataMemberAttributeMapping()
|
||||
{
|
||||
const string data = @"{ ""tag"":""tag-name"",
|
||||
""sha"": ""tag-sha"",
|
||||
""url"": ""tag-url"",
|
||||
""message"": ""initial version\n"",
|
||||
""tagger"": {
|
||||
""name"": ""tagger-name"",
|
||||
""email"": ""tagger-email"",
|
||||
""date"": ""2011-06-17T14:53:35-07:00""
|
||||
},
|
||||
""object"": {
|
||||
""type"": ""commit"",
|
||||
""sha"": ""object-sha"",
|
||||
""url"": ""object-url""
|
||||
}}";
|
||||
//const string data = @"{""name"":""tag-name"",""url"":""url""}";
|
||||
|
||||
var response = new ApiResponse<Tag>
|
||||
{
|
||||
Body = data,
|
||||
ContentType = "application/json"
|
||||
};
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
|
||||
jsonPipeline.DeserializeResponse(response);
|
||||
|
||||
Assert.NotNull(response.BodyAsObject);
|
||||
Assert.Equal("tag-name", response.BodyAsObject.Name);
|
||||
Assert.Equal("tag-sha", response.BodyAsObject.Sha);
|
||||
Assert.Equal("tag-url", response.BodyAsObject.Url);
|
||||
Assert.Equal("tag-message", response.BodyAsObject.Message);
|
||||
Assert.Equal("tagger.name", response.BodyAsObject.Tagger.Name);
|
||||
Assert.Equal("tagger.email", response.BodyAsObject.Tagger.Email);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Octokit.Internal
|
||||
return SimpleJson.DeserializeObject<T>(json, _serializationStrategy);
|
||||
}
|
||||
|
||||
class GitHubSerializerStrategy : PocoJsonSerializerStrategy
|
||||
class GitHubSerializerStrategy : DataContractJsonSerializerStrategy
|
||||
{
|
||||
protected override string MapClrMemberNameToJsonFieldName(string clrPropertyName)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DataContract]
|
||||
public class Tag
|
||||
{
|
||||
[DataMember(Name = "tag")]
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//#define SIMPLE_JSON_DYNAMIC
|
||||
|
||||
// NOTE: uncomment the following line to enable DataContract support.
|
||||
//#define SIMPLE_JSON_DATACONTRACT
|
||||
#define SIMPLE_JSON_DATACONTRACT
|
||||
|
||||
// NOTE: uncomment the following line to disable linq expressions/compiled lambda (better performance) instead of method.invoke().
|
||||
// define if you are using .net framework <= 3.0 or < WP7.5
|
||||
|
||||
Reference in New Issue
Block a user