--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/3f8aee5c-ba2f-40bb-a19d-9c5bfc3fba09n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/CABCjBXNi3%2Bv3Kg3%3D_x24vkTZZ664OyBEb_M_A7G%3DS4dQaovZpA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/CA%2BErqHkCPtv0VQ35x4s6QoZwTQ0Th%2BrpDJ%2Bzq9%2BN49FnNHDG%2Bg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/CAFW6U-rd5wFnCGnUoO3MdLqS3cVhsWXAG%2BbhSjspB2jZZo9wWg%40mail.gmail.com.
Umer,
It is possible with ExcelDna.Testing to open an excel template, click the ribbon button and then after plugin update the sheet run asserts.
I've created a sample solution (attached) that demonstrates it.
The main ribbon code is:
public void OnButtonPressed(IRibbonControl control)
{
Application app = (Application)ExcelDnaUtil.Application;
var ws = app.ActiveSheet;
ws.Range["A3"].Value = 22;
}
public void OnButtonAsyncPressed(IRibbonControl control)
{
Application app = (Application)ExcelDnaUtil.Application;
var ws = app.ActiveSheet;
ExcelAsyncUtil.QueueAsMacro(async () =>
{
await Task.Delay(2000);
ws.Range["A4"].Value = 33;
});
}
And testing code is:
using ExcelDna.Testing;
using Xunit;
[assembly: Xunit.TestFramework("Xunit.ExcelTestFramework", "ExcelDna.Testing")]
namespace MyAddIn.Test
{
[ExcelTestSettings(AddIn = @"..\..\..\MyAddIn\bin\Debug\MyAddIn-AddIn", Workbook = "Book.xlsx")]
public class Tests
{
[ExcelFact]
public void WorkbookData()
{
var ws = Util.Workbook.Sheets[1];
Assert.Equal(3, ws.Range["A2"].Value);
}
[ExcelFact]
public void Ribbon()
{
Automation.ClickRibbonButton("ExampleAddin", "My Button");
var ws = Util.Workbook.Sheets[1];
Assert.Equal(22, ws.Range["A3"].Value);
}
[ExcelFact]
public void RibbonAsync()
{
Automation.ClickRibbonButton("ExampleAddin", "My Button Async");
var ws = Util.Workbook.Sheets[1];
Automation.WaitFor(() => ws.Range["A4"].Value == 33, 3000);
Assert.Equal(33, ws.Range["A4"].Value);
}
}
}
On my machine it works both in VS 2019 and VS 2022.
When testing the extracted solution code from .zip I saw an error about xunit.runner.utility similar to yours (though for me it was for v452). It required to restart VS and rebuild to fix this problem. I assume it relates to packages restore.
Please try the attached solution on your machine.