Пример #1
0
        public void Device_CompareTo_Null()
        {
            var deviceTest = new DeviceTest(_commonServices, DeviceType.UnknownDevice);

            deviceTest.CompareTo(null).Should().Be(1);
            deviceTest.CompareTo((IPureObject)null).Should().Be(1);
        }
        async Task RunAllTheTests()
        {
            TestResults.Clear();
            TableView.ReloadData();

            if (RegisteredTests.Instance.Count == 0)
            {
                NavigationItem.Title = "No Tests to Run";
            }

            for (int counter = 0; counter < RegisteredTests.Instance.Count; counter++)
            {
                var number = counter + 1;
                NavigationItem.Title = $"Running Test {number} of {RegisteredTests.Instance.Count}";

                DeviceTest test = null;
                try
                {
                    test = RegisteredTests.Instance.GetTestAtIndex(counter);
                    await test.Execute();

                    LogTestResult(test, counter, true);
                }
                catch (Exception e)
                {
                    LogFailedException(test, counter, e);
                }
            }
        }
 public LoginViewModel()
 {
     azureService   = new AzureLoginService();
     LoginCommand   = new RelayCommand(DoLogin);
     LogOutCommand  = new RelayCommand(DoLogout);
     MonitorCommand = new RelayCommand(DoMonitor);
     myDeviceTest   = new DeviceTest();
 }
Пример #4
0
        public void Device_CompareTo_DeviceBase()
        {
            var deviceTest  = new DeviceTest(_commonServices, DeviceType.UnknownDevice);
            var deviceTest1 = new DeviceTest(_commonServices, DeviceType.UnknownDevice);

            deviceTest.CompareTo(deviceTest).Should().Be(0);
            deviceTest.CompareTo(deviceTest1).Should().Be(0);
        }
        public void ExecuteAlgorithmeWithForecast_ElevationOverHundredTest()
        {
            //initialize
            DeviceTest device = new DeviceTest {
                Temperature = 6.0, Humidity = 80
            };

            Mock <IStationPosition> stationDeviceMock = new Mock <IStationPosition>();

            stationDeviceMock.Setup(e => e.Altitude).Returns(1000);
            IStationPosition stationDevice = stationDeviceMock.Object;

            WeatherTest freezingToday = new WeatherTest {
                Temperature = 7.0, Humidity = 80, Date = now
            };
            IList <IWeather> forecastList = new List <IWeather> {
                freezingToday
            };

            WeatherTest tomorrow = new WeatherTest {
                Temperature = 5.5, Humidity = 90, Date = now.AddDays(1)
            };

            forecastList.Add(tomorrow);

            WeatherTest afterTomorrow = new WeatherTest {
                Temperature = -1.0, Humidity = 90, Date = now.AddDays(2)
            };

            forecastList.Add(afterTomorrow);

            Mock <IStationPosition> stationMock = new Mock <IStationPosition>();
            IStationPosition        station     = stationMock.Object;

            Mock <IAltitudeClient> altitudeClient = new Mock <IAltitudeClient>();

            altitudeClient.Setup(o => o.GetAltitude(It.IsAny <double>(), It.IsAny <double>())).ReturnsAsync(new GmeElevation
            {
                Altitude = 0
            });
            Mock <ILogger> logger     = new Mock <ILogger>();
            var            freezeAlgo = new FreezingAlgorithme(altitudeClient.Object, logger.Object);

            //execute
            FreezeForecast freeze = freezeAlgo.Execute(device, stationDevice, freezingToday, forecastList, station).Result;

            Check.That(freeze.FreezingStart.HasValue).IsEqualTo(true);
            Check.That(freeze.FreezingEnd.HasValue).IsEqualTo(true);

            Check.That(stationDevice.Altitude).IsStrictlyGreaterThan(100);

            Check.That(freeze.FreezingProbabilityList.Count).IsEqualTo(forecastList.Count());
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now)).IsEqualTo(FreezeForecast.FreezingProbability.ZERO);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(1))).IsEqualTo(FreezeForecast.FreezingProbability.HIGH);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(2))).IsEqualTo(FreezeForecast.FreezingProbability.IMMINENT);
        }
        void LogTestResult(DeviceTest test, int counter, bool result)
        {
            var item = new TestResultDetails()
            {
                test      = test,
                Exception = null,
                Index     = counter,
                Result    = result
            };

            TestResults.Add(item);
        }
        void LogFailedException(DeviceTest test, int counter, Exception e)
        {
            var item = new TestResultDetails()
            {
                test      = test,
                Exception = e,
                Index     = counter,
                Result    = false
            };

            TestResults.Add(item);
        }
