private void DoAddFormula(Formula f, IReference @ref)
    {
        bool sawException = false;

        try {
            MyFormulaEngine.AddFormula(f, @ref);
        } catch (Exception ex) {
            sawException = true;
        }

        Assert.IsTrue(sawException);
    }
    public void TestAddFormula()
    {
        // Null formula
        this.DoAddFormula(null, MyFormulaEngine.ReferenceFactory.Parse("a1"));
        Formula f = MyFormulaEngine.CreateFormula("1+1");

        // Null ref
        this.DoAddFormula(f, null);
        // Invalid references
        this.DoAddFormula(f, MyFormulaEngine.ReferenceFactory.Cells(2, 2, 4, 4));
        this.DoAddFormula(f, MyFormulaEngine.ReferenceFactory.Columns(3, 4));
        this.DoAddFormula(f, MyFormulaEngine.ReferenceFactory.Rows(5, 6));

        // Add with duplicate reference
        MyFormulaEngine.AddFormula(f, MyFormulaEngine.ReferenceFactory.Parse("A1"));
        this.DoAddFormula(f, MyFormulaEngine.ReferenceFactory.Parse("A1"));
    }