private CpuDetailResponse Map(CpuInfo setting, Cpu cpu) { var detail = new CpuDetailResponse { Description = setting.Description, HasError = cpu.HasError, IpAddress = setting.IpAddress, IsConnected = cpu.IsConnected, Name = setting.Name, Error = cpu.HasError ? new CpuError { ErrorCode = cpu.ErrorCode, ErrorText = cpu.ErrorText } : null }; return(detail); }
public void Process_MessageActionGetCpuByIp_CallsGetsCpuByIp() { var m = new Message { Id = guid, Action = MessageAction.GetCpuByIp, Data = "cpuname1" }; var cpuDetailResponse = new CpuDetailResponse { Description = "cpuname1", IsConnected = true, HasError = false, IpAddress = "120.0.0.1", Name = "cpuname1", Error = null }; var message = JsonConvert.SerializeObject(m); Mock <IPviApplication> pviApplicationMock = new Mock <IPviApplication>(); pviApplicationMock.Setup(p => p.GetCpuByIp(It.IsAny <string>())).Returns(cpuDetailResponse); var proc = new MessageProcessor(pviApplicationMock.Object); var response = proc.Process(message); pviApplicationMock.Verify(p => p.GetCpuByIp(It.IsAny <string>()), Times.Once); var result = JsonConvert.DeserializeObject <CpuDetailResponse>(response.Message); Assert.NotNull(result); Assert.IsType <CpuDetailResponse>(result); Assert.Equal("cpuname1", result.Description); Assert.True(result.IsConnected); Assert.False(result.HasError); Assert.Equal("120.0.0.1", result.IpAddress); Assert.Equal("cpuname1", result.Name); Assert.Null(result.Error); }
private CpuDetailResponse Map(CpuInfo setting, Cpu cpu) { var detail = new CpuDetailResponse(); detail.Description = setting.Description; detail.HasError = cpu.HasError; detail.IpAddress = setting.IpAddress; detail.IsConnected = cpu.IsConnected; detail.Name = setting.Name; if (cpu.HasError) { detail.Error = new CpuError { ErrorCode = cpu.ErrorCode, ErrorText = cpu.ErrorText }; } else { detail.Error = null; } return(detail); }
public void Process_MessageActionGetAllCpu_CallsGetsAllCpu() { var m = new Message { Id = guid, Action = MessageAction.GetAllCpuData, Data = "cpuname1" }; var cpuDetailResponse1 = new CpuDetailResponse { Description = "cpuname1", IsConnected = true, HasError = false, IpAddress = "120.0.0.1", Name = "cpuname1", Error = null }; var cpuDetailResponse2 = new CpuDetailResponse { Description = "cpuname2", IsConnected = true, HasError = false, IpAddress = "120.0.0.2", Name = "cpuname2", Error = null }; var cpuDetailResponse3 = new CpuDetailResponse { Description = "cpuname3", IsConnected = true, HasError = false, IpAddress = "120.0.0.3", Name = "cpuname3", Error = null }; var list = new List <CpuDetailResponse> { cpuDetailResponse1, cpuDetailResponse2, cpuDetailResponse3 }; var message = JsonConvert.SerializeObject(m); Mock <IPviApplication> pviApplicationMock = new Mock <IPviApplication>(); pviApplicationMock.Setup(p => p.GetCpuData()).Returns(list.ToArray()); var proc = new MessageProcessor(pviApplicationMock.Object); var response = proc.Process(message); pviApplicationMock.Verify(p => p.GetCpuData(), Times.Once); var result = JsonConvert.DeserializeObject <CpuDetailResponse[]>(response.Message); Assert.NotNull(result); Assert.IsType <CpuDetailResponse[]>(result); Assert.True(3 == result.Length); for (int i = 0; i < list.Count; i++) { Assert.Equal(list[i].Description, result[i].Description); Assert.Equal(list[i].IsConnected, result[i].IsConnected); Assert.Equal(list[i].HasError, result[i].HasError); Assert.Equal(list[i].IpAddress, result[i].IpAddress); Assert.Equal(list[i].Name, result[i].Name); Assert.Null(list[i].Error); } }