Пример #8
0
        public void Device_CompareTo_IPureObject()
        {
            var deviceTest  = new DeviceTest(_commonServices, DeviceType.UnknownDevice);
            var deviceTest1 = new DeviceTest(_commonServices, DeviceType.UnknownDevice);

            deviceTest.CompareTo((IPureObject)deviceTest).Should().Be(0);
            deviceTest.CompareTo((IPureObject)deviceTest1).Should().Be(0);

            Mock <IPureObject> pureObjectMock = new Mock <IPureObject>();

            Func <int> fx = () => deviceTest.CompareTo(pureObjectMock.Object);

            fx.Should().Throw <ArgumentException>().And.Message.Should().Be("Object must be of type DeviceBase.");
        }
Пример #9
0
 public ContactModel( )
 {
     deviceMelsecMC = new DeviceTest( )
     {
         Protocol = "Qna-3E",
         Classes  = new List <string>( )
         {
             "MelsecMcNet", "MelsecMcAsciiNet"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "QJ71E71-100",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 1, 1),
             },
             new DeviceTestItem( )
             {
                 Model    = "Q00J CPU",
                 Name     = "南京-Zoe",
                 DateTime = new DateTime(2018, 08, 25),
             },
             new DeviceTestItem( )
             {
                 Model    = "Q02U CPU",
                 Name     = "南京-Zoe",
                 DateTime = new DateTime(2018, 08, 25),
             },
             new DeviceTestItem( )
             {
                 Model    = "L02 PLC",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
             new DeviceTestItem( )
             {
                 Model    = "Q06UDV PLC",
                 Name     = "泉州-hwdq0012",
                 DateTime = new DateTime(2018, 8, 24),
             },
             new DeviceTestItem( )
             {
                 Model    = "Fx5u PLC",
                 Name     = "山楂",
                 DateTime = new DateTime(2018, 8, 24),
             }
         }
     };
     deviceMelsec1E = new DeviceTest( )
     {
         Protocol = "Qna-1E",
         Classes  = new List <string>( )
         {
             "MelsecA1ENet"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "Fx 3U",
                 Name     = "Unknown",
                 DateTime = new DateTime(2018, 07, 30),
             }
         }
     };
     deviceMelsecFx = new DeviceTest( )
     {
         Protocol = "Fx串口协议",
         Classes  = new List <string>( )
         {
             "MelsecFxSerial"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "Fx 3U",
                 Name     = "江阴-∮溪风-⊙_⌒",
                 DateTime = new DateTime(2018, 08, 24),
             }
         }
     };
     deviceSiemensS7 = new DeviceTest( )
     {
         Protocol = "S7",
         Classes  = new List <string>( )
         {
             "SiemensS7Net"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "1215C",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
             new DeviceTestItem( )
             {
                 Model    = "1214C",
                 Name     = "南京-Zoe",
                 DateTime = new DateTime(2018, 08, 25),
             },
             new DeviceTestItem( )
             {
                 Model    = "1200",
                 Name     = "南京-Zoe",
                 DateTime = new DateTime(2018, 08, 25),
             },
             new DeviceTestItem( )
             {
                 Model    = "1500",
                 Name     = "江阴-∮溪风-⊙_⌒",
                 DateTime = new DateTime(2018, 08, 25),
             },
             new DeviceTestItem( )
             {
                 Model    = "CPU315",
                 Name     = "南京-Zoe",
                 DateTime = new DateTime(2018, 08, 25),
             },
         }
     };
     deviceSiemensFW = new DeviceTest( )
     {
         Protocol = "Fetch/Write",
         Classes  = new List <string>( )
         {
             "SiemensFetchWriteNet"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "s7-314",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
         }
     };
     deviceOmronFins = new DeviceTest( )
     {
         Protocol = "Fins-Tcp",
         Classes  = new List <string>( )
         {
             "OmronFinsNet"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "example",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
         }
     };
     deviceModbusTcp = new DeviceTest( )
     {
         Protocol = "Modbus-Tcp",
         Classes  = new List <string>( )
         {
             "ModbusTcpNet"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "Siemens 1215C",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
             new DeviceTestItem( )
             {
                 Model    = "施耐德 M580PLC",
                 Name     = "杭州~马小辉",
                 DateTime = new DateTime(2018, 11, 30),
             },
             new DeviceTestItem( )
             {
                 Model    = "施耐德 LMC600",
                 Name     = "杭州~马小辉",
                 DateTime = new DateTime(2018, 11, 30),
             },
             new DeviceTestItem( )
             {
                 Model    = "施耐德 M340PLC",
                 Name     = "杭州~马小辉",
                 DateTime = new DateTime(2018, 11, 30),
             },
         }
     };
     deviceModbusRtu = new DeviceTest( )
     {
         Protocol = "Modbus-Rtu",
         Classes  = new List <string>( )
         {
             "ModbusRtu"
         },
         TestItems = new List <DeviceTestItem>( )
         {
             new DeviceTestItem( )
             {
                 Model    = "伺服驱动器",
                 Name     = "杭州-Richard.Hu",
                 DateTime = new DateTime(2018, 07, 30),
             },
         }
     };
 }
