Add attribute to serialize strings as base64 encoded

This commit is contained in:
Haacked
2014-12-29 22:51:16 -08:00
parent 99b93c1293
commit 83bc99256a
9 changed files with 119 additions and 12 deletions
+39 -1
View File
@@ -1,4 +1,4 @@
using System;
using Octokit.Helpers;
using Octokit.Internal;
using Xunit;
@@ -63,6 +63,21 @@ namespace Octokit.Tests
Assert.Equal("{\"int\":42,\"bool\":true}", json);
}
[Fact]
public void HandlesBase64EncodedStrings()
{
var item = new SomeObject
{
Name = "Ferris Bueller",
Content = "Day off",
Description = "stuff"
};
var json = new SimpleJsonSerializer().Serialize(item);
Assert.Equal("{\"name\":\"RmVycmlzIEJ1ZWxsZXI=\",\"description\":\"stuff\",\"content\":\"RGF5IG9mZg==\"}", json);
}
}
public class TheDeserializeMethod
@@ -80,6 +95,18 @@ namespace Octokit.Tests
Assert.True(sample.Private);
}
[Fact]
public void UnencodesBase64Strings()
{
const string json = "{\"name\":\"RmVycmlzIEJ1ZWxsZXI=\",\"description\":\"stuff\",\"content\":\"RGF5IG9mZg==\"}";
var someObject = new SimpleJsonSerializer().Deserialize<SomeObject>(json);
Assert.Equal("Ferris Bueller", someObject.Name);
Assert.Equal("Day off", someObject.Content);
Assert.Equal("stuff", someObject.Description);
}
[Fact]
public void CanDeserializeOrganization()
{
@@ -154,5 +181,16 @@ namespace Octokit.Tests
[Parameter(Key = "_links")]
public string Links { get; set; }
}
public class SomeObject
{
[SerializeAsBase64]
public string Name { get; set; }
[SerializeAsBase64]
public string Content;
public string Description { get; set; }
}
}
}