public void Test_AuthorizationObjectJsonReader_ReadObject_From_Json_String_Null() { var objectJsonReader = new AuthorizationObjectJsonReader(); Func <Task <ITraktAuthorization> > traktAuthorization = () => objectJsonReader.ReadObjectAsync(default(string)); traktAuthorization.Should().Throw <ArgumentNullException>(); }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Json_String_Empty() { var objectJsonReader = new AuthorizationObjectJsonReader(); ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(string.Empty); traktAuthorization.Should().BeNull(); }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_JsonReader_Null() { var objectJsonReader = new AuthorizationObjectJsonReader(); ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(default(JsonTextReader)); traktAuthorization.Should().BeNull(); }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Stream_Empty() { var objectJsonReader = new AuthorizationObjectJsonReader(); using (var stream = string.Empty.ToStream()) { ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(stream); traktAuthorization.Should().BeNull(); } }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_JsonReader_Empty() { var objectJsonReader = new AuthorizationObjectJsonReader(); using (var reader = new StringReader(string.Empty)) using (var jsonReader = new JsonTextReader(reader)) { ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(jsonReader); traktAuthorization.Should().BeNull(); } }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Json_String_Incomplete_4() { var objectJsonReader = new AuthorizationObjectJsonReader { CompleteDeserialization = true }; ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(JSON_INCOMPLETE_4); traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().Be("mockAccessToken"); traktAuthorization.RefreshToken.Should().Be("mockRefreshToken"); traktAuthorization.Scope.Should().Be(TraktAccessScope.Public); traktAuthorization.ExpiresInSeconds.Should().Be(0); traktAuthorization.TokenType.Should().Be(TraktAccessTokenType.Bearer); traktAuthorization.CreatedAtTimestamp.Should().Be(1506271312UL); traktAuthorization.IgnoreExpiration.Should().BeTrue(); }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Json_String_Not_Valid_8() { var objectJsonReader = new AuthorizationObjectJsonReader { CompleteDeserialization = true }; ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(JSON_NOT_VALID_8); traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().BeNull(); traktAuthorization.RefreshToken.Should().BeNull(); traktAuthorization.Scope.Should().BeNull(); traktAuthorization.ExpiresInSeconds.Should().Be(0); traktAuthorization.TokenType.Should().BeNull(); traktAuthorization.CreatedAtTimestamp.Should().Be(0); traktAuthorization.IgnoreExpiration.Should().BeFalse(); }
public static Task <ITraktAuthorization> DeserializeAsync(string authorizationJson, CancellationToken cancellationToken = default) { if (authorizationJson == null) { throw new ArgumentNullException(nameof(authorizationJson), "authorization json string must not be null"); } if (authorizationJson.Length == 0) { throw new ArgumentException(nameof(authorizationJson), "authorization json string must not be empty"); } IObjectJsonReader <ITraktAuthorization> objectJsonReader = JsonFactoryContainer.CreateObjectReader <ITraktAuthorization>(); AuthorizationObjectJsonReader authorizationObjectJsonReader = (objectJsonReader as AuthorizationObjectJsonReader); authorizationObjectJsonReader.CompleteDeserialization = true; return(authorizationObjectJsonReader.ReadObjectAsync(authorizationJson, cancellationToken)); }
public async Task Test_TraktAuthorization_From_Json() { var jsonReader = new AuthorizationObjectJsonReader(); var traktAuthorization = await jsonReader.ReadObjectAsync(JSON) as TraktAuthorization; traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().Be("dbaf9757982a9e738f05d249b7b5b4a266b3a139049317c4909f2f263572c781"); traktAuthorization.RefreshToken.Should().Be("76ba4c5c75c96f6087f58a4de10be6c00b29ea1ddc3b2022ee2016d1363e3a7c"); traktAuthorization.TokenType.Should().Be(TraktAccessTokenType.Bearer); traktAuthorization.ExpiresInSeconds.Should().Be(7776000U); traktAuthorization.Scope.Should().Be(TraktAccessScope.Public); traktAuthorization.CreatedAtTimestamp.Should().Be(s_createdAtTimestamp); traktAuthorization.CreatedAt.Should().Be(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(s_createdAtTimestamp)); traktAuthorization.IsExpired.Should().BeFalse(); traktAuthorization.IsValid.Should().BeTrue(); traktAuthorization.IsRefreshPossible.Should().BeTrue(); traktAuthorization.IgnoreExpiration.Should().BeFalse(); }
public async Task Test_TraktAuthorization_Equals() { var traktAuthorization1 = new TraktAuthorization(); var traktAuthorization2 = new TraktAuthorization(); traktAuthorization1.Equals(traktAuthorization2).Should().BeTrue(); var jsonReader = new AuthorizationObjectJsonReader(); var traktAuthorizationFromJson = await jsonReader.ReadObjectAsync(JSON) as TraktAuthorization; traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization2 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization2.Equals(traktAuthorization1).Should().BeTrue(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.AccessToken = null; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.RefreshToken = null; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.ExpiresInSeconds = 0; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.ExpiresInSeconds = 0; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.Scope = null; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.TokenType = null; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); traktAuthorization1 = CopyTraktAuthorization(traktAuthorizationFromJson); traktAuthorization1.CreatedAtTimestamp = 0; traktAuthorization2.Equals(traktAuthorization1).Should().BeFalse(); }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Stream_Not_Valid_7() { var objectJsonReader = new AuthorizationObjectJsonReader { CompleteDeserialization = true }; using (var stream = JSON_NOT_VALID_7.ToStream()) { ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(stream); traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().Be("mockAccessToken"); traktAuthorization.RefreshToken.Should().Be("mockRefreshToken"); traktAuthorization.Scope.Should().Be(TraktAccessScope.Public); traktAuthorization.ExpiresInSeconds.Should().Be(7200U); traktAuthorization.TokenType.Should().Be(TraktAccessTokenType.Bearer); traktAuthorization.CreatedAtTimestamp.Should().Be(1506271312UL); traktAuthorization.IgnoreExpiration.Should().BeFalse(); } }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Stream_Incomplete_14() { var objectJsonReader = new AuthorizationObjectJsonReader { CompleteDeserialization = true }; using (var stream = JSON_INCOMPLETE_14.ToStream()) { ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(stream); traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().BeNull(); traktAuthorization.RefreshToken.Should().BeNull(); traktAuthorization.Scope.Should().BeNull(); traktAuthorization.ExpiresInSeconds.Should().Be(0); traktAuthorization.TokenType.Should().BeNull(); traktAuthorization.CreatedAtTimestamp.Should().Be(0); traktAuthorization.IgnoreExpiration.Should().BeTrue(); } }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_JsonReader_Incomplete_3() { var objectJsonReader = new AuthorizationObjectJsonReader { CompleteDeserialization = true }; using (var reader = new StringReader(JSON_INCOMPLETE_3)) using (var jsonReader = new JsonTextReader(reader)) { ITraktAuthorization traktAuthorization = await objectJsonReader.ReadObjectAsync(jsonReader); traktAuthorization.Should().NotBeNull(); traktAuthorization.AccessToken.Should().Be("mockAccessToken"); traktAuthorization.RefreshToken.Should().Be("mockRefreshToken"); traktAuthorization.Scope.Should().BeNull(); traktAuthorization.ExpiresInSeconds.Should().Be(7200U); traktAuthorization.TokenType.Should().Be(TraktAccessTokenType.Bearer); traktAuthorization.CreatedAtTimestamp.Should().Be(1506271312UL); traktAuthorization.IgnoreExpiration.Should().BeTrue(); } }
public async Task Test_AuthorizationObjectJsonReader_ReadObject_From_Stream_Null() { var objectJsonReader = new AuthorizationObjectJsonReader(); Func <Task <ITraktAuthorization> > traktAuthorization = () => objectJsonReader.ReadObjectAsync(default(Stream)); await traktAuthorization.Should().ThrowAsync <ArgumentNullException>(); }