Пример #10
0
 public async Task <IViewComponentResult> InvokeAsync(DeviceTest deviceTest)
 {
     return(await Task.Run <IViewComponentResult>(() => View( deviceTest )));
 }
        public void ExecuteAlgorithmeWithForecast_ElevationUnderHundredTest()
        {
            //initialize
            DeviceTest device = new DeviceTest {
                Temperature = 6.0, Humidity = 80
            };

            Mock <IStationPosition> stationDeviceMock = new Mock <IStationPosition>();

            stationDeviceMock.Setup(e => e.Altitude).Returns(10);
            IStationPosition stationDevice = stationDeviceMock.Object;


            WeatherTest freezingToday = new WeatherTest {
                Temperature = -6.0, Humidity = 80, Date = now
            };
            //Mock<IWeather> freezingTodayMock = new Mock<IWeather>();

            //freezingTodayMock.Setup(e => e.Temperature).Returns(20);
            //freezingTodayMock.Setup(e => e.Humidity).Returns(80);
            //freezingTodayMock.Setup(e => e.Date).Returns(now);
            //IWeather freezingToday = freezingTodayMock.Object;
            IEnumerable <IWeather> forecastList = new List <IWeather> {
                freezingToday
            };

            //Mock<IWeather> tomorrowMock = new Mock<IWeather>();
            //tomorrowMock.Setup(e => e.Temperature).Returns(-6);
            //tomorrowMock.Setup(e => e.Humidity).Returns(80);
            //tomorrowMock.Setup(e => e.Date).Returns(now.AddDays(1));
            //IWeather tomorrow = tomorrowMock.Object;
            WeatherTest tomorrow = new WeatherTest {
                Temperature = 12.0, Humidity = 80, Date = now.AddDays(1)
            };

            (forecastList as List <IWeather>).Add(tomorrow);

            //Mock<IWeather> afterTomorrowMock = new Mock<IWeather>();
            //afterTomorrowMock.Setup(e => e.Temperature).Returns(-13.0);
            //afterTomorrowMock.Setup(e => e.Humidity).Returns(50.0);
            //afterTomorrowMock.Setup(e => e.Date).Returns(now.AddDays(2));
            //IWeather afterTomorrow = afterTomorrowMock.Object;
            WeatherTest afterTomorrow = new WeatherTest {
                Temperature = -13.0, Humidity = 50, Date = now.AddDays(2)
            };

            (forecastList as List <IWeather>).Add(afterTomorrow);

            //Mock<IWeather> afterMock = new Mock<IWeather>();
            //afterMock.Setup(e => e.Temperature).Returns(-42);
            //afterMock.Setup(e => e.Humidity).Returns(90);
            //afterMock.Setup(e => e.Date).Returns(now.AddDays(3));
            //IWeather after = afterMock.Object;
            WeatherTest after = new WeatherTest {
                Temperature = -42, Humidity = 90, Date = now.AddDays(3)
            };

            (forecastList as List <IWeather>).Add(after);

            //Mock<IWeather> endFreezeingDayMock = new Mock<IWeather>();
            //endFreezeingDayMock.Setup(e => e.Temperature).Returns(-11.0);
            //endFreezeingDayMock.Setup(e => e.Humidity).Returns(1.0);
            //endFreezeingDayMock.Setup(e => e.Date).Returns(now.AddDays(4));
            //IWeather endFreezeingDay = endFreezeingDayMock.Object;
            WeatherTest endFreezeingDay = new WeatherTest {
                Temperature = -11.0, Humidity = 1.0, Date = now.AddDays(4)
            };

            (forecastList as List <IWeather>).Add(endFreezeingDay);

            //Mock<IWeather> endFreezeingMock = new Mock<IWeather>();
            //endFreezeingMock.Setup(e => e.Temperature).Returns(-20);
            //endFreezeingMock.Setup(e => e.Humidity).Returns(85);
            //endFreezeingMock.Setup(e => e.Date).Returns(now.AddDays(5));
            //IWeather endFreezeing = endFreezeingMock.Object;
            WeatherTest endFreezeing = new WeatherTest {
                Temperature = -20, Humidity = 85, Date = now.AddDays(5)
            };

            (forecastList as List <IWeather>).Add(endFreezeing);

            Mock <IStationPosition> stationMock = new Mock <IStationPosition>();
            IStationPosition        station     = stationMock.Object;

            Mock <IAltitudeClient> altitudeClient = new Mock <IAltitudeClient>();

            altitudeClient.Setup(o => o.GetAltitude(It.IsAny <double>(), It.IsAny <double>())).ReturnsAsync(new GmeElevation
            {
                Altitude = 0
            });
            Mock <ILogger> logger     = new Mock <ILogger>();
            var            freezeAlgo = new FreezingAlgorithme(altitudeClient.Object, logger.Object);

            //execute
            FreezeForecast freeze = freezeAlgo.Execute(device, stationDevice, freezingToday, forecastList, station).Result;

            //test
            Check.That(freeze.FreezingStart.HasValue).IsEqualTo(true);
            Check.That(altitudeClient.Object.GetAltitude(0, 0).Result.Altitude - stationDevice.Altitude).IsStrictlyLessThan(Math.Abs(100));
            Console.WriteLine((forecastList as List <IWeather>).Count);
            Check.That(freeze.FreezingProbabilityList.Count).IsEqualTo((forecastList as List <IWeather>).Count);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now)).IsEqualTo(FreezeForecast.FreezingProbability.HIGH);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(1))).IsEqualTo(FreezeForecast.FreezingProbability.ZERO);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(2))).IsEqualTo(FreezeForecast.FreezingProbability.MEDIUM);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(3))).IsEqualTo(FreezeForecast.FreezingProbability.IMMINENT);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(4))).IsEqualTo(FreezeForecast.FreezingProbability.MEDIUM);
            Check.That(freeze.FreezingProbabilityList.GetValueOrDefault(now.AddDays(5))).IsEqualTo(FreezeForecast.FreezingProbability.IMMINENT);
            Check.That(freeze.FreezingEnd.HasValue).IsEqualTo(true);
        }
Пример #12
0
        public void Device_ToLogParents()
        {
            var deviceTest = new DeviceTest(_commonServices, DeviceType.UnknownDevice);

            TestOutputHelper.WriteLine(deviceTest.ToString(LogLevel.Debug, LoggableFormat.ToLogWithParents));
        }