예제 #1
0
        public ErrorResult EnrichError(SpreadsheetWorkbook spreadsheetWorkbook, Exception e)
        {
            var formulaName = spreadsheetWorkbook.GetFormulaName();

            if (e.GetType() == typeof(ExpressionParseException))
            {
                var error = "Invalid expression found in tax formula [" + formulaName +
                            "]. Check that separators and delimiters use the English locale.";
                return(new ErrorResult(formulaName, error, spreadsheetWorkbook.GetPresentation()));
            }

            if (e.Message.StartsWith("Circular Reference"))
            {
                var error = parseCircularReferenceException(e, formulaName);
                return(new ErrorResult(formulaName, error, spreadsheetWorkbook.GetPresentation()));
            }

            if ("Object reference not set to an instance of an object".Equals(e.Message) &&
                StackTraceContains(e, "vLookup"))
            {
                return(new ErrorResult(formulaName, "Missing Lookup Table", spreadsheetWorkbook.GetPresentation()));
            }
            if ("No matches found".Equals(e.Message))
            {
                var error = parseNoMatchException(e, formulaName);
                return(new ErrorResult(formulaName, error, spreadsheetWorkbook.GetPresentation()));
            }

            return(new ErrorResult(formulaName, e.Message, spreadsheetWorkbook.GetPresentation()));
        }
예제 #2
0
        public ErrorResult EnrichError(SpreadsheetWorkbook spreadsheetWorkbook, Exception e)
        {
            var formulaName = spreadsheetWorkbook.GetFormulaName();

            var error = _errorValidators
                        .FirstOrDefault(ev => ev.Validate(e))
                        ?.ErrorMessage(e, formulaName)
                        ?? e.Message;

            return(new ErrorResult(formulaName, error, spreadsheetWorkbook.GetPresentation()));
        }
예제 #3
0
        public void ShouldReturnInvalidExpression()
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new ExpressionParseException("ExpressionParseException error");

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal("Invalid expression found in tax formula [" + worksheet.GetFormulaName() + "]. Check that separators and delimiters use the English locale.", actual.Message);
        }
        public void SampleTest()
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new Exception("Terrible problem");

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal("Fixme", actual.Message);
        }
예제 #5
0
        public void SimpleExceptionShouldReturnMessage(string message)
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new Exception(message);

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal(message, actual.Message);
        }
예제 #6
0
        public void ShouldReturnMissingFormula()
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new SpreadsheetException("Missing Formula", new List <string>()
            {
                "C1", "C2", "C3"
            }, "token");

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal($"Invalid expression found in tax formula [{worksheet.GetFormulaName()}]. Check for merged cells near {e.Cells}", actual.Message);
        }
예제 #7
0
        public void ShouldReturnCircularReference()
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new SpreadsheetException("Circular Reference xxx", new List <string>()
            {
                "C1", "C2", "C3"
            }, "token");

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal("Circular Reference in spreadsheet related to formula '" + worksheet.GetFormulaName() + "'. Cells: " + e.Cells, actual.Message);
        }
예제 #8
0
        public void SpreadsheetExceptionShouldReturnNoMatchesFound()
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var e = new SpreadsheetException("No matches found", new List <string>()
            {
                "C1", "C2", "C3"
            }, "token");

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal("No match found for token [" + e.Token + "] related to formula '" + worksheet.GetFormulaName() + "'.", actual.Message);
        }
예제 #9
0
        public void ShouldReturnMissingLookUpTable(string stack)
        {
            var enricher = new MessageEnricher();

            var worksheet = new SpreadsheetWorkbook();

            var mock = new Mock <Exception>();

            mock.Setup(ex => ex.Message).Returns("Object reference not set to an instance of an object");
            mock.Setup(ex => ex.StackTrace).Returns(stack);
            var e = mock.Object;

            var actual = enricher.EnrichError(worksheet, e);

            Assert.Equal("Missing Lookup Table", actual.Message);
        }