DI and ExcelDNA.Testing #590
schebotar
started this conversation in
Show and tell
Replies: 1 comment
-
hi @schebotar
public sealed class TestContext : IDisposable
{
public Application ExcelApp { get; private set; }
public Workbook CurrentBook => ExcelApp?.ActiveWorkbook;
public Worksheet CurrentSheet => (Worksheet)CurrentBook?.ActiveSheet;
public Range CurrentCell => ExcelApp?.ActiveCell;
public TestContext()
{
// Create and launch an excel instance
ExcelApp = new Application();
ExcelApp.Visible = true;
ExcelApp.Workbooks.Add();
// Active or add your addin to excel
_yourAddIn = ExcelApp.AddIns.Cast<AddIn>().FirstOrDefault(p => p.FullName.Equals(AddInDir));
if (_dogsAddIn == null)
{
_yourAddIn = ExcelApp.AddIns.Add(AddInDir, true);
}
Thread.Sleep(TimeSpan.FromSeconds(2));
_yourAddIn .Installed = false;
Thread.Sleep(TimeSpan.FromSeconds(1));
_yourAddIn .Installed = true;
Assert.NotNull(_yourAddIn );
Assert.True(_yourAddIn .Installed, "Add-in Install failure!");
}
// .... other methods
}
public class YourClassName: IClassFixture<TestContext>
{
private readonly TestContext _context;
public OptionsTest(TestContext context)
{
_context = context;
}
// .... your other test case methods
} and then you can use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.
I'm working on pet-project Excel add-in.
I implemented DI like this
IExcelReader implementation have to found some patterns (Products) on worksheet or in range and count them.
All seems working in standard way.
Now I'm trying to test this project with ExcelDNA.Testing
Looks like XUnit is kinda restricted in injections. I found the way to get it worked, but it looks not good and I have a feeling there is better way.
Any tips on this?
Beta Was this translation helpful? Give feedback.
All reactions