public void SmartDictionary_Should_HaveNewItem_When_NewDesiredPropertyAdded()
        {
            // Arrange
            const string NEW_KEY   = "new key";
            const string NEW_VALUE = "new value";

            ISmartDictionary reportedProps = GetTestProperties();

            this.target.RegisterChangeUpdateAsync(DEVICE_ID, reportedProps);

            TwinCollection desiredProps = new TwinCollection();

            desiredProps[NEW_KEY] = NEW_VALUE;

            // Act
            // Use reflection to invoke private callback
            MethodInfo methodInfo = this.target.GetType().GetMethod("OnChangeCallback", BindingFlags.Instance | BindingFlags.NonPublic);

            methodInfo.Invoke(this.target, new object[] { desiredProps, null });

            var result = reportedProps.Get(NEW_KEY);

            // Assert
            Assert.Equal(result, NEW_VALUE);
        }
        // For each sensors specified, increase the current state, up to a maximum, then restart from a minimum
        private void RunIncreasingScript(object scriptParams, ISmartDictionary state)
        {
            var sensors = this.JsonParamAsDictionary(scriptParams);

            foreach (var sensor in sensors)
            {
                // Extract scripts parameters from the device model script configuration
                (double min, double max, double step) = this.GetMinMaxStepParameters(sensor.Value);

                // Add the sensor to the state if missing
                if (!state.Has(sensor.Key))
                {
                    state.Set(sensor.Key, min);
                }

                double current = Convert.ToDouble(state.Get(sensor.Key));
                double next    = AreEqual(current, max) ? min : Math.Min(current + step, max);

                state.Set(sensor.Key, next);
            }
        }
예제 #3
0
        public void SmartDictionary_Should_UpdateValue_When_DesiredPropertiesChange()
        {
            // Arrange
            const string NEW_VALUE = "new value";

            ISmartDictionary reportedProps = this.GetTestProperties();

            this.target.RegisterChangeUpdateAsync(this.sdkClient.Object, DEVICE_ID, reportedProps).CompleteOrTimeout();

            TwinCollection desiredProps = new TwinCollection();

            desiredProps[KEY1] = NEW_VALUE;

            // Act
            // Use reflection to invoke private callback
            MethodInfo methodInfo = this.target.GetType().GetMethod("OnChangeCallback", BindingFlags.Instance | BindingFlags.NonPublic);

            methodInfo.Invoke(this.target, new object[] { desiredProps, null });

            var result = reportedProps.Get(KEY1);

            // Assert
            Assert.Equal(result, NEW_VALUE);
        }