示例#1
0
        public async Task TestPollForEvents()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"{MockDigitalstromConnection.BaseUri}/json/event/get")
            .WithExactQueryString($"subscriptionID=42&timeout=60000&token={MockDigitalstromConnection.AppToken}")
            .Respond("application/json", @"{
                                  ""result"":
                                  {
                                      ""events"": [
                                          {
                                              ""name"": ""callScene"",
                                              ""properties"": {
                                                  ""callOrigin"": ""2"",
                                                  ""sceneID"": ""5"",
                                                  ""forced"": ""true"",
                                                  ""groupID"": ""1"",
                                                  ""zoneID"": ""32027"",
                                                  ""originToken"": ""5f4d6babc_dummy_unittest_token_83025a07162890c80a8b587bea589b8e2"",
                                                  ""originDSUID"": ""0000000000000000000000000000000000""
                                              },
                                              ""source"": {
                                                  ""set"": "".zone(32027).group(1)"",
                                                  ""groupID"": 1,
                                                  ""zoneID"": 32027,
                                                  ""isApartment"": false,
                                                  ""isGroup"": true,
                                                  ""isDevice"": false
                                              }
                                          }
                                      ]
                                  },
                                  ""ok"": true
                              }");

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

            var result = await dsApiClient.PollForEvents(42, 60000);

            Assert.Equal("callScene", result.Events[0].Name);
            Assert.Equal("2", result.Events[0].Properties.CallOrigin);
            Assert.Equal("5", result.Events[0].Properties.SceneID);
            Assert.True(result.Events[0].Properties.Forced);
            Assert.Equal("32027", result.Events[0].Properties.ZoneID);
            Assert.Equal("5f4d6babc_dummy_unittest_token_83025a07162890c80a8b587bea589b8e2", result.Events[0].Properties.OriginToken);
            Assert.Equal("0000000000000000000000000000000000", result.Events[0].Properties.OriginDSUID);
            Assert.Equal(".zone(32027).group(1)", result.Events[0].Source.Set);
            Assert.Equal(1, (int)result.Events[0].Source.GroupID);
            Assert.Equal(32027, (int)result.Events[0].Source.ZoneID);
            Assert.False(result.Events[0].Source.IsApartment);
            Assert.True(result.Events[0].Source.IsGroup);
            Assert.False(result.Events[0].Source.IsDevice);
        }
示例#2
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}"));
        }