Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit cd87db0

Browse files
mbraekmantomkerkhovestijnmoreels
authored
Write a blog post about the test framework (#56)
Blog post. Related to #32. Co-authored-by: Tom Kerkhove <kerkhove.tom@gmail.com> Co-authored-by: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
1 parent 57ed627 commit cd87db0

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Announcing the Invictus Test Framework for Azure Logic Apps
2+
--
3+
>While writing unit or integration tests should be part of every project, this proofs to be quite difficult whenever creating integration scenarios using Azure Logic Apps.
4+
>Thanks to the creation of the Invictus Test Framework for Azure Logic Apps, there is no longer any excuse not to write any test-cases.
5+
6+
Up until now, when building interfaces on top of Azure Logic Apps, you were forced to manually (re)test every implemented feature because there simply wasn't anything available to help you on your way.
7+
8+
While this approach works fine, we've found that it has a few flaws:
9+
- New people on your team don't have an easy way to understand how flows should work
10+
- It's cumbersome since you cannot easily automate it to guarantee quality
11+
- It takes time & effort which ends up in a higher engineering & testing cost, money you'd like to spend elsewhere
12+
13+
Since developing the Invictus Methodology, which includes patterns, best practices and several templates, Codit has been investing in building a solid foundation enabling us to quickly kick-off new projects, while ensuring a high level of quality. The biggest thing which, until now, was still lacking, was the ability to include test-cases into those projects.
14+
Because of this, we started working on a framework that allowed us to easily enable/disable, trigger and even modify existing Azure Logic Apps. But, since the operations are not enough to write full-blown test-scenarios, we extended this list to ensure you would also be able to monitor the executed Azure Logic App runs.
15+
16+
All these operations have now been forged into the Invictus Test Framework for Azure Logic Apps which we used internally for our customers and have proven to be effective.
17+
Today, **we are happy to announce that we are open-sourcing Invictus Test Framework for Azure Logic Apps on GitHub** and it is now available on NuGet for you to use on your projects!
18+
19+
Get started very easily :
20+
```shell
21+
> Install-Package Invictus.Testing.LogicApps
22+
```
23+
24+
### Authentication
25+
When you want to use this package to track of control your Logic Apps, you will have to authenticate against your Azure subscription containing said Logic Apps of course.
26+
As of today, we provide support for using service principal authentication! Our framework requires to have at least [*Logic App Contributor*](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#logic-app-contributor) which gives enough permissions to do our magic.
27+
28+
Of course, you can re-use existing service principals that you already have in Azure DevOps for example. However, seeing as this service principal typically has contributor-access to the entire subscription, which is quite an overkill for testing-purposes, it would be advised to create a new service principal, entirely dedicated to the testing scenarios.
29+
30+
But what exactly do you need to specify in order to really authenticate?
31+
Well, below is an overview of the required information:
32+
33+
```csharp
34+
// The Tenant ID of the Azure AD
35+
string tenantId = "my-tenant-id";
36+
// The ID of the subscription containing your Azure Logic App.
37+
string subscriptionId = "my-subscription-id";
38+
// The application id of the service principal to be used to authenticate.
39+
string clientId = "my-client-id";
40+
// The client secret created along with the service principal used for authentication.
41+
// You might want to look at Arcus Security to ensure this value can be stored in Azure Key Vault instead
42+
string clientSecret = "my-client-secret";
43+
44+
// Use the LogicAppAuthentication-class to retrieve the required access token.
45+
var authentication = LogicAppAuthentication.UsingServicePrincipal(tenantId, subscriptionId, clientId, clientSecret);
46+
```
47+
48+
*Read more about how to authenticate and gain access to your Logic Apps in [our documentation](https://invictus-integration.github.io/testing-framework/#/logic-apps/authentication).*
49+
50+
### Controlling an Azure Logic App
51+
52+
One of the key aspects of our framework is the ability to have control over every single Azure Logic App that is part of your interface. This can be done by only specifying the name of the resource group and the Azure Logic App itself.
53+
54+
Once authenticated, you can perform any of the following operations:
55+
- Get the Logic App metadata
56+
- Get the Logic App trigger-URL
57+
- (Temporarily) enable the Logic App
58+
- (Temporarily) update the Logic App definition
59+
- (Temporarily) enable static results on specific actions within the Logic App
60+
- Trigger a Logic App run
61+
- Cancel a Logic App run
62+
- Delete a Logic App
63+
64+
All of these features provide you the possibility to adjust and trigger your Azure Logic Apps to allow for a specific scenario to be tested.
65+
66+
As you don't want your unit/integration test related Logic App to inflict costs while not being used, here is an example of how you can temporarily enable an Azure Logic App during your test:
67+
```csharp
68+
using (var logicApp = await LogicAppClient.CreateAsync(resourceGroup, logicAppName, authentication))
69+
{
70+
// Any action to be performed before enabling the Logic App.
71+
await using (await logicApp.TemporaryEnableAsync())
72+
{
73+
// Perform actions related to your test-case, while the Logic App is enabled.
74+
}
75+
// Any action to be performed after disabling the Logic App.
76+
}
77+
```
78+
79+
*Read more about how to control an Azure Logic App in [our documentation](https://invictus-integration.github.io/testing-framework/#/logic-apps/control-single-logicapp).*
80+
81+
### Monitoring an Azure Logic App
82+
83+
After preparing & triggering the interface to match your test scenario, it is important to be able to retrieve enough information to verify the outcome of the test.
84+
To accommodate this, we provide a fluent way of describing what you are looking for allowing you to:
85+
- Get an Azure Logic App run by its correlation ID (aka *client tracking ID*)
86+
- Get an Azure Logic App run by one or more tracked properties
87+
- Get an Azure Logic App run within a specific time frame
88+
- Get a list of Azure Logic App runs within a specific time frame
89+
- Get a given number of completed Azure Logic App runs (polling) which can be success or failed.
90+
*In case you have the same Logic App running multiple times in parallel.*
91+
92+
Every Azure Logic App run provides information about all metadata of the run itself such the status, what triggered it, start/end time, correlation, information & tracked properties for every single action and more!
93+
94+
To give you an idea of how you can use our framework to monitor Logic App runs, let's take a look!
95+
In this first example, we will be polling for a single run that contains the specified correlation id and give up after 15 seconds:
96+
```csharp
97+
LogicAppRun logicAppRun =
98+
await LogicAppsProvider.LocatedAt(resourceGroup, logicAppName, authentication)
99+
.WithTimeout(TimeSpan.FromSeconds(15))
100+
.WithCorrelationId("08586073923413753771945113291CU110")
101+
.PollForSingleLogicAppRunAsync();
102+
```
103+
If the framework was unable to find a run within the specific time frame, a `TimeOutException` will be thrown.
104+
105+
In this last example, we are expecting to find 3 Azure Logic Apps runs who have _OrderNumber_ as a tracked property where we expect `123456` as its value.
106+
To achieve this, we will be checking for 60 seconds and move on if we couldn't find them.
107+
```csharp
108+
IEnumerable<LogicAppRun> logicAppRuns =
109+
await LogicAppsProvider.LocatedAt(resourceGroup, logicAppName, authentication)
110+
.WithTimeout(TimeSpan.FromSeconds(60))
111+
.WithTrackedProperty("OrderNumber", "123456")
112+
.PollForLogicAppRunsAsync(minimumNumberOfItems: 3);
113+
```
114+
As was the case when looking for a single run, a `TimeOutException` will be thrown if the framework was unable to find the requested number of runs within the allotted time frame.
115+
116+
117+
*Read more about how to monitor an Azure Logic App in [our documentation](https://invictus-integration.github.io/testing-framework/#/logic-apps/polling-logicapp-runs).*
118+
119+
120+
# Conclusion
121+
We are happy to help the Azure Logic Apps community to build automated test suits on top of Azure Logic Apps! We welcome everybody to add feature requests [on GitHub](https://github.com/invictus-integration/testing-framework/) and accept contributions to make the framework even better!

0 commit comments

Comments
 (0)