Beispiel #1
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_JsonReader_Null()
        {
            var          objectJsonReader = new DeviceObjectJsonReader();
            ITraktDevice traktDevice      = await objectJsonReader.ReadObjectAsync(default(JsonTextReader));

            traktDevice.Should().BeNull();
        }
Beispiel #2
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Json_String_Empty()
        {
            var          objectJsonReader = new DeviceObjectJsonReader();
            ITraktDevice traktDevice      = await objectJsonReader.ReadObjectAsync(string.Empty);

            traktDevice.Should().BeNull();
        }
Beispiel #3
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Stream_Empty()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var stream = string.Empty.ToStream())
            {
                ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(stream);

                traktDevice.Should().BeNull();
            }
        }
Beispiel #4
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_JsonReader_Empty()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var reader = new StringReader(string.Empty))
                using (var jsonReader = new JsonTextReader(reader))
                {
                    ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(jsonReader);

                    traktDevice.Should().BeNull();
                }
        }
Beispiel #5
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Json_String_Incomplete_6()
        {
            var          objectJsonReader = new DeviceObjectJsonReader();
            ITraktDevice traktDevice      = await objectJsonReader.ReadObjectAsync(JSON_INCOMPLETE_6);

            traktDevice.Should().NotBeNull();
            traktDevice.DeviceCode.Should().Be("mockDeviceCode");
            traktDevice.UserCode.Should().BeNull();
            traktDevice.VerificationUrl.Should().BeNull();
            traktDevice.ExpiresInSeconds.Should().Be(0);
            traktDevice.IntervalInSeconds.Should().Be(0);
        }
Beispiel #6
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Json_String_Not_Valid_6()
        {
            var          objectJsonReader = new DeviceObjectJsonReader();
            ITraktDevice traktDevice      = await objectJsonReader.ReadObjectAsync(JSON_NOT_VALID_6);

            traktDevice.Should().NotBeNull();
            traktDevice.DeviceCode.Should().BeNull();
            traktDevice.UserCode.Should().BeNull();
            traktDevice.VerificationUrl.Should().BeNull();
            traktDevice.ExpiresInSeconds.Should().Be(0);
            traktDevice.IntervalInSeconds.Should().Be(0);
        }
Beispiel #7
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Stream_Incomplete_4()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var stream = JSON_INCOMPLETE_4.ToStream())
            {
                ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(stream);

                traktDevice.Should().NotBeNull();
                traktDevice.DeviceCode.Should().Be("mockDeviceCode");
                traktDevice.UserCode.Should().Be("mockUserCode");
                traktDevice.VerificationUrl.Should().Be("mockUrl");
                traktDevice.ExpiresInSeconds.Should().Be(0);
                traktDevice.IntervalInSeconds.Should().Be(600U);
            }
        }
Beispiel #8
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_Stream_Not_Valid_5()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var stream = JSON_NOT_VALID_5.ToStream())
            {
                ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(stream);

                traktDevice.Should().NotBeNull();
                traktDevice.DeviceCode.Should().Be("mockDeviceCode");
                traktDevice.UserCode.Should().Be("mockUserCode");
                traktDevice.VerificationUrl.Should().Be("mockUrl");
                traktDevice.ExpiresInSeconds.Should().Be(7200U);
                traktDevice.IntervalInSeconds.Should().Be(0);
            }
        }
Beispiel #9
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_JsonReader_Incomplete_3()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var reader = new StringReader(JSON_INCOMPLETE_3))
                using (var jsonReader = new JsonTextReader(reader))
                {
                    ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(jsonReader);

                    traktDevice.Should().NotBeNull();
                    traktDevice.DeviceCode.Should().Be("mockDeviceCode");
                    traktDevice.UserCode.Should().Be("mockUserCode");
                    traktDevice.VerificationUrl.Should().BeNull();
                    traktDevice.ExpiresInSeconds.Should().Be(7200U);
                    traktDevice.IntervalInSeconds.Should().Be(600U);
                }
        }
Beispiel #10
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_JsonReader_Not_Valid_4()
        {
            var objectJsonReader = new DeviceObjectJsonReader();

            using (var reader = new StringReader(JSON_NOT_VALID_4))
                using (var jsonReader = new JsonTextReader(reader))
                {
                    ITraktDevice traktDevice = await objectJsonReader.ReadObjectAsync(jsonReader);

                    traktDevice.Should().NotBeNull();
                    traktDevice.DeviceCode.Should().Be("mockDeviceCode");
                    traktDevice.UserCode.Should().Be("mockUserCode");
                    traktDevice.VerificationUrl.Should().Be("mockUrl");
                    traktDevice.ExpiresInSeconds.Should().Be(0);
                    traktDevice.IntervalInSeconds.Should().Be(600U);
                }
        }
        public async Task Test_TraktAuthenticationModule_GenerateDevice_With_ClientId()
        {
            string deviceJson = await TestUtility.SerializeObject(MockDevice);

            deviceJson.Should().NotBeNullOrEmpty();

            string      postContent = $"{{ \"client_id\": \"{TestConstants.TRAKT_CLIENT_ID}\" }}";
            TraktClient client      = TestUtility.GetAuthenticationMockClient(GET_DEVICE_URI, postContent, deviceJson);
            TraktResponse <ITraktDevice> response = await client.Authentication.GenerateDeviceAsync(TestConstants.TRAKT_CLIENT_ID);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull();

            ITraktDevice responseDevice = response.Value;

            responseDevice.Should().NotBeNull();
            responseDevice.DeviceCode.Should().Be(MockDevice.DeviceCode);
            responseDevice.UserCode.Should().Be(MockDevice.UserCode);
            responseDevice.VerificationUrl.Should().Be(MockDevice.VerificationUrl);
            responseDevice.ExpiresInSeconds.Should().Be(MockDevice.ExpiresInSeconds);
            responseDevice.IntervalInSeconds.Should().Be(MockDevice.IntervalInSeconds);
            responseDevice.CreatedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(3600));
            responseDevice.IsExpiredUnused.Should().BeFalse();
            responseDevice.IsValid.Should().BeTrue();

            ITraktDevice clientDevice = client.Authentication.Device;

            clientDevice.Should().NotBeNull();
            clientDevice.DeviceCode.Should().Be(responseDevice.DeviceCode);
            clientDevice.UserCode.Should().Be(responseDevice.UserCode);
            clientDevice.VerificationUrl.Should().Be(responseDevice.VerificationUrl);
            clientDevice.ExpiresInSeconds.Should().Be(responseDevice.ExpiresInSeconds);
            clientDevice.IntervalInSeconds.Should().Be(responseDevice.IntervalInSeconds);
            clientDevice.CreatedAt.Should().Be(responseDevice.CreatedAt);
            clientDevice.IsExpiredUnused.Should().BeFalse();
            clientDevice.IsValid.Should().BeTrue();
        }