Files
ClosedXML/ClosedXML_Tests/Excel/CalcEngine/CalcEngineExceptionTests.cs
T
Thom Lamb 2cd6df6481 Initial commit of the ClosedXML library
Establishes the foundational structure, core Excel functionality, and tooling.

- Implements base components for cells, ranges, columns, and rows.
- Integrates a custom calculation engine with a wide range of Excel functions.
- Adds comprehensive support for styling, conditional formatting, data validation, comments, pictures, and charts.
- Configures build setup, project metadata (NuGet), and developer guidelines.
- Includes editor and Git attributes for consistent code style and line endings.
2026-06-23 11:02:53 -05:00

57 lines
1.8 KiB
C#

using ClosedXML.Excel;
using ClosedXML.Excel.CalcEngine.Exceptions;
using NUnit.Framework;
using System;
using System.Globalization;
using System.Threading;
namespace ClosedXML_Tests.Excel.CalcEngine
{
[TestFixture]
public class CalcEngineExceptionTests
{
[OneTimeSetUp]
public void SetCultureInfo()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
}
[Test]
public void InvalidCharNumber()
{
Assert.Throws<CellValueException>(() => XLWorkbook.EvaluateExpr("CHAR(-2)"));
Assert.Throws<CellValueException>(() => XLWorkbook.EvaluateExpr("CHAR(270)"));
}
[Test]
public void DivisionByZero()
{
Assert.Throws<DivisionByZeroException>(() => XLWorkbook.EvaluateExpr("0/0"));
Assert.Throws<DivisionByZeroException>(() => new XLWorkbook().AddWorksheet().Evaluate("0/0"));
}
[Test]
public void InvalidFunction()
{
Exception ex;
ex = Assert.Throws<NameNotRecognizedException>(() => XLWorkbook.EvaluateExpr("XXX(A1:A2)"));
Assert.That(ex.Message, Is.EqualTo("The identifier `XXX` was not recognised."));
var ws = new XLWorkbook().AddWorksheet();
ex = Assert.Throws<NameNotRecognizedException>(() => ws.Evaluate("XXX(A1:A2)"));
Assert.That(ex.Message, Is.EqualTo("The identifier `XXX` was not recognised."));
}
[Test]
public void NestedNameNotRecognizedException()
{
using var wb = new XLWorkbook();
var ws = wb.AddWorksheet();
ws.Cell("A1").SetFormulaA1("=XXX");
ws.Cell("A2").SetFormulaA1(@"=IFERROR(A1, ""Success"")");
Assert.AreEqual("Success", ws.Cell("A2").Value);
}
}
}