public void Exception_WhenErrorDataIsException_ReturnsException() { var ex = new Exception("test"); var error = new SingleError(ErrorLocation.EmptyLocation, ex, ErrorCode.IndexOutOfBounds); Assert.Same(ex, error.Exception); }
public void Constructor_NullRow_ErrorDetail() { List <InsertErrorsData> errors = new List <InsertErrorsData> { new InsertErrorsData { Index = null, Errors = new List <ErrorProto> { new ErrorProto { Reason = "Very bad reason", Message = "A very bad error occurred" } } } }; SingleError expected = new SingleError { Reason = "Very bad reason", Message = "Error in row unknown. A very bad error occurred" }; // This is allowed in case there's no information (index) // to associate errors to a row. BigQueryInsertRowErrors insertRowErrors = new BigQueryInsertRowErrors(null, errors); Assert.Single(insertRowErrors); Assert.Contains(expected, insertRowErrors, new SingleErrorEqualityComparer()); Assert.Null(insertRowErrors.OriginalRow); Assert.Null(insertRowErrors.OriginalRowIndex); }
public void Exception_WhenErrorDataIsNotException_ReturnsNull() { var ex = new Exception("test"); var error = new SingleError(ErrorLocation.EmptyLocation, ErrorCode.UnitExpected); Assert.Null(error.Exception); }
public void ToString_ReturnsMessageAndLocation() { var location = new ErrorLocation("test"); var error = new SingleError(location, ErrorCode.StepDoesNotExist, "test"); Assert.Equal($"{error.Message} in {location.AsString()}", error.ToString()); }
public void LogError_WhenErrorHasExceptionAndLocation_LogsMessage() { var loggerFactory = TestLoggerFactory.Create(); var logger = loggerFactory.CreateLogger("Test"); const string stepName = "TestStep"; var location = new ErrorLocation( stepName, new TextLocation("Text", new TextPosition(1, 1, 1), new TextPosition(2, 2, 2)) ); var expected = $"Test (Step: {stepName} {location.TextLocation})"; var error = new SingleError(location, new Exception("Test"), ErrorCode.UnexpectedEnumValue); logger.LogError(error); var logMessages = loggerFactory.Sink.LogEntries.ToList(); Assert.NotNull(logMessages[0].Exception); //Test (Step: TestStep Line: 1, Col: 1, Idx: 1 - Line: 2, Col: 2, Idx: 2 Text: Text) Assert.Contains( logMessages, l => l.LogLevel == LogLevel.Error && l.Message !.Equals(expected) ); }
public void LogError_WhenErrorHasNoExceptionAndLocation_LogsMessage() { var loggerFactory = TestLoggerFactory.Create(); var logger = loggerFactory.CreateLogger("Test"); var errorCode = ErrorCode.ExternalProcessError; const string stepName = "TestStep"; var location = new ErrorLocation( stepName, new TextLocation("Text", new TextPosition(1, 1, 1), new TextPosition(2, 2, 2)) ); var expected = $"{errorCode.GetFormattedMessage("error")} (Step: {stepName} {location.TextLocation})"; var error = new SingleError(location, errorCode, "error"); logger.LogError(error); var logMessages = loggerFactory.Sink.LogEntries.ToList(); Assert.Null(logMessages[0].Exception); Assert.Contains( logMessages, l => l.LogLevel == LogLevel.Error && l.Message !.Equals(expected) ); }
public void LogError_WhenErrorHasNoException_LogsMessage() { var loggerFactory = TestLoggerFactory.Create(); var logger = loggerFactory.CreateLogger("Test"); var errorCode = ErrorCode.CannotConvertNestedEntity; var error = new SingleError(ErrorLocation.EmptyLocation, errorCode, "type"); logger.LogError(error); var logMessages = loggerFactory.Sink.LogEntries.ToList(); Assert.Null(logMessages[0].Exception); Assert.Contains( logMessages, l => l.LogLevel == LogLevel.Error && l.Message !.Equals($"{errorCode.GetFormattedMessage("type")} (Step: n/a)") ); }
public void Constructor_NullRow_NoErrorDetail() { List <InsertErrorsData> errors = new List <InsertErrorsData> { new InsertErrorsData { } }; SingleError expected = new SingleError { Message = "Error in row unknown." }; // This is allowed in case there's no information (index) // to associate errors to a row. BigQueryInsertRowErrors insertRowErrors = new BigQueryInsertRowErrors(null, errors); Assert.Single(insertRowErrors); Assert.Contains(expected, insertRowErrors, new SingleErrorEqualityComparer()); Assert.Null(insertRowErrors.OriginalRow); Assert.Null(insertRowErrors.OriginalRowIndex); }
public void LogError_WhenErrorHasException_LogsMessage() { var loggerFactory = TestLoggerFactory.Create(); var logger = loggerFactory.CreateLogger("Test"); var error = new SingleError( ErrorLocation.EmptyLocation, new Exception("Test"), ErrorCode.WrongVariableType ); logger.LogError(error); var logMessages = loggerFactory.Sink.LogEntries.ToList(); Assert.NotNull(logMessages[0].Exception); Assert.Contains( logMessages, l => l.LogLevel == LogLevel.Error && l.Message !.Equals("Test (Step: n/a)") ); }
public Rules oneR() { double errorMinimo; int minimo; var frequences = getFrequences(); var conjuntos = cantidadDeErrores(frequences); List <ErrorPorList> reglasFinales = new List <ErrorPorList>(); foreach (var conjunto in conjuntos) { foreach (var aux in conjunto) { ErrorPorList error = new ErrorPorList(); error.element = aux.element; error.objectiveElement = aux.objectiveElement; error.quantity = aux.quantity; reglasFinales.Add(error); contador += error.quantity; if (contador >= columnas.ElementAt(i).Count) { columnasFinales.Add(columnNames.ElementAt(i++), reglasFinales); reglasFinales = new List <ErrorPorList>(); contador = 0; } } } int j; foreach (var col in columnasFinales) { Rules nuevaRegla = new Rules(); nuevaRegla.name = col.Key; for (int i = 0; i < col.Value.Count; i++) { auxiliar = false; SingleError error = new SingleError() { element = col.Value.ElementAt(i).element, objectiveElement = col.Value.ElementAt(i).objectiveElement, singleError = col.Value.ElementAt(i).quantity }; nuevaRegla.cantidad += (int)error.singleError; j = i + 1; if (j < col.Value.Count) { while (col.Value.ElementAt(j).element == error.element) { auxiliar = true; if (col.Value.ElementAt(j).quantity > error.singleError) { error.element = col.Value.ElementAt(j).element; error.objectiveElement = col.Value.ElementAt(j).objectiveElement; error.singleError = col.Value.ElementAt(j).quantity; } if (nuevaRegla.error == 0) { nuevaRegla.error = error.singleError; } nuevaRegla.cantidad += col.Value.ElementAt(j).quantity; col.Value.RemoveAt(j); j++; if (j >= col.Value.Count) { break; } } if (!auxiliar) { nuevaRegla.error = 0; } } if (error.singleError < nuevaRegla.error) { nuevaRegla.error = error.singleError; } nuevaRegla.reglas.Add(error); } reglas.Add(nuevaRegla); } errorMinimo = reglas.FirstOrDefault().error / reglas.FirstOrDefault().cantidad; minimo = 0; for (int i = 0; i < reglas.Count; i++) { if ((reglas.ElementAt(i).error / reglas.ElementAt(i).cantidad) < errorMinimo) { errorMinimo = reglas.ElementAt(i).error / reglas.ElementAt(i).cantidad; minimo = i; } } return(reglas.ElementAt(minimo)); }
static SizedImage() { possibleErrors = new SingleError[1]; possibleErrors[0] = new SingleError((long)ErrorTypes.BadFile, "BadFile", "You may only upload Image files."); }