public void Execute_catches_exceptions() { var handler = new Handler(); var operation = new Mock<Executor.OperationBase>(handler) { CallBase = true }; var error = new ArgumentOutOfRangeException("Needs to be about 20% more cool."); operation.Object.Execute(() => { throw error; }); Assert.Equal(error.GetType().FullName, handler.ErrorType); Assert.Equal(error.Message, handler.ErrorMessage); Assert.NotEmpty(handler.ErrorStackTrace); }
private void TS_ThrowTextPatternRangeExceptions() { int results = 0; bool isEqual = false; string text = ""; object nullObject = null; TextPattern differentTextPattern = TextTestsHelper.GetDifferentTextPattern(m_le, CheckType.IncorrectElementConfiguration); TextPatternRange targetRange = null; ArgumentException aeEx = new ArgumentException("<<Fake argument>>"); ArgumentNullException anEx = new ArgumentNullException("<<Fake null argument>>"); TextPatternRange callingRange = null; ArgumentOutOfRangeException aoreEx = new ArgumentOutOfRangeException(); //--------- // Compare //--------- // ArgumentNullException – if the range is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_Compare(callingRange, null, ref isEqual, anEx.GetType(), CheckType.Verification); // ArgumentException – if range is from another container. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_Compare(callingRange, differentTextPattern.DocumentRange, ref isEqual, aeEx.GetType(), CheckType.Verification); //------------------ // CompareEndPoints //------------------ // ArgumentNullException – if the range is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_CompareEndpoints(callingRange, TextPatternRangeEndpoint.Start, null, TextPatternRangeEndpoint.Start, ref results, anEx.GetType(), CheckType.Verification); // ArgumentException – if range is from another container. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_CompareEndpoints(callingRange, TextPatternRangeEndpoint.Start, differentTextPattern.DocumentRange, TextPatternRangeEndpoint.Start, ref results, aeEx.GetType(), CheckType.Verification); //--------------- // FindAttribute //--------------- // ArgumentException – if wrong type is specified. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_FindAttribute(callingRange, ref targetRange, TextPattern.AnimationStyleAttribute, results, true, aeEx.GetType(), CheckType.Verification); // ArgumentNullException – if attribute value is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_FindAttribute(callingRange, ref targetRange, TextPattern.AnimationStyleAttribute, null, true, anEx.GetType(), CheckType.Verification); // ArgumentNullException – if attribute is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_FindAttribute(callingRange, ref targetRange, null, (object)text, true, anEx.GetType(), CheckType.Verification); //---------- // FindText //---------- // ArgumentNullException – if null is applied for search text argument. _tth.Range_FindText( callingRange, ref targetRange, null, true, true, anEx.GetType() , CheckType.Verification ); // ArgumentException –if empty string is applied for search text argument. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_FindText(callingRange, ref targetRange, "", true, true, aeEx.GetType(), CheckType.Verification); //------------------- // GetAttributeValue //------------------- // ArgumentNullException – if attribute is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_GetAttributeValue(callingRange, null, ref nullObject, anEx.GetType(), CheckType.Verification); //--------- // GetText //--------- // Shoduld return ArgumentOutOfRangeException per the spec. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_GetText(callingRange, ref text, Int32.MinValue, aoreEx.GetType(), CheckType.Verification); //--------------------- // MoveEndpointByRange //--------------------- // ArgumentNullException – if targetRange is null. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_MoveEndpointByRange(callingRange, TextPatternRangeEndpoint.Start, null, TextPatternRangeEndpoint.Start, anEx.GetType(), CheckType.Verification); // ArgumentException – if range is from a different container. callingRange = _pattern.DocumentRange.Clone(); _tth.Range_MoveEndpointByRange(callingRange, TextPatternRangeEndpoint.Start, differentTextPattern.DocumentRange, TextPatternRangeEndpoint.Start, aeEx.GetType(), CheckType.Verification); m_TestStep++; }
public void PruebaConstructor() { #region Caso 1: Indice en rango válido. { // Preparación. int índice = 3; // Llama al constructor en prueba. ClaseDeRuta objectoEnPrueba = new ClaseDeRuta(índice); // Prueba Propiedades. Assert.AreEqual(índice, objectoEnPrueba.Indice, "Indice"); } #endregion #region Caso 2: Indice fuera de rango. { // Preparación. int índiceFueraDeRango = 40; bool lanzóExcepción = false; ArgumentOutOfRangeException excepciónEsperada = new ArgumentOutOfRangeException( "El índice de la clase de ruta debe estar entre 0 y menor o igual a 4, pero es: 40"); // Llama al constructor en prueba. try { ClaseDeRuta objectoEnPrueba = new ClaseDeRuta(índiceFueraDeRango); } catch (Exception e) { // Prueba las propiedades de la excepción. Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción"); Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message"); lanzóExcepción = true; } Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción."); } #endregion }
public void TestGetTextMethod50916(TestCaseAttribute testCase) { HeaderComment(testCase); ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException("Unused, just need an instance for GetType() below"); GetTextHelper(SampleText.NotEmpty, TargetRangeType.EmptyStart, MaxLength.NegativeMaxInt, GetResult.Exception, ex.GetType()); }