Ejemplo n.º 1
0
        public async Task Test_TraktDevice_Equals()
        {
            var traktDevice1 = new TraktDevice();
            var traktDevice2 = new TraktDevice();

            traktDevice1.Equals(traktDevice2).Should().BeTrue();

            var jsonReader          = new DeviceObjectJsonReader();
            var traktDeviceFromJson = await jsonReader.ReadObjectAsync(JSON) as TraktDevice;

            traktDevice1 = CopyTraktDevice(traktDeviceFromJson);
            traktDevice2 = CopyTraktDevice(traktDeviceFromJson);

            traktDevice2.Equals(traktDevice1).Should().BeTrue();

            traktDevice1            = CopyTraktDevice(traktDeviceFromJson);
            traktDevice1.DeviceCode = null;
            traktDevice2.Equals(traktDevice1).Should().BeFalse();

            traktDevice1          = CopyTraktDevice(traktDeviceFromJson);
            traktDevice1.UserCode = null;
            traktDevice2.Equals(traktDevice1).Should().BeFalse();

            traktDevice1 = CopyTraktDevice(traktDeviceFromJson);
            traktDevice1.VerificationUrl = null;
            traktDevice2.Equals(traktDevice1).Should().BeFalse();

            traktDevice1 = CopyTraktDevice(traktDeviceFromJson);
            traktDevice1.ExpiresInSeconds = 0;
            traktDevice2.Equals(traktDevice1).Should().BeFalse();

            traktDevice1 = CopyTraktDevice(traktDeviceFromJson);
            traktDevice1.IntervalInSeconds = 0;
            traktDevice2.Equals(traktDevice1).Should().BeFalse();
        }
Ejemplo n.º 2
0
        public async Task Test_DeviceObjectJsonReader_ReadObject_From_JsonReader_Null()
        {
            var          objectJsonReader = new DeviceObjectJsonReader();
            ITraktDevice traktDevice      = await objectJsonReader.ReadObjectAsync(default(JsonTextReader));

            traktDevice.Should().BeNull();
        }
Ejemplo n.º 3
0
        public void Test_DeviceObjectJsonReader_ReadObject_From_Stream_Null()
        {
            var objectJsonReader = new DeviceObjectJsonReader();
            Func <Task <ITraktDevice> > traktDevice = () => objectJsonReader.ReadObjectAsync(default(Stream));

            traktDevice.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
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();
                }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public async Task Test_TraktDevice_From_Json()
        {
            var jsonReader  = new DeviceObjectJsonReader();
            var traktDevice = await jsonReader.ReadObjectAsync(JSON) as TraktDevice;

            traktDevice.Should().NotBeNull();
            traktDevice.DeviceCode.Should().Be("194e624d66681668632a29292d72b87cb02d4e231d428d3136e596af9e5f942f");
            traktDevice.UserCode.Should().Be("0F843E93");
            traktDevice.VerificationUrl.Should().Be("https://trakt.tv/activate");
            traktDevice.ExpiresInSeconds.Should().Be(600U);
            traktDevice.IntervalInSeconds.Should().Be(5U);
            traktDevice.IntervalInMilliseconds.Should().Be(5000U);
            traktDevice.IsValid.Should().BeTrue();
            traktDevice.IsExpiredUnused.Should().BeFalse();
            traktDevice.CreatedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMilliseconds(1000));
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
                }
        }
Ejemplo n.º 13
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);
                }
        }
Ejemplo n.º 14
0
 public async Task Test_DeviceObjectJsonReader_ReadObject_From_Json_String_Null()
 {
     var objectJsonReader = new DeviceObjectJsonReader();
     Func <Task <ITraktDevice> > traktDevice = () => objectJsonReader.ReadObjectAsync(default(string));
     await traktDevice.Should().ThrowAsync <ArgumentNullException>();
 }