mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 04:56:29 +00:00
Add attribute to serialize strings as base64 encoded
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user