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

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

            var result = await dsApiClient.GetStructure();

            Assert.Equal("South - none", result.Clusters[0].Name);
            Assert.Equal(2, result.Clusters[0].ApplicationType);
            Assert.True(result.Clusters[0].IsPresent);

            Assert.Equal(32027, (int)result.Zones[0].Id);
            Assert.True(result.Zones[0].IsPresent);

            Assert.Equal("1337234200000e80deadbeef", result.Zones[0].Devices[0].Id);
            Assert.Equal("MyDevice", result.Zones[0].Devices[0].Name);
            Assert.Equal("13372342f800000000000f0000deadbeef", result.Zones[0].Devices[0].DSUID);
            Assert.Equal("99999942f800000000000f0000deadbeef", result.Zones[0].Devices[0].MeterDSUID);
            Assert.Equal(new DateTime(2019, 04, 19, 22, 33, 29), result.Zones[0].Devices[0].LastDiscovered);
            Assert.Equal(new List <int>()
            {
                48
            }.Select(x => (Group)x), result.Zones[0].Devices[0].Groups);

            Assert.Equal(253, (int)result.Zones[0].Devices[0].Sensors[0].Type);
            Assert.Equal(0, result.Zones[0].Devices[0].Sensors[0].Value);
            Assert.False(result.Zones[0].Devices[0].Sensors[0].Valid);

            Assert.Equal(3, (int)result.Zones[0].Groups[0].Color);
            Assert.True(result.Zones[0].Groups[0].IsValid);
            Assert.Equal(new List <int>()
            {
                0, 5, 17, 18, 19, 6
            }.Select(x => (Scene)x), result.Zones[0].Groups[0].ActiveBasicScenes);
        }
示例#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}"));
        }