Unit Testing Framework
This page provides instruction on Unit Testing your C# / .NET SanteDB Plugins
Install SanteDB Server TestFramework
Because many core SanteDB components (including your service implementations) will need to be registered with a SanteDB host context, you must first establish an application context. SanteDB provides tools for quickly establishing a TestApplicationContext however this requires installation of the nuget package:
Setting up the TestApplicationContext
The TestApplicationContext should be initialized in a common place. Below provides an example of a TestClass which initializes a TestApplicationContext.
You will also need to create an embedded resource in your test assembly named TestConfig.xml which contains the configuration you wish to use for your test:
Use the SolutionExplorer and Properties window to set the Build Action to Embedded Resource and ensure that your TestConfig.xml is placed in the root of your test assembly project.
Unit Tests for Data Services
If your unit test requires accessing or interacting with the SanteDB data store or repository services, you should register the required persistence classes in your TestConfig.xml and inherit from DataTest.
Execution Environment
If you're using the data persistence services, you will need to ensure that the Visual Studio test runner (or the NUnit tool) is running in x64 mode. In Visual Studio, this requires selecting Test -> Processor Architecture -> x64.
Last updated