public void TestTraktSerializationServiceDeserializeTraktAuthorizationArgumentExceptions() { Action act = () => TraktSerializationService.DeserializeAuthorization(null); act.ShouldThrow <ArgumentException>(); act = () => TraktSerializationService.DeserializeAuthorization(string.Empty); act.ShouldThrow <ArgumentException>(); }
static void Main(string[] args) { TraktClient client = new TraktClient(CLIENT_ID, CLIENT_SECRET); TraktAuthorization fakeAuthorization = new TraktAuthorization { AccessToken = "FakeAccessToken", RefreshToken = "FakeRefreshToken", ExpiresInSeconds = 90 * 24 * 3600, AccessScope = TraktAccessScope.Public, TokenType = TraktAccessTokenType.Bearer }; Console.WriteLine("Fake Authorization:"); Console.WriteLine($"Created (UTC): {fakeAuthorization.Created}"); Console.WriteLine($"Access Scope: {fakeAuthorization.AccessScope.DisplayName}"); Console.WriteLine($"Refresh Possible: {fakeAuthorization.IsRefreshPossible}"); Console.WriteLine($"Valid: {fakeAuthorization.IsValid}"); Console.WriteLine($"Token Type: {fakeAuthorization.TokenType.DisplayName}"); Console.WriteLine($"Access Token: {fakeAuthorization.AccessToken}"); Console.WriteLine($"Refresh Token: {fakeAuthorization.RefreshToken}"); Console.WriteLine($"Token Expired: {fakeAuthorization.IsExpired}"); Console.WriteLine($"Expires in {fakeAuthorization.ExpiresInSeconds / 3600 / 24} days"); Console.WriteLine("-------------------------------------------------------------"); //string fakeAuthorizationJson = TraktSerializationService.Serialize(client.Authorization); string fakeAuthorizationJson = TraktSerializationService.Serialize(fakeAuthorization); if (!string.IsNullOrEmpty(fakeAuthorizationJson)) { Console.WriteLine("Serialized Fake Authorization:"); Console.WriteLine(fakeAuthorizationJson); Console.WriteLine("-------------------------------------------------------------"); TraktAuthorization deserializedFakeAuthorization = TraktSerializationService.DeserializeAuthorization(fakeAuthorizationJson); if (deserializedFakeAuthorization != null) { client.Authorization = deserializedFakeAuthorization; Console.WriteLine("Deserialized Fake Authorization:"); Console.WriteLine($"Created (UTC): {deserializedFakeAuthorization.Created}"); Console.WriteLine($"Access Scope: {deserializedFakeAuthorization.AccessScope.DisplayName}"); Console.WriteLine($"Refresh Possible: {deserializedFakeAuthorization.IsRefreshPossible}"); Console.WriteLine($"Valid: {deserializedFakeAuthorization.IsValid}"); Console.WriteLine($"Token Type: {deserializedFakeAuthorization.TokenType.DisplayName}"); Console.WriteLine($"Access Token: {deserializedFakeAuthorization.AccessToken}"); Console.WriteLine($"Refresh Token: {deserializedFakeAuthorization.RefreshToken}"); Console.WriteLine($"Token Expired: {deserializedFakeAuthorization.IsExpired}"); Console.WriteLine($"Expires in {deserializedFakeAuthorization.ExpiresInSeconds / 3600 / 24} days"); } } Console.ReadLine(); }
public void TestTraktSerializationServiceDeserializeTraktAuthorizationInvalidJson() { Action act = () => TraktSerializationService.DeserializeAuthorization("{ \"invalid\": \"json\" }"); act.ShouldNotThrow(); var result = TraktSerializationService.DeserializeAuthorization("{ \"invalid\": \"json\" }"); result.Should().BeNull(); }
public void TestTraktSerializationServiceDeserializeTraktAuthorization() { var authorization = TraktSerializationService.DeserializeAuthorization(AUTHORIZATION_JSON); authorization.Should().NotBeNull(); authorization.AccessToken.Should().Be(AUTHORIZATION.AccessToken); authorization.RefreshToken.Should().Be(AUTHORIZATION.RefreshToken); authorization.ExpiresInSeconds.Should().Be(AUTHORIZATION.ExpiresInSeconds); authorization.AccessScope.Should().Be(AUTHORIZATION.AccessScope); authorization.TokenType.Should().Be(AUTHORIZATION.TokenType); authorization.Created.Should().Be(AUTHORIZATION.Created); authorization.IgnoreExpiration.Should().Be(AUTHORIZATION.IgnoreExpiration); }
public void TestTraktSerializationServiceDeserializeTraktAuthorizationInvalidJson() { Action act = () => TraktSerializationService.DeserializeAuthorization("{ \"invalid\": \"json\" }"); act.ShouldNotThrow(); var result = TraktSerializationService.DeserializeAuthorization("{ \"invalid\": \"json\" }"); result.Should().BeNull(); act = () => TraktSerializationService.DeserializeAuthorization("invalid\": \"json\" }"); act.ShouldThrow <ArgumentException>(); string invalidAuthorizationJson = "{" + $"\"AccessToken\":\"\"," + $"\"RefreshToken\":\"\"," + $"\"ExpiresIn\":\"stringvalue\"," + $"\"Scope\":\"public\"," + $"\"TokenType\":\"bearer\"," + $"\"CreatedAtTicks\":0," + $"\"IgnoreExpiration\":false" + "}"; act = () => TraktSerializationService.DeserializeAuthorization(invalidAuthorizationJson); act.ShouldThrow <ArgumentException>(); invalidAuthorizationJson = "{" + $"\"AccessToken\":\"\"," + $"\"RefreshToken\":\"\"," + $"\"ExpiresIn\":0," + $"\"Scope\":\"public\"," + $"\"TokenType\":\"bearer\"," + $"\"CreatedAtTicks\":\"stringvalue\"," + $"\"IgnoreExpiration\":false" + "}"; act = () => TraktSerializationService.DeserializeAuthorization(invalidAuthorizationJson); act.ShouldThrow <ArgumentException>(); }