コード例 #1
0
        public async Task TestSceneCallOnModelChangePrefilledModel()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.AddInitialAndSubscribeMocks();

            var callSceneRequest1 = mockHttp.AddCallSceneMock(zoneKitchen, Color.Yellow, SceneCommand.Preset1);
            var callSceneRequest2 = mockHttp.AddCallSceneMock(zoneKitchen, Color.Black, SceneCommand.DeepOff);

            var model = new ApartmentState();

            model[zoneKitchen, Color.Yellow].Value = SceneCommand.Preset0;
            model[zoneKitchen, Color.Black].Value  = SceneCommand.Preset0;

            using (var dssClient = new DigitalstromDssClient(mockHttp.AddAuthMock().ToMockProvider()))
                using (var subscriber = new DssEventSubscriber(dssClient, new List <SystemEventName>()
                {
                    SystemEvent.CallScene
                }, 42))
                    using (var aggregator = new TwinChangeAggregator(model))
                    {
                        aggregator.SceneChangedInternal += (s, e) => dssClient.CallScene(e.Zone, e.Group, e.Scene).Wait();

                        Assert.Equal(0, mockHttp.GetMatchCount(callSceneRequest1));
                        Assert.Equal(0, mockHttp.GetMatchCount(callSceneRequest2));

                        await mockHttp.WaitForCallSceneAsync(callSceneRequest1, () =>
                        {
                            model[zoneKitchen, Color.Yellow].Value = SceneCommand.Preset1;
                        });

                        Assert.Equal(1, mockHttp.GetMatchCount(callSceneRequest1));
                        Assert.Equal(0, mockHttp.GetMatchCount(callSceneRequest2));

                        // even setting the same value again should result in a scene call
                        await mockHttp.WaitForCallSceneAsync(callSceneRequest1, () =>
                        {
                            model[zoneKitchen, Color.Yellow].Value = SceneCommand.Preset1;
                        });

                        Assert.Equal(2, mockHttp.GetMatchCount(callSceneRequest1));
                        Assert.Equal(0, mockHttp.GetMatchCount(callSceneRequest2));

                        await mockHttp.WaitForCallSceneAsync(callSceneRequest2, () =>
                        {
                            model[zoneKitchen, Color.Black].Value = SceneCommand.DeepOff;
                        });

                        Assert.Equal(2, mockHttp.GetMatchCount(callSceneRequest1));
                        Assert.Equal(1, mockHttp.GetMatchCount(callSceneRequest2));
                    }
        }
コード例 #2
0
        public async Task TestCallScene()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"{MockDigitalstromConnection.BaseUri}/json/zone/callScene")
            .WithExactQueryString($"id=32027&groupID=1&sceneNumber=5&force=true&token={MockDigitalstromConnection.AppToken}")
            .Respond("application/json", @"{
                                  ""ok"": true
                              }");

            using var dsApiClient = new DigitalstromDssClient(mockHttp.AddAuthMock().ToMockProvider());

            await dsApiClient.CallScene(zoneKitchen, Color.Yellow, SceneCommand.Preset1, true);
        }
コード例 #3
0
        public async Task GenerateUnitTestRequestUris()
        {
            var mockHttp = new MockDigitalstromConnection.TestGenerationHttpMessageHandler();

            using var dsApiClient = new DigitalstromDssClient(mockHttp.AddAuthMock().ToTestGenerationProvider());

            var UriForMethodName = new Dictionary <string, string>();

            try { await dsApiClient.GetSensorValues(); } catch { }
            UriForMethodName.Add("GetSensorValues", mockHttp.LastCalledUri);

            try { await dsApiClient.GetStructure(); } catch { }
            UriForMethodName.Add("GetStructure", mockHttp.LastCalledUri);

            try { await dsApiClient.GetTemperatureControlStatus(); } catch { }
            UriForMethodName.Add("GetTemperatureControlStatus", mockHttp.LastCalledUri);

            try { await dsApiClient.GetTemperatureControlValues(); } catch { }
            UriForMethodName.Add("GetTemperatureControlValues", mockHttp.LastCalledUri);

            try { await dsApiClient.GetTemperatureControlConfig(); } catch { }
            UriForMethodName.Add("GetTemperatureControlConfig", mockHttp.LastCalledUri);

            try { await dsApiClient.SetTemperatureControlValues(zoneKitchen, null, null, 22); } catch { }
            UriForMethodName.Add("SetTemperatureControlValues", mockHttp.LastCalledUri);

            try { await dsApiClient.CallScene(zoneKitchen, Color.Yellow, SceneCommand.Preset1, true); } catch { }
            UriForMethodName.Add("CallScene", mockHttp.LastCalledUri);

            try { await dsApiClient.GetReachableScenes(zoneKitchen, Color.Yellow); } catch { }
            UriForMethodName.Add("GetReachableScenes", mockHttp.LastCalledUri);

            try { await dsApiClient.GetLastCalledScene(zoneKitchen, Color.Yellow); } catch { }
            UriForMethodName.Add("GetLastCalledScene", mockHttp.LastCalledUri);

            try { await dsApiClient.GetZonesAndLastCalledScenes(); } catch { }
            UriForMethodName.Add("GetZonesAndLastCalledScenes", mockHttp.LastCalledUri);

            try { await dsApiClient.GetDevicesAndOutputChannelTypes(); } catch { }
            UriForMethodName.Add("GetDevicesAndOutputChannelTypes", mockHttp.LastCalledUri);

            try { await dsApiClient.GetDevicesAndLastOutputValues(); } catch { }
            UriForMethodName.Add("GetDevicesAndLastOutputValues", mockHttp.LastCalledUri);

            try { await dsApiClient.GetZonesAndSensorValues(); } catch { }
            UriForMethodName.Add("GetZonesAndSensorValues", mockHttp.LastCalledUri);

            try { await dsApiClient.GetMeteringCircuits(); } catch { }
            UriForMethodName.Add("GetMeteringCircuits", mockHttp.LastCalledUri);

            try { await dsApiClient.GetCircuitZones(); } catch { }
            UriForMethodName.Add("GetCircuitZones", mockHttp.LastCalledUri);

            try { await dsApiClient.GetTotalEnergy(1, 600); } catch { }
            UriForMethodName.Add("GetTotalEnergy", mockHttp.LastCalledUri);

            try { await dsApiClient.GetEnergy(new Dsuid("99999942f800000000000f0000deadbeef"), 1, 600); } catch { }
            UriForMethodName.Add("GetEnergy", mockHttp.LastCalledUri);

            try { await dsApiClient.Subscribe((SystemEventName)SystemEvent.CallScene, 42); } catch { }
            UriForMethodName.Add("Subscribe", mockHttp.LastCalledUri);

            try { await dsApiClient.Unsubscribe((SystemEventName)SystemEvent.CallScene, 42); } catch { }
            UriForMethodName.Add("Unsubscribe", mockHttp.LastCalledUri);

            try { await dsApiClient.PollForEvents(42, 60000); } catch { }
            UriForMethodName.Add("PollForEvents", mockHttp.LastCalledUri);

            try
            {
                await dsApiClient.RaiseEvent((SystemEventName)SystemEvent.CallScene,
                                             new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("mykey", "myval") });
            }
            catch { }
            UriForMethodName.Add("RaiseEvent", mockHttp.LastCalledUri);

            var allUris = string.Join("\n", UriForMethodName.Select(x => $"{x.Key}: {x.Value}"));
        }