I'm trying to test my WF4 State Machine workflow. A few of the transitions are triggered by Receive activities and, based on the data in the message, make the the appropriate transition. Right now I'm using the WorkflowApplicationTest to run my tests, but am only able to test my timeout pathing, since any other transitions are triggered by this receive. I've looked at using the XamlInjector to mock the Receive, but it looks like it only works with custom activities. I also tried making a custom Receive activity so that I could mock that, but couldn't figure out everything I needed to do to make my custom receive work or find any info on creating custom Receive activities.
Is there a simple solution that I am overlooking on how to test this? And if a custom Receive is the only way to be able to use the XamlInjector, how do I write one?
I am using the Visual Studio test framework for my unit tests.
I've got just the thing for you. See How do I Mock Receive and Send activities?
Related
I have an Azure Function which is triggered by an Azure Service Bus Queue.
The function is below.
How this Run method can be unit tested?
And how an integration test can be done by starting with AddContact trigger, checking the logic in the method and the data being sent to a blob using the output binding?
public static class AddContactFunction
{
[FunctionName("AddContactFunction")]
public static void Run([ServiceBusTrigger("AddContact", Connection = "AddContactFunctionConnectionString")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
}
I had the exact same doubts.
Adding Unit Tests is not too complicated, at the end of the day, its a function, so all we got to do is to call the Azure Function with the correct string, for parameter string myQueueItem.
Adding Integration tests needs some additional ground work. In the Github project, the author uses the TestFunctionHost class from Azure/azure-functions-host project.
I tried following this strategy, but the amount of code needed to setup all these is uncomfortably high for my liking. Not a lot of it is well documented, and some of the stuff needs developers to use Azure App Services myGet feed.
I wanted a simpler approach, and thankfully I found one.
Azure Functions is built on top of the Azure WebJobs SDK package, and leverages its JobHost class to run. So in our integration tests, all we need to do, is to setup this Host, and tell it where to look for the Azure Functions to load and run.
IHost host = new HostBuilder()
.ConfigureWebJobs()
.ConfigureDefaultTestHost<CLASS_CONTAINING_THE_AZURE_FUNCTIONS>(webjobsBuilder => {
webjobsBuilder.AddAzureStorage();
webjobsBuilder.AddServiceBus();
})
.ConfigureServices(services => {
services.AddSingleton<INameResolver>(resolver);
})
.Build();
using (host) {
await host.StartAsync();
// ..
}
...
Once this is done, we can send messages to ServiceBus and our Azure Functions will get triggered. Once can even set breakpoints in the Functions getting tested and debug issues!
I have blogged about the whole process here and I have also created a github repository at this link, to showcase test driven development with Azure Functions.
How this Run method can be unit tested?
The method is a static public method. You can unit test it by invoking the static method AddContactFunction.Run(/* parameters /*); You will not need a Service Bus namespace or a message for that matter as your function expects to receive a string from the SDK. Which you can provide and verify the logic works as expected.
And how an integration test can be done by starting with AddContact trigger, checking the logic in the method and the data being sent to a blob using the output binding?
This would be a much more sophisticated scenario. This would require to run Functions runtime and generate a real Service Bus message to trigger the functions as well as validate that the blob was written. There's no integration/end-to-end testing framework that is shipped with Functions and you'd need to come up with something custom. Azure Functions Core Tools could be helpful to achieve that.
I have a test collection with hundreds of tests.
I'd like to send the test result as an SMS message on my phone.
I have all the other parts working but is there any way to get a count of passed and failed tests as a variable for my last test which is testing our SMS service, so I could get the result to my phone as an SMS message.
I only need to get a count of failed and count of passed cases during the collection run.
But if it is possible to get the name(s) of the failed cases as well, then I would be fully satisfied.
-Jarno Storhammar-
You could try creating a node script with Newman and sending the results captured in the summary.run.stats object to an external API, that would send you an SMS message with the details you want. Services like Twilio could handle that part.
It's not something the native Postman app would perform out of the box but I'm sure it can be done.
I'd like to ask whether it's possible to implement publish/subscribe pattern (http://getakka.net/articles/clustering/distributed-publish-subscribe.html) where subscriber is an AtLeastOnceDeliveryReceiveActor (http://getakka.net/articles/persistence/at-least-once-delivery.html)
I cannot make it working due to fact that AtLeastOnceDeliveryReceiveActor doesn't have Receive method, but just Command. When I get reference to an actor and using Tell method send a message then Command receive it, but if I'd like to use mediator with Publish method then Command doesn't receive that message.
Thanks in advance.
ReceivePersistentActor's Command works just like Receive handler (the only distinction is acknowledgement of persistence/recovery lifecycle of an actor). That being said, you could potentially build an at-least-once-delivery publish/subscribe bus... however I'd advise to simply integrate your actors logic with an existing persistent queue/log (like Kafka, RabbitMQ, Azure Service Bus, whatever) instead of trying to recreate it in Akka. I guess it will be less painful for most of the people.
I have an app we have connected to Pubnub for a live socket service to keep data on the page fresh for the user.
I have an ajax call that will do something with our API, and when it is successful I call an action on the application controller. At or around the same time, as long as Pubnub is still connected it receives a message with the action handler name and it attempts to call the same action.
Ideally I want to make sure this code only runs once weather it was first called by Pubnub or by my ajax success callback. How can I do this maybe using the ember run loop? It seems viable here I'm just not able to wrap my head around how I would actually do this.
Well, I would only use the web socket.
But for your question:
There is not build-in functionality in the runloop to do that. You will need some kind of uniq message id, and then have a list of processed messages and check there before you run your code.
We have a BizTalk application which sends XML files to external applications by using a web-service.
BizTalk calls the web-services method by passing XML file and destination application URL as parameters.
If the external applications are not able to receive the XML, or if there is no response received from the web-service back to BizTalk the message gets suspended in BizTalk.
Presently for this situation we manually go to BizTalk admin and resume each suspended message.
Our clients want this process to be automated all, they want an dashboard which shows list of message details and a button, on its click all the suspended messages have to be resumed.
If you are doing this within an orchestration and catching the connection error, just add a delay shape configured to 5 hours. Or set a retry interval to 300 minutes and multiple retries on the send port if that makes sense. You can do this using the rule engine as well.
Why not implement an asynchronous pattern?
You make it so, so that the orchestration sends the file out via a send shape while initializing a certain correlation set.
You then put a listen shape with at one end:
- the receive (following the initialized correlation set)
- a delay shape set to 5 hours.
When you receive the message, your orchestration can handle it gracefully.
When you don't, the delay shape will kick in and you handle accordingly.
Benefit to this solution in comparison to the solution of 40Alpha will be that your orchestration will only 'wake up' from a dehydrated state if the timeout kicks in OR when the response is received. In the example of 40Alpha, the orchestration would wake up a lot of times, consuming extra resources.
You may want to look a product like BizTalk 360. It has those sort of monitoring and command built into it. I'm not sure it works with BizTalk 2006R2 though, but you should be thinking about moving off that platform anyway as it is going out of Microsoft support.