From: Manish A. <mag...@us...> - 2007-01-18 10:49:49
|
User: magrawal Date: 07/01/18 02:49:49 Modified: etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit.Tests TestScenarioHelperTests.cs etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit CodeDataProviderAttribute.cs XMLAsserterAttribute.cs XMLDataProviderAttribute.cs Log: added better error messages for failure conditions while loading data from XML files. Revision Changes Path 1.3 +51 -36 plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit.Tests/TestScenarioHelperTests.cs Index: TestScenarioHelperTests.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit.Tests/TestScenarioHelperTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- TestScenarioHelperTests.cs 18 Jan 2007 09:15:22 -0000 1.2 +++ TestScenarioHelperTests.cs 18 Jan 2007 10:49:48 -0000 1.3 @@ -26,14 +26,14 @@ TestScenarioHelper.Invoke("ProcessTestObject", "default", this); } [Test] - [ExpectedException(typeof(FileNotFoundException))] + [ExpectedException(typeof(Exception), "Could not load data for testObj from the file ../../testdata/input\\TestScenarioHelperTests\\ProcessTestObject_NoInputFile_testObj.xml for the test method ProcessTestObject and scenario NoInputFile.")] public void TestInvokeNoInputFile() { TestScenarioHelper.Invoke("ProcessTestObject", "NoInputFile", this); } [Test] - [ExpectedException(typeof(FileNotFoundException))] + [ExpectedException(typeof(Exception), "Could not load the expected output from the file ../../testdata/expected_output\\TestScenarioHelperTests\\ProcessTestObject_NoExpectedOutputFile.xml for the test method ProcessTestObject and scenario NoExpectedOutputFile.")] public void TestInvokeNoExpectedOutputFile() { TestScenarioHelper.Invoke("ProcessTestObject", "NoExpectedOutputFile", this); @@ -402,5 +402,20 @@ } #endregion + #region test missing input or output files + + [Test] + [ExpectedException(typeof(Exception), "Could not write actual output to the file ../../testdata/actual_output\\InvalidPath\\ProcessInvalidOutputPath_InvalidActualOutputPath.xml for the test method ProcessInvalidOutputPath and scenario InvalidActualOutputPath.")] + public void TestInvokeInvalidActualOutputPath() + { + TestScenarioHelper.Invoke("ProcessInvalidOutputPath", "InvalidActualOutputPath", this); + } + + [XMLAsserter(ActualOutputDir = "InvalidPath")] + private TestObject ProcessInvalidOutputPath() + { + return new TestObject(); + } + #endregion } } 1.2 +13 -6 plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/CodeDataProviderAttribute.cs Index: CodeDataProviderAttribute.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/CodeDataProviderAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- CodeDataProviderAttribute.cs 10 Jan 2007 22:56:52 -0000 1.1 +++ CodeDataProviderAttribute.cs 18 Jan 2007 10:49:48 -0000 1.2 @@ -18,14 +18,21 @@ public object GetData(ParameterInfo pInfo, string methodName, string scenarioName, object testFixture) { - if (string.IsNullOrEmpty(DataMethodName)) { DataMethodName = string.Format("{0}_{1}_Data", methodName, pInfo.Name); } + try + { MethodInfo mInfo = testFixture.GetType().GetMethod(DataMethodName, BindingFlags.NonPublic | BindingFlags.Instance| BindingFlags.IgnoreCase); object[] parameters = new object[] { pInfo, methodName, scenarioName }; return mInfo.Invoke(testFixture, parameters); } + catch (Exception e) + { + string errorMessage = string.Format("Could not load data for {0} from the method {1} for the test method {2} and scenario {3}.", pInfo.Name, DataMethodName, methodName, scenarioName); + throw new Exception(errorMessage, e); + } + } } } 1.3 +152 -121 plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/XMLAsserterAttribute.cs Index: XMLAsserterAttribute.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/XMLAsserterAttribute.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- XMLAsserterAttribute.cs 18 Jan 2007 09:15:22 -0000 1.2 +++ XMLAsserterAttribute.cs 18 Jan 2007 10:49:48 -0000 1.3 @@ -101,6 +101,8 @@ { string outputFileName = GetFileName(pInfo, methodName, scenarioName); string actualOutputPath = Path.Combine(ActualOutputDir, outputFileName); + try + { XmlSerializer xs = null; if (null == outputObj) { @@ -116,6 +118,13 @@ xs.Serialize(actualOutput, outputObj); } } + catch (Exception e) + { + string errorMessage = string.Format("Could not write actual output to the file {0} for the test method {1} and scenario {2}.", actualOutputPath, methodName, scenarioName); + throw new Exception(errorMessage, e); + } + } + /// <summary> /// Helper method to call NXUnit assertions on the /// output from the test method and comparing the @@ -133,22 +142,45 @@ string expectedOutputPath = Path.Combine(ExpectedOutputDir, outputFileName); string rulesPath = Path.Combine(RulesDir, outputFileName); XmlDocument rules = new XmlDocument(); + try + { if (File.Exists(rulesPath)) { rules.Load(rulesPath); } + } + catch (Exception e) + { + string errorMessage = string.Format("Could not load the assertion rules from the file {0} for the test method {1} and scenario {2}.", rulesPath, methodName, scenarioName); + throw new Exception(errorMessage, e); + } XmlDocument actualXml = new XmlDocument(); + try + { actualXml.Load(actualOutputPath); ApplyRules(actualXml, rules); + } + catch (Exception e) + { + string errorMessage = string.Format("Could not load the actual output from the file {0} for the test method {1} and scenario {2}.", actualOutputPath, methodName, scenarioName); + throw new Exception(errorMessage, e); + } XmlDocument expectedXml = new XmlDocument(); + try + { expectedXml.Load(expectedOutputPath); ApplyRules(expectedXml, rules); + } + catch (Exception e) + { + string errorMessage = string.Format("Could not load the expected output from the file {0} for the test method {1} and scenario {2}.", expectedOutputPath, methodName, scenarioName); + throw new Exception(errorMessage, e); + } XMLInput actual = XMLInput.CreateInput(actualXml); XMLInput expected = XMLInput.CreateInput(expectedXml); - AssertStrategy strategy = XMLAssert.DEFAULT_STRATEGY; strategy.IsEmptyAttrSensitive = false; strategy.IsEmptyElementSensitive = false; @@ -195,4 +227,3 @@ #endregion } } - \ No newline at end of file 1.2 +23 -9 plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/XMLDataProviderAttribute.cs Index: XMLDataProviderAttribute.cs =================================================================== RCS file: /cvsroot/andromdaplugins/plugins/etc/andromda-dotnet/AndroMDA.ScenarioUnit/AndroMDA.ScenarioUnit/XMLDataProviderAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- XMLDataProviderAttribute.cs 10 Jan 2007 22:56:52 -0000 1.1 +++ XMLDataProviderAttribute.cs 18 Jan 2007 10:49:48 -0000 1.2 @@ -14,6 +14,7 @@ public class XMLDataProviderAttribute : Attribute, IDataProvider { + #region member variables and properties. private string _inputDir; public string InputDir @@ -30,18 +31,30 @@ set { _inputDir = value; } } - + #endregion + #region public methods public object GetData(ParameterInfo pInfo, string methodName, string scenarioName, object testFixture) { string inputFileName = GetFileName(pInfo, methodName, scenarioName); string inputPath = Path.Combine(InputDir, inputFileName); + try + { XmlSerializer xs = new XmlSerializer(pInfo.ParameterType); using (StreamReader sr = new StreamReader(inputPath)) { return xs.Deserialize(sr); } } + catch (Exception e) + { + string errorMessage = string.Format("Could not load data for {0} from the file {1} for the test method {2} and scenario {3}.", pInfo.Name, inputPath, methodName, scenarioName); + throw new Exception(errorMessage, e); + } + } + + #endregion + #region private helper methods /// <summary> /// Helper method to determine the XML file name for a parameter. /// </summary> @@ -52,13 +65,14 @@ private static string GetFileName(ParameterInfo pInfo, string methodName, string scenarioName) { string fileName = methodName + "_" + scenarioName; - if (pInfo.Name != string.Empty && pInfo.Name != "" && pInfo.Name != null) + if (!string.IsNullOrEmpty(pInfo.Name)) { fileName += "_" + pInfo.Name; } fileName += ".xml"; return fileName; } + + #endregion } } - \ No newline at end of file |