public static void ArgumentOutOfRangeExceptionIsThrown(Action action, string expectedArgumentName) { if (action == null) { throw new ArgumentNullException("method"); } if (expectedArgumentName == null) { throw new ArgumentNullException("expectedArgumentName"); } if (expectedArgumentName == string.Empty) { throw new ArgumentException(ValidationPredicateMessages.NullOrEmptyStringMessage, "expectedArgumentName"); } ArgumentOutOfRangeException ex = null; try { action(); } catch (ArgumentOutOfRangeException e) { ex = e; } Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType()); Assert.IsNotNull(ex); Assert.AreEqual(expectedArgumentName, ex.ParamName); }
public void Execute_catches_exceptions() { var handler = new OperationResultHandler(); var error = new ArgumentOutOfRangeException("Needs to be about 20% more cool."); new MockOperation <string>(handler, (Action)(() => throw error)); Assert.Equal(error.GetType().FullName, handler.ErrorType); Assert.Equal(error.Message, handler.ErrorMessage); Assert.NotEmpty(handler.ErrorStackTrace); }
public void Execute_catches_exceptions() { var handler = new OperationResultHandler(); var operation = new Mock <OperationExecutor.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); }
public void TestCreationWithIncorrectCapacity() { var actualException = new Exception(); var expectedException = new ArgumentOutOfRangeException(); try { var queue = new CustomQueue <int>(-1); } catch (Exception exception) { actualException = exception; } Assert.AreEqual(expectedException.GetType(), actualException.GetType()); }
// public static TheDarkOwlLogger.TheDarkOwlLogger Bugger = new TheDarkOwlLogger.TheDarkOwlLogger(false, true, true, "WhiteTiger"); public static void errorreport(Exception e) { NoNullAllowedException nonullallowedext = new NoNullAllowedException(); System.Data.RowNotInTableException exrownotinTable = new RowNotInTableException(); System.ArgumentOutOfRangeException excarg = new ArgumentOutOfRangeException(); System.IO.FileNotFoundException filenotfound = new FileNotFoundException(); System.Xml.XmlException xmlexc = new XmlException(); if ((e.GetType() != nonullallowedext.GetType()) && (e.GetType() != exrownotinTable.GetType()) && (e.GetType() != excarg.GetType()) && (e.GetType() != filenotfound.GetType()) && (e.GetType() != xmlexc.GetType())) { logman.TraceException(e.Message, e); } }
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 SetVatRate_IncorrectVatParameter_CorrectExceptionType() { //Arrange var invoiceItem = new InvoiceItem(); int vatParamter = 120; Exception expectedException = null; var argumentOutOfRangeException = new ArgumentOutOfRangeException(); //Act try { invoiceItem.SetVatRate(vatParamter); } catch (Exception ex) { expectedException = ex; } //Assert Assert.AreEqual(argumentOutOfRangeException.GetType(), expectedException.GetType()); }
/// <summary> /// Executes the given command. Will send any exception that occures to the client. /// </summary> /// <param name="serverCommand">The ServerCommand containing the deviceIndex and the command.</param> private static async Task ExecuteCommand(ServerCommand serverCommand) { int deviceIndex = serverCommand.DeviceIndex; if (deviceIndex > MiBands.Count - 1) { MiBands.Add(new MiBand2(MiBands.Count)); } MiBand2 miBand2 = MiBands[deviceIndex]; try { switch (serverCommand.Command) { case Consts.Command.ConnectBand: await miBand2.ConnectBandAsync(); SendSuccess(deviceIndex); break; case Consts.Command.DisconnectBand: miBand2.DisconnectBand(); SendSuccess(deviceIndex); break; case Consts.Command.AuthenticateBand: await miBand2.AuthenticateBandAsync(); SendSuccess(deviceIndex); break; case Consts.Command.StartMeasurement: await miBand2.StartMeasurementAsync(); SendSuccess(deviceIndex); break; case Consts.Command.StopMeasurement: await miBand2.StopMeasurementAsync(); SendSuccess(deviceIndex); break; case Consts.Command.SubscribeToHeartRateChange: miBand2.SubscribeToHeartRateChange(OnHeartRateChange); SendSuccess(deviceIndex); break; case Consts.Command.SubscribeToDeviceConnectionStatusChanged: miBand2.DeviceConnectionChanged += OnDeviceConnectionStatusChanged; break; case Consts.Command.AskUserForTouch: await miBand2.AskUserForTouchAsync(); SendSuccess(deviceIndex); break; case Consts.Command.StopServer: if (miBand2.Connected) { miBand2.DisconnectBand(); } _listenForCommands = false; _server.Stop(); break; default: ArgumentOutOfRangeException exception = new ArgumentOutOfRangeException(nameof(serverCommand.Command), serverCommand.Command, "Could not find command."); SendData(serverCommand.DeviceIndex, new ServerResponse(exception).ToJson()); break; } } catch (Exception exception) { Console.WriteLine("EXCEPTION OCCURED:"); Console.WriteLine("Type: {0}\nMessage{1}", exception.GetType(), exception.Message); ServerResponse response = new ServerResponse(exception); SendData(serverCommand.DeviceIndex, response.ToJson()); } }
public void ArgumentOutOfRangeExceptionĆeBitiUhvaćenKaoArgumentOutOfRangeException() { Assert.IsTrue(ProvjeriCatchBlokove()); Exception e = new ArgumentOutOfRangeException(); Iznimke.VišestrukiBlokoviCatch.HvatanjeIznimkePremaTipu(e); Assert.AreEqual(string.Format(Iznimke.VišestrukiBlokoviCatch.FormatFiltraArgumentOutOfRangeException, e.GetType().Name), cw.GetString()); }