public VariableResponse ReadVariables(VariableInfo info)
        {
            if (info == null)
            {
                return(null);
            }
            ;

            var response = new VariableResponse(info.CpuName);

            if (_service.Cpus.ContainsKey(info.CpuName))
            {
                var cpu = _service.Cpus[info.CpuName];

                foreach (var variable in info.Variables)
                {
                    if (cpu.Variables.ContainsKey(variable))
                    {
                        var value = ConvertVariableValue(cpu.Variables[variable].Value);
                        response.AddValue(variable, value);
                    }
                }
            }

            return(response);
        }
Esempio n. 2
0
        public void Process_MessageActionReadAllVariables_CallsReadAllVariables()
        {
            var m = new Message
            {
                Id     = guid,
                Action = MessageAction.ReadAllVariables,
                Data   = "cpu1"
            };

            var variableResponse = new VariableResponse("cpu1");

            variableResponse.AddValue("variable1", "value1");
            variableResponse.AddValue("variable2", "value2");
            variableResponse.AddValue("variable3", "value3");

            var message = JsonConvert.SerializeObject(m);
            Mock <IPviApplication> pviApplicationMock = new Mock <IPviApplication>();

            pviApplicationMock.Setup(p => p.ReadAllVariables(It.IsAny <string>())).Returns(variableResponse);
            var proc     = new MessageProcessor(pviApplicationMock.Object);
            var response = proc.Process(message);

            pviApplicationMock.Verify(p => p.ReadAllVariables(It.IsAny <string>()), Times.Once);

            var result = JsonConvert.DeserializeObject <VariableResponse>(response.Message);

            Assert.NotNull(result);
            Assert.IsType <VariableResponse>(result);
            Assert.True(3 == result.Values.Length);

            for (int i = 0; i < variableResponse.Values.Length; i++)
            {
                Assert.Equal(variableResponse.Values[i].Name, result.Values[i].Name);
                Assert.Equal(variableResponse.Values[i].Value, result.Values[i].Value);
            }
        }