Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
 //[Test()]
 public void InitializeAsyncTest_RunTwiceDoesNotThrow()
 {
     using var client = new HomematicIpClient(accessPoint, authToken);
     Assert.DoesNotThrowAsync(async() => await client.Initialize());
     Assert.DoesNotThrowAsync(async() => await client.Initialize());
 }