Ejemplo n.º 1
0
        public bool CompareExtendedDashboardMainValueToParameter(string nameOfDashboardValueToCompare, string pathToParameter, double accuracy)
        {
            try
            {
                bool result = false;

                string dashboardValue = this.GetExtendedDashboardMainValueByName(nameOfDashboardValueToCompare);
                string parameterValue = new GetParameterValue().Run(pathToParameter);

                if (dashboardValue == string.Empty)
                {
                    Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Failed to get the value for the dashboard value " + nameOfDashboardValueToCompare + ". Is the name correct?");
                }
                else if (parameterValue == string.Empty)
                {
                    Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Failed to get the value for the parameter" + pathToParameter + ". Is the name correct?");
                }
                else
                {
                    decimal decimal1;
                    decimal decimal2;
                    if (decimal.TryParse(dashboardValue, out decimal1) && decimal.TryParse(parameterValue, out decimal2))
                    {
                        var dashboardValueAsDouble = Convert.ToDouble(dashboardValue);
                        var parameterValueAsDouble = Convert.ToDouble(parameterValue);
                        if (Math.Abs(dashboardValueAsDouble - parameterValueAsDouble) > accuracy)
                        {
                            Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Values are different: Dashboard value for " + nameOfDashboardValueToCompare + " = " + dashboardValueAsDouble + ". Parameter value for " + pathToParameter + " = " + parameterValueAsDouble);
                        }
                        else
                        {
                            Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Values are equal: Dashboard value for " + nameOfDashboardValueToCompare + " = " + dashboardValueAsDouble + ". Parameter value for " + pathToParameter + " = " + parameterValueAsDouble);
                            result = true;
                        }
                    }
                    else if (dashboardValue == parameterValue)
                    {
                        Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Values are equal: Dashboard value for " + nameOfDashboardValueToCompare + " = " + dashboardValue + ". Parameter value for " + pathToParameter + " = " + parameterValue);
                        result = true;
                    }
                    else
                    {
                        Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Values are different: Dashboard value for " + nameOfDashboardValueToCompare + " = " + dashboardValue + ". Parameter value for " + pathToParameter + " = " + parameterValue);
                    }
                }

                return(result);
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                return(false);
            }
        }
        /// <summary>
        /// The compare ne 107 simulation with tree parameter.
        /// </summary>
        /// <param name="tab">
        /// The tab index which will be selected. CodeWrights started index at 1, so 1 = Electronics, 2 = Process, 3 = Configuration, 4 = Simulation
        /// </param>
        /// <param name="diagnosticEvent">
        /// The diagnostic event, must be written as shown on GUI
        /// </param>
        /// <param name="expectedCategory">
        /// The expected category: Failure, Function Check, Out Of Specification or Maintenance Required
        /// </param>
        /// <param name="expectedSimulatedEvent">
        /// The expected simulated event, must be written as shown on GUI
        /// </param>
        /// <param name="pathToParameterInTree">
        /// The path to parameter in tree, must be written as shown on GUI
        /// </param>
        /// <param name="expectedParameterValue">
        /// The expected parameter value, must be written as shown on GUI. Leading letter F, C, S, M could be ignored
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
// ReSharper disable InconsistentNaming
        public bool CompareNE107SimulationWithTreeParameter(int tab, string diagnosticEvent, string expectedCategory, string expectedSimulatedEvent, string pathToParameterInTree, string expectedParameterValue)
// ReSharper restore InconsistentNaming
        {
            if (this.SelectTab(tab))
            {
                string currentCategory = new NE107Functions().GetActiveDiagnosticEventCategory(diagnosticEvent);
                if (this.RemoveWhiteSpaces(currentCategory).ToLower().Contains(this.RemoveWhiteSpaces(expectedCategory).ToLower()))
                {
                    string eventLabel = new NE107Elements().EventLabel(diagnosticEvent).GetAttributeValueText("Text");
                    if (this.SelectTab(4))
                    {
                        string currentSimulatedEvent = new NE107Functions().GetSimulationAreaDiagnosticEventSimulation();
                        if (this.RemoveWhiteSpaces(currentSimulatedEvent).ToLower().Contains(this.RemoveWhiteSpaces(expectedSimulatedEvent).ToLower()))
                        {
                            string[] currentEventParts   = this.NormalizeWhiteSpaces(currentSimulatedEvent).Split(' ');
                            string[] expectedEventParts  = this.NormalizeWhiteSpaces(eventLabel).Split(' ');
                            string   currentEventNumber  = currentEventParts[0];
                            string   expectedEventNumber = expectedEventParts[expectedEventParts.Length - 1];

                            if (currentEventNumber.Equals(expectedEventNumber))
                            {
                                string parameterValue = new GetParameterValue().Run(pathToParameterInTree);
                                if (this.RemoveWhiteSpaces(parameterValue.ToLower()).Contains(this.RemoveWhiteSpaces(expectedParameterValue.ToLower())))
                                {
                                    Report.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Diagnostic Event with [{0}] has expected category [{1}]. \nParameter value of parameter [{2}] is as expected [{3}]", diagnosticEvent, expectedCategory, pathToParameterInTree, expectedParameterValue));
                                    return(true);
                                }

                                Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Parameter value of parameter [{0}] is not as expected [{1}].", pathToParameterInTree, parameterValue));
                                return(false);
                            }

                            Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Diagnostic event number [{0}] is not as expected [{1}]", currentEventNumber, expectedEventNumber));
                            return(false);
                        }

                        Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Simulated diagnostic event [{0}] is not as expected [{1}]", currentSimulatedEvent, expectedSimulatedEvent));
                        return(false);
                    }

                    Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Error while switching to expceted tab [{0}]", tab));
                    return(false);
                }

                Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Diagnostic event category [{0}] is not as expected [{1}]", currentCategory, expectedCategory));
                return(false);
            }

            Report.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Error while switching to expceted tab [{0}]", tab));
            return(false);
        }