public static void Init(string jsonFilename, string?rootPath = null) { if (rootPath != null) { TestDataRoot = rootPath; } TestItems.Clear(); var items = JsonConvert.DeserializeObject <List <Item> >(File.ReadAllText(Path.Combine(TestDataRoot, jsonFilename)), new JsonSerializerSettings() { Converters = { new Converter() } }); if (items == null) { return; } foreach (var item in items) { TestItems.Add(item.Name, item); } }
/// <summary> /// 注册测试信息 /// </summary> /// <param name="controller"></param> /// <param name="job"></param> /// <param name="testChannel"></param> public void Register(MeasurementController controller, MeasurementJobInformation job, bool[] testChannel) { MeasurementController = controller; MeasurementJob = job; //点测测试组 var ILgroups = job.SpecData.TestSystemGroups.Where(q => q.TestGroupTestType == "Point" || q.TestGroupTestType == "PointPDL").Select(q => q.TestGroupID).ToList(); //回损测试组 var RLgroups = job.SpecData.TestSystemGroups.Where(q => q.TestGroupTestType == "RL").Select(q => q.TestGroupID).ToList(); //点测测试项 var ilTestItems = job.SpecData.WorkInfoSpecItems.Where(q => ILgroups.Any(g => g == q.TestGroupID) || RLgroups.Any(g => g == q.TestGroupID)).ToList(); //插损 //回损测试项 var rl1TestItems = job.SpecData.WorkInfoSpecItems.Where(q => RLgroups.Any(g => g == q.TestGroupID)).ToList(); //按端口归组 var portILGroup = ilTestItems.GroupBy(q => q.PortSetting % TestPortSetting.DataDivide).ToList(); TestItems.Clear(); TestItems.Add(new ReferenceTestItem() { ItemID = Guid.NewGuid(), TestTypeID = TestTypes[0], ItemName = "连接仪器", Wavelenght = 0D, Channel = 0, ReferenceType = -1, ReferenceData = default(List <TPointTestItem>), LastValueString = "", ValueString = "", ReferenceResult = -1, OrderID = TestItems.Count + 1 }); Wavelengths.Clear(); Channels.Clear(); for (int i = 0; i < Framework.MeasurementSystemSetting.SystemData.Setting.Profile.SimultaneousNumber; i++) { if (testChannel.Length > i && !testChannel[i]) { continue; } foreach (var port in portILGroup) { if (port.Key == 0) { continue; } var list = port.ToList(); if (list.Count < 1) { continue; } var channel = MeasurementController.GetSimultaneityPort(i, port.Key); string name = MeasurementController.GetPortName(channel); var wlGroup = list.Where(q => q.TestSetting.IsDouble()).GroupBy(q => q.TestSetting.CastTo <double>()); foreach (var wlItem in wlGroup) { var wl = wlItem.Key; var refData = ""; var oldRef = job.ReferenceData.GetReference(1, channel, wl); if (oldRef != null) { refData = oldRef.Power.ToString("F3"); } TestItems.Add(new ReferenceTestItem() { ItemID = Guid.NewGuid(), TestTypeID = TestTypes[1], ItemName = $"获取 IL (功率计 {name}, 波长 {wl}) 归零值", Wavelenght = wl, Channel = channel, ReferenceType = 1, ReferenceData = new List <TPointTestItem>(), LastValueString = refData, ValueString = "", ReferenceResult = -1, OrderID = TestItems.Count + 1 }); if (!Wavelengths.Contains(wl)) { Wavelengths.Add(wl); } if (!Channels.Contains(channel)) { Channels.Add(channel); } } } } //按端口归组 var portRLGroup = rl1TestItems.GroupBy(q => q.PortSetting % TestPortSetting.DataDivide).ToList(); for (int i = 0; i < Framework.MeasurementSystemSetting.SystemData.Setting.Profile.SimultaneousNumber; i++) { if (testChannel.Length > i && !testChannel[i]) { continue; } foreach (var port in portRLGroup) { if (port.Key == 0) { continue; } var list = port.ToList(); if (list.Count < 1) { continue; } var channel = MeasurementController.GetSimultaneityPort(i, port.Key); string name = MeasurementController.GetPortName(channel); var wlGroup = list.Where(q => q.TestSetting.IsDouble()).GroupBy(q => q.TestSetting.CastTo <double>()); foreach (var wlItem in wlGroup) { var wl = wlItem.Key; var refData = ""; var oldRef = job.ReferenceData.GetReference(2, channel, wl); if (oldRef != null) { refData = oldRef.Power.ToString("F3"); } TestItems.Add(new ReferenceTestItem() { ItemID = Guid.NewGuid(), TestTypeID = TestTypes[2], ItemName = $"获取 ({name},波长 {wl}) 的系统回损", Wavelenght = wl, Channel = channel, ReferenceType = 2, ReferenceData = new List <TPointTestItem>(), LastValueString = refData, ValueString = "", ReferenceResult = -1, OrderID = TestItems.Count + 1 }); if (!Wavelengths.Contains(wl)) { Wavelengths.Add(wl); } if (!Channels.Contains(channel)) { Channels.Add(channel); } } } } TestItems.Add(new ReferenceTestItem() { ItemID = Guid.NewGuid(), TestTypeID = TestTypes[TestTypes.Length - 1], ItemName = "保存数据", Wavelenght = 0D, Channel = 0, ReferenceType = -1, ReferenceData = new List <TPointTestItem>(), LastValueString = "", ValueString = "", ReferenceResult = -1, OrderID = TestItems.Count + 1 }); }
public void RunTests() { if (IsRunning) { return; } TestItems.Clear(); IsRunning = true; var assembly = Assembly.GetCallingAssembly(); Type[] types = assembly.GetTypes(); // Find all the test classes // foreach (Type type in types) { if (type.IsDefined(typeof(TestFixtureAttribute), false)) { object fixtureInstance = Activator.CreateInstance(type); MethodInfo[] methods = type.GetMethods(); MethodInfo setUpMethod = methods.FirstOrDefault(x => x.IsDefined(typeof(SetUpAttribute), false)); MethodInfo tearDownMethod = methods.FirstOrDefault(x => x.IsDefined(typeof(TearDownAttribute), false)); foreach (MethodInfo testMethod in methods) { if (testMethod.IsDefined(typeof(TestAttribute), false)) { // Add the item to the list for UI purposes TestItems.Add(new TestItem { Name = type.Name + "::" + testMethod.Name }); TestItems.Last().Success = true; try { // First run setup for the test if available if (setUpMethod != null) { setUpMethod.Invoke(fixtureInstance, null); } } catch (Exception e) { TestItems.Last().Success = false; TestItems.Last().Message = e.ToString(); } // If the setup was successful, run the test method, ignoring expected exceptions // if (TestItems.Last().Success.Value) { try { testMethod.Invoke(fixtureInstance, null); } catch (Exception e) { if (testMethod.IsDefined(typeof(ExpectedException), false)) { var expectedEx = testMethod.GetCustomAttributes(typeof(ExpectedException), false)[0] as ExpectedException; if (e.InnerException == null || expectedEx.ExceptionType != e.InnerException.GetType()) { TestItems.Last().Success = false; TestItems.Last().Message = e.ToString(); } } else { TestItems.Last().Success = false; TestItems.Last().Message = e.ToString(); } } } try { // Finally clean up regardless of previous results // if (tearDownMethod != null) { tearDownMethod.Invoke(fixtureInstance, null); } } catch (Exception e) { TestItems.Last().Success = false; TestItems.Last().Message = e.ToString(); } } } } } IsRunning = false; }