Exemplo n.º 1
0
 /// <summary>
 /// Constructs an MbUnitCpp tests.
 /// </summary>
 /// <param name="testInfoData">Information about the test.</param>
 /// <param name="resolver"></param>
 public MbUnitCppTest(TestInfoData testInfoData, IStringResolver resolver)
     : base(testInfoData.Name, testInfoData.FakeCodeElement)
 {
     this.testInfoData = testInfoData;
     Id         = testInfoData.GetId();
     Kind       = GetKind(testInfoData.Kind);
     IsTestCase = !testInfoData.HasChildren;
     Metadata.AddAll(testInfoData.GetMetadata(resolver));
 }
Exemplo n.º 2
0
        private TestResult RunTestStep(ITestCommand testCommand, TestInfoData testStepInfo, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            ITestContext   testContext    = testCommand.StartPrimaryChildStep(parentTestStep);
            TestStepResult testStepResult = repository.RunTest(testStepInfo);

            reporter.Run(testContext, testStepInfo, testStepResult);
            WriteToTestLog(testContext, testStepResult);
            testContext.AddAssertCount(testStepResult.AssertCount);
            progressMonitor.Worked(1);
            return(testContext.FinishStep(testStepResult.TestOutcome, testStepResult.Duration));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reports an assertion failure.
        /// </summary>
        /// <param name="testContext"></param>
        /// <param name="testInfoData"></param>
        /// <param name="testStepResult"></param>
        public void Run(ITestContext testContext, TestInfoData testInfoData, TestStepResult testStepResult)
        {
            if (testStepResult.TestOutcome == TestOutcome.Failed)
            {
                MbUnitCppAssertionFailure failure = testStepResult.Failure;
                var builder = new AssertionFailureBuilder(failure.Description);

                if (failure.HasExpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawExpectedAndActualValuesWithDiffs(failure.ExpectedValue, failure.ActualValue);
                }
                else if (failure.HasUnexpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawLabeledValuesWithDiffs("Unexpected Value", failure.UnexpectedValue, "Actual Value", failure.ActualValue);
                }
                else
                {
                    if (failure.HasExpectedValue)
                    {
                        builder.AddRawExpectedValue(failure.ExpectedValue);
                    }

                    if (failure.HasActualValue)
                    {
                        builder.AddRawActualValue(failure.ActualValue);
                    }

                    if (failure.HasUnexpectedValue)
                    {
                        builder.AddRawLabeledValue("Unexpected Value", failure.UnexpectedValue);
                    }
                }

                foreach (var extra in failure.ExtraLabeledValues)
                {
                    builder.AddRawLabeledValue(extra.First, extra.Second);
                }

                if (failure.Message.Length > 0)
                {
                    builder.SetMessage(failure.Message);
                }

                builder.SetStackTrace(testInfoData.GetStackTraceData(failure.Line));
                builder.ToAssertionFailure().WriteTo(testContext.LogWriter.Failures);
            }
        }
Exemplo n.º 4
0
        public bool SetData(
            TestInfoData data1,
            Dictionary <string, string> data2)
        {
            if (data1 == null)
            {
                ErrorString = "测试数据为空";
                return(false);
            }
            tempSetting = data1.TestInfo.TempSetting.Split(",");
            if (data2 != null)
            {
                foreach (var item in data2)
                {
                    exData.Add(item.Key, item.Value);
                }
            }

            testInfo = data1.TestInfo;
            classID  = data1.ProductInfo.ProductClassID;

            var ports = BaseSettingsManager.Get <SystemGroupSetting>().GetPorts(classID);
            var types = new List <string>();

            foreach (var source in data1.TestSources)
            {
                var type = source.SourceType;
                if (!BaseSettingsManager.Get <TestTypeSetting>().ContainsType(type))
                {
                    continue;
                }
                types.Add(type);
            }

            collection = new TestDataCollection(types.ToArray(), tempSetting, ports);

            foreach (var source in data1.TestSources)
            {
                var type = source.SourceType;
                if (!types.Contains(type))
                {
                    continue;
                }

                foreach (var tempData in source.SourceData)
                {
                    var temp = tempData.Key;
                    foreach (var portData in tempData.Value)
                    {
                        var port = portData.Key;
                        var list = new SortedList <double, PointTestItem>();
                        foreach (var wlData in portData.Value)
                        {
                            var wl   = wlData.Key;
                            var item = wlData.Value;
                            list.Add(wl, new PointTestItem(item));
                        }

                        collection.Add(type, temp, port, list);
                    }
                }
            }

            referenceData = new ReferenceData(Guid.Empty, false);
            for (int i = 0; i < data1.ReferenceData.Count; i++)
            {
                foreach (var portTemp in data1.ReferenceData[i])
                {
                    var port = portTemp.Key;
                    foreach (var item in portTemp.Value)
                    {
                        var d = new PointTestItem(item.Value);
                        referenceData.AddReference(i, port, d);
                    }
                }
            }

            exData["sn"]            = data1.TestInfo.SN;
            exData["csn"]           = data1.CustomerSN;
            exData["workorder"]     = data1.WorkInfo.WorkOrderID;
            exData["id"]            = data1.WorkInfo.WorkOrderID;
            exData["workorderid"]   = data1.WorkInfo.WorkOrderID;
            exData["productcode"]   = data1.ProductInfo.ProductCode;
            exData["productname"]   = data1.ProductInfo.ProductName;
            exData["stationname"]   = data1.StationInfo.StationName;
            exData["operator"]      = data1.WorkInfo.WorkInfoOperator;
            exData["room"]          = tempSetting.Length > 0 ? tempSetting[0] : "";
            exData["low"]           = tempSetting.Length > 1 ? tempSetting[1] : "";
            exData["high"]          = tempSetting.Length > 2 ? tempSetting[2] : "";
            exData["productremark"] = data1.ProductInfo.ProductRemark;
            var remarks = data1.ProductInfo.ProductRemark.Split("\r\n");

            for (int i = 0; i < remarks.Length; i++)
            {
                exData[$"productremark[{i}]"] = remarks[i];
            }
            return(true);
        }
Exemplo n.º 5
0
        public void LoadData(Guid id)
        {
            var text = this.Text;

            this.Text = "正在载入数据,请稍候...";
            this.GetService <ModifyTestInfo>().ExecuteAsync(c => c.GetTestInfo(id), (result) =>
            {
                if (!result.Status || result.Data == null)
                {
                    AppFramework.Context.ShowError(result.Message);
                    return;
                }

                testData          = result.Data;
                var dsTestItems   = new DataTable();
                var dsTestInfo    = new DataTable();
                var dsPointSource = new DataTable();
                var dsPDLSource   = new DataTable();
                var dsRLSource    = new DataTable();
                var dsReferencecs = new DataTable();
                System.Threading.ThreadPool.QueueUserWorkItem((O) =>
                {
                    text = string.Format("{0}  {1}", text, testData.TestInfo.SN);

                    CreateTestInfoData(dsTestInfo);
                    CreateTestItemsData(dsTestItems);

                    CreateRefernececsData(dsReferencecs);

                    CreateSourcData("Point", dsPointSource);
                    CreateSourcData("PointPDL", dsPDLSource);
                    CreateSourcData("RL", dsRLSource);

                    while (this.IsNormalState() && !loaded)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                    if (!this.IsNormalState())
                    {
                        return;
                    }

                    this.Invoke(new MethodInvoker(delegate
                    {
                        dgvTestInfo.DataSource = dsTestInfo;
                        dgvTestInfo.Columns["ItemName"].HeaderText  = "项目";
                        dgvTestInfo.Columns["ItemValue"].HeaderText = "结果";

                        dgvTestItems.DataSource = dsTestItems;
                        dgvTestItems.Columns["TestItemID"].Visible     = false;
                        dgvTestItems.Columns["TestID"].Visible         = false;
                        dgvTestItems.Columns["SystemID"].Visible       = false;
                        dgvTestItems.Columns["ItemName"].HeaderText    = "项目";
                        dgvTestItems.Columns["TestTemp"].HeaderText    = "温度";
                        dgvTestItems.Columns["TestSetting"].HeaderText = "设置";
                        foreach (var resultItem in BaseSettingsManager.Get <ResultSettings>().NeedSettingResult)
                        {
                            dgvTestItems.Columns[$"TestItemCompute{resultItem.ResultID}"].HeaderText = resultItem.ResultName;
                        }
                        dgvTestItems.Columns["ItemValue"].HeaderText        = "值";
                        dgvTestItems.Columns["ItemResult"].Visible          = false;
                        dgvTestItems.Columns["ItemResultString"].HeaderText = "结果";
                        dgvTestItems.Columns["OrderID"].HeaderText          = "排序";

                        dgvReferencecs.DataSource = dsReferencecs;
                        dgvReferencecs.Columns["Type"].HeaderText       = "分类";
                        dgvReferencecs.Columns["Port"].HeaderText       = "端口";
                        dgvReferencecs.Columns["WaveLength"].HeaderText = "波长";
                        dgvReferencecs.Columns["Power"].HeaderText      = "功率";
                        dgvReferencecs.Columns["IL"].Visible            = false;
                        dgvReferencecs.Columns["MaxPower"].Visible      = false;
                        dgvReferencecs.Columns["MinPower"].Visible      = false;
                        dgvReferencecs.Columns["AvgPower"].Visible      = false;

                        dgvPointSource.DataSource = dsPointSource;
                        dgvPointSource.Columns["Temperature"].HeaderText = "温度";
                        dgvPointSource.Columns["Port"].HeaderText        = "端口";
                        dgvPointSource.Columns["WaveLength"].HeaderText  = "波长";
                        dgvPointSource.Columns["Power"].HeaderText       = "功率";
                        dgvPointSource.Columns["IL"].HeaderText          = "插损";
                        dgvPointSource.Columns["MaxPower"].Visible       = false;
                        dgvPointSource.Columns["MinPower"].Visible       = false;
                        dgvPointSource.Columns["AvgPower"].Visible       = false;

                        dgvPDLSource.DataSource = dsPDLSource;
                        dgvPDLSource.Columns["Temperature"].HeaderText = "温度";
                        dgvPDLSource.Columns["Port"].HeaderText        = "端口";
                        dgvPDLSource.Columns["WaveLength"].HeaderText  = "波长";
                        dgvPDLSource.Columns["Power"].Visible          = false;
                        dgvPDLSource.Columns["IL"].HeaderText          = "插损";
                        dgvPDLSource.Columns["MaxPower"].HeaderText    = "最大功率";
                        dgvPDLSource.Columns["MinPower"].HeaderText    = "最小功率";
                        dgvPDLSource.Columns["AvgPower"].Visible       = false;

                        dgvRLSource.DataSource = dsRLSource;
                        dgvRLSource.Columns["Temperature"].HeaderText = "温度";
                        dgvRLSource.Columns["Port"].HeaderText        = "端口";
                        dgvRLSource.Columns["WaveLength"].HeaderText  = "波长";
                        dgvRLSource.Columns["Power"].HeaderText       = "读取功率";
                        dgvRLSource.Columns["IL"].HeaderText          = "实际功率";
                        dgvRLSource.Columns["MaxPower"].Visible       = false;
                        dgvRLSource.Columns["MinPower"].Visible       = false;
                        dgvRLSource.Columns["AvgPower"].Visible       = false;
                        this.Text = text;
                    }));
                });
            });
        }
Exemplo n.º 6
0
        public ActionResult <TestInfoData> GetTestInfo(Guid pTestID)
        {
            try
            {
                var info = new TestInfoData();
                info.TestInfo = repository.GetData(pTestID);
                if (info.TestInfo == null)
                {
                    return(ActionResult <TestInfoData> .SetError("找不到数据", null));
                }
                info.WorkInfo    = DbFactory.Repository <WorkInfoRepository>(false).GetData(info.TestInfo.WorkInfoID);
                info.ProductInfo = DbFactory.Repository <ProductInfoRepository>(false).GetData(info.WorkInfo.ProductID);
                info.StationInfo = DbFactory.Repository <StationInfoRepository>(false).GetData(info.WorkInfo.StationID);
                info.SpecInfo    = DbFactory.Repository <SpecInfoRepository>(false).GetData(info.WorkInfo.SpecID);
                info.TestSources = new List <TestSource>();
                var obj = DbFactory.MsSql.ExecuteScalar(
                    new SqlQuery("SerialNumberInfo")
                    .Select("CustomerSN")
                    .Where("SN", info.TestInfo.SN)
                    .Where("ProductID", info.WorkInfo.ProductID)
                    );
                info.CustomerSN = obj == null ? "" : obj.ToString();
                Dictionary <string, string> source = new Dictionary <string, string>();

                if (!Directory.Exists(info.TestInfo.TestSourceSetting))
                {
                    if (info.TestInfo.TestSaveType == 1) //数据库
                    {
                        var tSource = repository.GetTestSource(pTestID);

                        if (tSource.Count > 0)
                        {
                            if (!Directory.Exists(info.TestInfo.TestSourceSetting))
                            {
                                Directory.CreateDirectory(info.TestInfo.TestSourceSetting);
                            }
                            foreach (var item in tSource)
                            {
                                File.WriteAllText($"{info.TestInfo.TestSourceSetting}{item.Key}.json", item.Value);
                            }
                        }
                    }
                    else if (info.TestInfo.TestSaveType == 2)
                    {
                        Download(info.TestInfo.TestSourceSetting, info.TestInfo.TestSourceSetting);
                    }
                }
                var di = new DirectoryInfo(info.TestInfo.TestSourceSetting);
                if (di.Exists)
                {
                    foreach (var item in di.GetFiles("Source_*.json"))
                    {
                        var txt = GetTextFileContent(item.FullName);
                        if (string.IsNullOrEmpty(txt))
                        {
                            continue;
                        }

                        var data = txt.FromJsonString <Dictionary <string, Dictionary <int, SortedList <double, TPointTestItem> > > >();
                        if (data == null)
                        {
                            continue;
                        }
                        var t = item.Name.Split(".")[0].Split("_")[1];
                        info.TestSources.Add(new TestSource()
                        {
                            SourceType = t,
                            SourceData = data
                        });
                    }
                }

                info.ReferenceData = new List <Dictionary <int, SortedList <double, TPointTestItem> > >();
                for (int i = 0; i < 3; i++)
                {
                    var rfPath = $"{info.TestInfo.TestSourceSetting}Reference{i}.json";
                    var data   = default(Dictionary <int, SortedList <double, TPointTestItem> >);

                    var txt = GetTextFileContent(rfPath);
                    if (!string.IsNullOrEmpty(txt))
                    {
                        data = txt.FromJsonString <Dictionary <int, SortedList <double, TPointTestItem> > >();
                    }

                    if (data == null)
                    {
                        data = new Dictionary <int, SortedList <double, TPointTestItem> >();
                    }
                    info.ReferenceData.Add(data);
                }

                return(ActionResult <TestInfoData> .SetSuccess("成功", info));
            }
            catch (Exception ex)
            {
                return(ActionResult <TestInfoData> .SetError(ex.Message, null));
            }
        }