public void CtorTest_Success()
 {
     Assert.DoesNotThrow(() =>
     {
         using var client = new HomematicIpClient(accessPoint, authToken);
     });
 }
 public void CtorTest_Fail()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using var client = new HomematicIpClient("", "");
     });
 }
        public void InitializeAsyncTest_RaisesEvents()
        {
            var tcs = new TaskCompletionSource <PushEventArgs>();

            using var client        = new HomematicIpClient(accessPoint, authToken);
            client.SerializerError += (s, e) =>
            {
                TestContext.Out.WriteLine(e.ErrorContext.Error.ToString());
                TestContext.Out.WriteLine();
            };
            client.StateChanged += (s, e) => { tcs.SetResult(e); };

            Assert.DoesNotThrowAsync(async() =>
            {
                await client.Initialize();

                var result = await client.Service.GetDevicesAsync(CancellationToken.None);
                var light  = result.OfType <SwitchDeviceBase>().First();

                await client.Service.SetDeviceStateAsync(light.Id, !light.On);
                await tcs.Task.WaitAsync(new CancellationTokenSource(50000).Token);
            });

            //tcs.Task.Wait(50000);
            Assert.IsTrue(tcs.Task.IsCompleted);
        }
        public void GetGroupsAsyncTest_ServiceProviderIsSet()
        {
            IEnumerable <IGroup> result = default;

            using var client = new HomematicIpClient(accessPoint, authToken);
            Assert.DoesNotThrowAsync(async() =>
            {
                await client.Initialize();
                result = await client.Service.GetGroupsAsync(CancellationToken.None);
            });
            Assert.IsTrue(result.All(x => x.Service != null));
        }
        public async Task IsLightAndShadowTest()
        {
            using var client = new HomematicIpClient(accessPoint, authToken);

            await client.Initialize();

            var result = await client.Service.GetDevicesAsync(CancellationToken.None);

            var light = result.OfType <SwitchDeviceBase>().First();

            Assert.IsTrue(light.IsLightAndShadow());
        }
        public async Task ToggleOnTest()
        {
            using var client = new HomematicIpClient(accessPoint, authToken);

            await client.Initialize();

            var result = await client.Service.GetDevicesAsync(CancellationToken.None);

            var light = result.OfType <SwitchDeviceBase>().First();

            await light.ToggleStateAsync();

            var expected = await client.Service.GetDeviceAsync <SwitchDeviceBase>(light.Id);

            Assert.AreEqual(light.Id, expected.Id);
            Assert.AreNotEqual(light.On, expected.On);
        }
        public void GetDevicesAsyncTest_Success()
        {
            IEnumerable <IDevice> result = default;
            var hasError = false;

            using var client        = new HomematicIpClient(accessPoint, authToken);
            client.SerializerError += (s, e) =>
            {
                TestContext.Out.WriteLine(e.ErrorContext.Error.ToString());
                TestContext.Out.WriteLine();
                hasError = true;
            };

            Assert.DoesNotThrowAsync(async() => await client.Initialize());
            Assert.DoesNotThrowAsync(async() => result = await client.Service.GetDevicesAsync(CancellationToken.None));
            CollectionAssert.IsNotEmpty(result);
            Assert.IsFalse(hasError);
        }
        public void GetCurrentStateAsyncTest_Success()
        {
            CurrentState result   = default;
            var          hasError = false;

            using var client        = new HomematicIpClient(accessPoint, authToken);
            client.SerializerError += (s, e) =>
            {
                TestContext.Out.WriteLine(e.ErrorContext.Error.ToString());
                TestContext.Out.WriteLine();
                hasError = true;
            };

            Assert.DoesNotThrowAsync(async() =>
            {
                await client.Initialize();
                result = await client.Service.GetCurrentStateAsync();
            });
            Assert.IsNotNull(result);
            Assert.IsFalse(hasError);
        }
 //[Test()]
 public void InitializeAsyncTest_RunTwiceDoesNotThrow()
 {
     using var client = new HomematicIpClient(accessPoint, authToken);
     Assert.DoesNotThrowAsync(async() => await client.Initialize());
     Assert.DoesNotThrowAsync(async() => await client.Initialize());
 }
 public void GetDevicesAsyncTest_FailIfNotInitialized()
 {
     using var client = new HomematicIpClient(accessPoint, authToken);
     Assert.ThrowsAsync <InvalidOperationException>(async() =>
                                                    await client.Service.GetDevicesAsync(CancellationToken.None));
 }