Class TestApi
Namespace: Casewhere.Runtime.DSL.Api
Assembly: Casewhere.Runtime.dll
public class TestApi : ITestApi, IDslApi, IDslContextualApi
Inheritance
Implements
ITestApi, IDslApi, IDslContextualApi
Inherited Members
object.ToString(), object.Equals(object), object.Equals(object, object), object.ReferenceEquals(object, object), object.GetHashCode(), object.GetType(), object.MemberwiseClone()
Extension Methods
ObjectExtension.ConvertToBsonValue(object), EnumExtensions.DeepClone<TestApi>(TestApi)
Constructors
TestApi(IWorkflowSimulator, IEnumerable<ITypeRandom>, IRegisterNameCache, IDataObjectApiService, IDataClassRepository, IDomainRepository, IPluginTestScenarioManager)
public TestApi(IWorkflowSimulator workflowSimulator, IEnumerable<ITypeRandom> typeRandoms, IRegisterNameCache registerNameCache, IDataObjectApiService dataObjectApiService, IDataClassRepository dataClassRepository, IDomainRepository domainRepository, IPluginTestScenarioManager pluginTestScenarioManager)
Parameters
workflowSimulator
IWorkflowSimulator
typeRandoms
IEnumerable<ITypeRandom>
registerNameCache
IRegisterNameCache
dataObjectApiService
IDataObjectApiService
dataClassRepository
IDataClassRepository
domainRepository
IDomainRepository
pluginTestScenarioManager
IPluginTestScenarioManager
Methods
CleanAll()
Clear all dummy data created while running the workflow unit test.
var testApi = ctx.Use<ITestApi>();
testApi.CleanAll();
public void CleanAll()
Create(string, string)
Create a Dummy Data Object and persist it to the database. The system will automatically clean up the data object after the test is finished
public string Create(string dataClassName, string registerName = null)
Parameters
dataClassName
string
The Data Class name.
registerName
string
Optional name of sharing data stored in memory.
Returns
The Id data object just created.
Examples
var testApi = ctx.Use<ITestApi>();
var doId = testApi.Create("TestSampleData");
Create(string, object, string)
Persist a Data Object in the database. The system will automatically clean up the data object after the test is finished.
public string Create(string dataClassName, object data, string registerName = null)
Parameters
dataClassName
string
Data Class name
data
object
Data Object to be added.
registerName
string
Optional name of sharing data stored in memory. If null, the data object will be added to the case of the workflow.
Returns
Id of the added Data Object.
Examples
var testApi = ctx.Use<ITestApi>();
var doId = testApi.Create("TestSampleData", new
{
Name = "Tester",
IsActive = true,
Level = 1
});
CreateDocumentUploadSession(Guid, string, string, string, int, string)
Create new document upload session with corresponding workflow, activity and document upload component name. This API is recommended to be called inside OnExecuting method.
public Guid CreateDocumentUploadSession(Guid documentId, string workflowName, string activityName, string componentName, int fileSize = 0, string fileName = "")
Parameters
documentId
Guid
Use IDocumentApi to create a DocumentInfo object.
workflowName
string
The workflow name.
activityName
string
The activity name.
componentName
string
The document upload component name.
fileSize
int
File size of document.
fileName
string
File name of document.
Returns
Return the document upload session ID if it excutes successfully.
False(bool, string)
Verifies that an expression is false.
var testApi = ctx.Use<ITestApi>();
var dataObject = new JObject() { { "Role", "Admin" }};
testApi.False(dataObject["Role"].ToObject<string>() == "Admin", "Role must contain admin");
public void False(bool condition, string reason)
Parameters
condition
bool
Logical condition expression.
reason
string
Error message.
Get<T>(string)
Get a dummy data object from the cache. This is useful for mocking data while writing a workflow unit test.
public T Get<T>(string registerName)
Parameters
registerName
string
Name used to register value will be cached
Returns
T
Return the data object.
Type Parameters
T
Type of the cached object.
Examples
var testApi = ctx.Use<ITestApi>();
int value = testApi.Get<int>("TestSampleData");
Get(string)
Get a dummy data object from the cache. This is useful for mocking data while writing a workflow unit test.
public DynamicDataObject Get(string registerName)
Parameters
registerName
string
Name used to register value will be cached
Returns
DynamicDataObject
Return the data object.
Examples
var testApi = ctx.Use<ITestApi>();
int value = testApi.Get("TestSampleData");
Get<T>(string, string)
Get value by name in a workflow.
public T Get<T>(string workflowName, string key)
Parameters
workflowName
string
The name of workflow.
key
string
The key.
Returns
T
Value in running workflow by type.
Type Parameters
T
The variable type.
Examples
var testApi = ctx.Use<ITestApi>();
testApi.Get< int >("SampleWorkflow", "IntValue")
Get(string, string)
Get value object by name in a workflow.
public DynamicDataObject Get(string workflowName, string key)
Parameters
workflowName
string
The workflow name.
key
string
The key.
Returns
DynamicDataObject
Value object by key in running workflow.
IsActivityCompleted(string, string)
Evaluate whether the activity is completed or not
var testApi = ctx.Use<ITestApi>();
testApi.IsActivityCompleted("workflowName", "activityName")
public bool IsActivityCompleted(string workflowName, string activityName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
Returns
Return true if the Activity is completed, otherwise, return false
IsActivityEditable(string, string)
Evaluate whether the activity is editable or not
var testApi = ctx.Use<ITestApi>();
testApi.IsActivityEditable("workflowName", "activityName")
public bool IsActivityEditable(string workflowName, string activityName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
Returns
Return true if the Activity is editable, otherwise, return false
IsActivityIncluded(string, string)
Evaluate whether the activity is included or not
var testApi = ctx.Use<ITestApi>();
testApi.IsActivityIncluded("workflowName", "activityName")
public bool IsActivityIncluded(string workflowName, string activityName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
Returns
Return true if the Activity is included, otherwise, return false
IsFormFieldEnabled(string, string, string)
Evaluate whether the form field is enable or not
var testApi = ctx.Use<ITestApi>();
testApi.IsFormFieldEnabled("workflowName", "activityName", "componentName")
public bool IsFormFieldEnabled(string workflowName, string activityName, string componentName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
componentName
string
Form Component Name
Returns
Return true if the form component is enabled, otherwise, return false
IsFormFieldReadonly(string, string, string)
Evaluate whether the form field is readonly or not
var testApi = ctx.Use<ITestApi>();
testApi.IsFormFieldReadonly("workflowName", "activityName", "componentName")
public bool IsFormFieldReadonly(string workflowName, string activityName, string componentName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
componentName
string
Form Component Name
Returns
Return true if the form component is readonly, otherwise, return false
IsFormFieldRequired(string, string, string)
Evaluate whether the form field is required or not
var testApi = ctx.Use<ITestApi>();
testApi.IsFormFieldRequired("workflowName", "activityName", "componentName")
public bool IsFormFieldRequired(string workflowName, string activityName, string componentName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
componentName
string
Form Component Name
Returns
Return true if the form component is required, otherwise, return false
IsFormFieldVisible(string, string, string)
Evaluate whether the form field is visible or not
var testApi = ctx.Use<ITestApi>();
testApi.IsFormFieldVisible("workflowName", "activityName", "componentName")
public bool IsFormFieldVisible(string workflowName, string activityName, string componentName)
Parameters
workflowName
string
Workflow Name
activityName
string
Activity Name
componentName
string
Form Component Name
Returns
Return true if the form component is visible, otherwise, return false
IsWorkflowCompleted(string)
Evaluate whether the workflow is completed or not
public bool IsWorkflowCompleted(string workflowName)
Parameters
workflowName
string
Workflow Name
Returns
Return true if the Workflow is completed, otherwise, return false
Examples
var testApi = ctx.Use<ITestApi>();
testApi.IsWorkflowCompleted("workflowName")
New<T>(string)
Generate value primitive data types and can be set to the cache
var testApi = ctx.Use<ITestApi>();
testApi.New<int>("TestSampleData");
public T New<T>(string registerName = null)
Parameters
registerName
string
Name used to register value will be cached.
Returns
T
Return a generic data object.
Type Parameters
T
Type of the cached object.
New(string, string)
Generate data class object and can be set to the cache
var testApi = ctx.Use<ITestApi>();
var data = testApi.New("TestSampleData");
public DynamicDataObject New(string dataClassName, string registerName = null)
Parameters
dataClassName
string
The Data Class name.
registerName
string
Optional name used to register value will be cached.
Returns
DynamicDataObject
Return a dynamic data object.
OnExecuted(string, string, Action)
Register an action to be invoked when the specific workflow executed.
public void OnExecuted(string workflowName, string activityName, Action action)
Parameters
workflowName
string
The workflow name.
activityName
string
The activity name.
action
Action
Invoke action.
OnExecuting(string, string, Action)
Register an action to be invoked when the specific workflow activity starts executing.
public void OnExecuting(string workflowName, string activityName, Action action)
Parameters
workflowName
string
The workflow name.
activityName
string
The activity name.
action
Action
Invoke action.
Ref(string, string)
Get the data object is being referenced in a workflow.
public DynamicDataObject Ref(string workflowName, string key)
Parameters
workflowName
string
The workflow name.
key
string
The reference key.
Returns
DynamicDataObject
Data object is being referenced in running workflow.
Replace(string, object)
Replace the value in the cache. This is useful for mocking data while writing a workflow unit test.
public void Replace(string registerName, object value)
Parameters
registerName
string
Name used to register value will be cached
value
object
An object value of replacing current value in cache
Examples
var testApi = ctx.Use<ITestApi>();
testApi.Replace("TestSampleData",1);
Set(string, object)
Set a dummy data object into the cache. This is useful for mocking data while writing a workflow unit test.
public void Set(string registerName, object value)
Parameters
registerName
string
Name used to register value will be cached
value
object
An object value stored in cache
Examples
var testApi = ctx.Use<ITestApi>();
testApi.Set("TestSampleData",1);
SetContext(WorkflowContext)
public void SetContext(WorkflowContext context)
Parameters
context
WorkflowContext
SimulatePluginInvocation(string, string)
Invoke a plugin method. This method cannot work with legacy plugins.
public PluginTestScenario SimulatePluginInvocation(string pluginName, string methodName)
Parameters
pluginName
string
Name of the plugin.
methodName
string
Invoked method name.
Returns
Return the PluginTestScenario object with predefined plugin result
Examples
var pluginResult = new PluginResult { Data = new Dictionary<string, object>() };
pluginResult.Data.Add("subject", "Test plugin on Dev env");
pluginResult.Data.Add("body", "Test plugin on Dev env");
var testApi = ctx.Use<ITestApi>();
testApi.SimulatePluginInvocation("CwMail", "SendEmail").Parameters(parms => parms["subject"].ToString() == "Test plugin on Dev env").Returns(pluginResult);
Submit(string, string, params FormSubmittedDataObject[])
Simulating form submission
public void Submit(string workflowName, string activityName, params FormSubmittedDataObject[] formSubmittedDataObjects)
Parameters
workflowName
string
Name of the simulated workflow
activityName
string
Name of the simulated activity
formSubmittedDataObjects
FormSubmittedDataObject[]
Submitted data
True(bool, string)
Verifies that an expression is true.
var testApi = ctx.Use<ITestApi>();
var dataObject = new JObject() { { "Role", "Admin" }};
testApi.True(dataObject["Role"].ToObject<string>() == "Admin", "Role must contain admin");
public void True(bool condition, string reason)
Parameters
condition
bool
Logical condition expression.
reason
string
Error message.