mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
maint: Fixing the use of the binary formatter in net461 so all unit tests now pass. (#2535)
This commit is contained in:
@@ -2,11 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
#if !NO_SERIALIZABLE
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
#endif
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
@@ -92,7 +89,6 @@ namespace Octokit.Tests.Exceptions
|
||||
Assert.Equal("message2", thirdException.ApiError.Message);
|
||||
}
|
||||
|
||||
#if !NO_SERIALIZABLE
|
||||
[Fact]
|
||||
public void CanPopulateObjectFromSerializedData()
|
||||
{
|
||||
@@ -102,19 +98,11 @@ namespace Octokit.Tests.Exceptions
|
||||
@"already in use"",""resource"":""PublicKey""}],""message"":""Validation Failed""}");
|
||||
|
||||
var exception = new ApiException(response);
|
||||
var deserialized = BinaryFormatterExtensions.SerializeAndDeserializeObject(exception);
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var formatter = new BinaryFormatter();
|
||||
formatter.Serialize(stream, exception);
|
||||
stream.Position = 0;
|
||||
var deserializedObject = formatter.Deserialize(stream);
|
||||
var deserialized = (ApiException)deserializedObject;
|
||||
Assert.Equal("Validation Failed", deserialized.ApiError.Message);
|
||||
Assert.Equal("key is already in use", exception.ApiError.Errors.First().Message);
|
||||
}
|
||||
Assert.Equal("Validation Failed", deserialized.ApiError.Message);
|
||||
Assert.Equal("key is already in use", exception.ApiError.Errors.First().Message);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class TheToStringMethod
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
#if !NO_SERIALIZABLE
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
#endif
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
using Octokit.Tests.Helpers;
|
||||
|
||||
namespace Octokit.Tests.Exceptions
|
||||
{
|
||||
@@ -38,7 +35,6 @@ namespace Octokit.Tests.Exceptions
|
||||
Assert.Equal("Validation Failed", exception.Message);
|
||||
}
|
||||
|
||||
#if !NO_SERIALIZABLE
|
||||
[Fact]
|
||||
public void CanPopulateObjectFromSerializedData()
|
||||
{
|
||||
@@ -48,18 +44,11 @@ namespace Octokit.Tests.Exceptions
|
||||
@"already in use"",""resource"":""PublicKey""}],""message"":""Validation Failed""}");
|
||||
|
||||
var exception = new ApiValidationException(response);
|
||||
var deserialized = BinaryFormatterExtensions.SerializeAndDeserializeObject(exception);
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var formatter = new BinaryFormatter();
|
||||
formatter.Serialize(stream, exception);
|
||||
stream.Position = 0;
|
||||
var deserialized = (ApiValidationException)formatter.Deserialize(stream);
|
||||
Assert.Equal("Validation Failed", deserialized.ApiError.Message);
|
||||
Assert.Equal("key is already in use", exception.ApiError.Errors.First().Message);
|
||||
}
|
||||
Assert.Equal("Validation Failed", deserialized.ApiError.Message);
|
||||
Assert.Equal("key is already in use", exception.ApiError.Errors.First().Message);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
#if !NO_SERIALIZABLE
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
#endif
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
using Octokit.Tests.Helpers;
|
||||
|
||||
namespace Octokit.Tests.Exceptions
|
||||
{
|
||||
@@ -86,7 +82,6 @@ namespace Octokit.Tests.Exceptions
|
||||
Assert.Equal(TimeSpan.Zero, exception.GetRetryAfterTimeSpan());
|
||||
}
|
||||
|
||||
#if !NO_SERIALIZABLE
|
||||
[Fact]
|
||||
public void CanPopulateObjectFromSerializedData()
|
||||
{
|
||||
@@ -99,24 +94,17 @@ namespace Octokit.Tests.Exceptions
|
||||
|
||||
var exception = new RateLimitExceededException(response);
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var formatter = new BinaryFormatter();
|
||||
formatter.Serialize(stream, exception);
|
||||
stream.Position = 0;
|
||||
var deserialized = (RateLimitExceededException)formatter.Deserialize(stream);
|
||||
var deserialized = BinaryFormatterExtensions.SerializeAndDeserializeObject(exception);
|
||||
|
||||
Assert.Equal(HttpStatusCode.Forbidden, deserialized.StatusCode);
|
||||
Assert.Equal(100, deserialized.Limit);
|
||||
Assert.Equal(42, deserialized.Remaining);
|
||||
var expectedReset = DateTimeOffset.ParseExact(
|
||||
"Mon 01 Jul 2013 5:47:53 PM -00:00",
|
||||
"ddd dd MMM yyyy h:mm:ss tt zzz",
|
||||
CultureInfo.InvariantCulture);
|
||||
Assert.Equal(expectedReset, deserialized.Reset);
|
||||
}
|
||||
Assert.Equal(HttpStatusCode.Forbidden, deserialized.StatusCode);
|
||||
Assert.Equal(100, deserialized.Limit);
|
||||
Assert.Equal(42, deserialized.Remaining);
|
||||
var expectedReset = DateTimeOffset.ParseExact(
|
||||
"Mon 01 Jul 2013 5:47:53 PM -00:00",
|
||||
"ddd dd MMM yyyy h:mm:ss tt zzz",
|
||||
CultureInfo.InvariantCulture);
|
||||
Assert.Equal(expectedReset, deserialized.Reset);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class GetRetryAfterTimeSpanMethod
|
||||
@@ -153,7 +141,7 @@ namespace Octokit.Tests.Exceptions
|
||||
{
|
||||
var beginTime = DateTimeOffset.Now;
|
||||
var resetTime = beginTime - TimeSpan.FromHours(1);
|
||||
|
||||
|
||||
var response = CreateResponse(HttpStatusCode.Forbidden,
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user