internal void Test() { var config = new XmlDocument(); var context = new Context(); config.Load(@"XmlCompare\testConfig.xml"); XmlNode configPart = config.SelectSingleNode("/TestStep"); context.Add("searchDirectory", Directory.GetCurrentDirectory() + @"\XmlCompare"); var comparer = new BizUnitCompare.XmlCompare.XmlCompare(); comparer.Execute(configPart, context); }
public void TestDisposeWithException() { Context context = new Context(); context.DisposeMembersOnTestCaseCompletion = true; IDisposable disposable = mockery.DynamicMock<IDisposable>(); IEnumerable notDisposable = mockery.DynamicMock<IEnumerable>(); context.Add("DisposableClassKey", disposable); context.Add("NotDisposableClassKey", notDisposable); using (mockery.Record()) { disposable.Dispose(); LastCall.Throw(new ApplicationException("Exception thrown during dispose.")).Repeat.Once(); } using (mockery.Playback()) { BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(new BizUnitTestCase("TestDisposeWithException"), context); bizUnit.RunTest(); } }
public void TestDisposeWithNoDisposables() { Context context = new Context(); context.DisposeMembersOnTestCaseCompletion = true; IEnumerable notDisposable = mockery.DynamicMock<IEnumerable>(); using (mockery.Record()) { context.Add("NotDisposableClassKey", notDisposable); } using (mockery.Playback()) { BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(new BizUnitTestCase("TestDisposeWithNoDisposables"), context); bizUnit.RunTest(); } }
public void SetUp() { CleanFileSystem(); _config.Load(@"FlatfileCompare\testConfig.xml"); _configPart = _config.SelectSingleNode("/TestStep"); _context = new Context(); _context.Add("searchDirectory", _testFilesPath); _context.Add("deleteFile", "false"); _context.Add("goalFile", _testFilesPath + "test.goal"); _context.Add("filter", "test.test"); }
private void ValidateXPathExpressions(XmlDocument doc, Context context) { foreach (XPathDefinition validation in _xPathValidations) { var xpathExp = validation.XPath; var expectedValue = validation.Value; if (null != validation.Description) { context.LogInfo("XPath: {0}", validation.Description); } context.LogInfo("Evaluting XPath {0} equals \"{1}\"", xpathExp, expectedValue); XPathNavigator xpn = doc.CreateNavigator(); object result = xpn.Evaluate(xpathExp); string actualValue = null; if (result.GetType().Name == "XPathSelectionIterator") { var xpi = result as XPathNodeIterator; xpi.MoveNext(); // BUGBUG! actualValue = xpi.Current.ToString(); } else { actualValue = result.ToString(); } if (!string.IsNullOrEmpty(validation.ContextKey)) { context.Add(validation.ContextKey, actualValue); } if (!string.IsNullOrEmpty(expectedValue)) { if (0 != expectedValue.CompareTo(actualValue)) { context.LogError("XPath evaluation failed. Expected:<{0}>. Actual:<{1}>.", expectedValue, actualValue); throw new ApplicationException( string.Format("XmlValidationStep failed, compare {0} != {1}, xpath query used: {2}", expectedValue, actualValue, xpathExp)); } context.LogInfo("XPath evaluation succeeded. Expected:<{0}>. Actual:<{1}>.", expectedValue, actualValue); } } }
public void TestNotDispose() { Context context = new Context(); context.DisposeMembersOnTestCaseCompletion = false; IDisposable disposable = mockery.DynamicMock<IDisposable>(); context.Add("DisposableClassKey", disposable); using (mockery.Record()) { disposable.Dispose(); LastCall.Repeat.Never(); } using (mockery.Playback()) { BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(new BizUnitTestCase("TestNotDispose"), context); bizUnit.RunTest(); } }
public void TestDisposeWithSteps() { Context context = new Context(); context.DisposeMembersOnTestCaseCompletion = true; IDisposable disposable = mockery.DynamicMock<IDisposable>(); IEnumerable notDisposable = mockery.DynamicMock<IEnumerable>(); context.Add("DisposableClassKey", disposable); context.Add("NotDisposableClassKey", notDisposable); BizUnitTestCase testCase = new BizUnitTestCase("TestDisposeWithSteps"); ITestStepOM mockStep1 = mockery.DynamicMock<ITestStepOM>(); testCase.AddTestStep(mockStep1, TestStage.Setup); ITestStepOM mockStep2 = mockery.DynamicMock<ITestStepOM>(); testCase.AddTestStep(mockStep2, TestStage.Execution); ITestStepOM mockStep3 = mockery.DynamicMock<ITestStepOM>(); testCase.AddTestStep(mockStep3, TestStage.Cleanup); using (mockery.Record()) { mockStep1.Execute(context); LastCall.Repeat.Once(); mockStep2.Execute(context); LastCall.Repeat.Once(); mockStep3.Execute(context); LastCall.Repeat.Once(); disposable.Dispose(); LastCall.Repeat.Once(); } using (mockery.Playback()) { BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(testCase, context); bizUnit.RunTest(); } }
/// <summary> /// Execute() implementation /// </summary> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public override void Execute(Context context) { FileStream dstFs = null; Stream srcFs = null; try { context.LogInfo("FileCreateStep about to copy the data from File: {0} to the File: {1}", _sourcePath, _creationPath); srcFs = DataSource.Load(context); dstFs = File.Create(_creationPath); var buff = new byte[BuffSize]; int read = srcFs.Read(buff, 0, BuffSize); while (read > 0) { dstFs.Write(buff, 0, read); read = srcFs.Read(buff, 0, BuffSize); } context.Add(FileCreationPathContextKey, _creationPath, true); } finally { if (null != srcFs) { srcFs.Close(); } if (null != dstFs) { dstFs.Close(); } } }