Book Image

Azure Serverless Computing Cookbook - Third Edition

By : Praveen Kumar Sreeram
Book Image

Azure Serverless Computing Cookbook - Third Edition

By: Praveen Kumar Sreeram

Overview of this book

This third edition of Azure Serverless Computing Cookbook guides you through the development of a basic back-end web API that performs simple operations, helping you understand how to persist data in Azure Storage services. You'll cover the integration of Azure Functions with other cloud services, such as notifications (SendGrid and Twilio), Cognitive Services (computer vision), and Logic Apps, to build simple workflow-based applications. With the help of this book, you'll be able to leverage Visual Studio tools to develop, build, test, and deploy Azure functions quickly. It also covers a variety of tools and methods for testing the functionality of Azure functions locally in the developer's workstation and in the cloud environment. Once you're familiar with the core features, you'll explore advanced concepts such as durable functions, starting with a "hello world" example, and learn about the scalable bulk upload use case, which uses durable function patterns, function chaining, and fan-out/fan-in. By the end of this Azure book, you'll have gained the knowledge and practical experience needed to be able to create and deploy Azure applications on serverless architectures efficiently.
Table of Contents (14 chapters)
13
Index

Developing unit tests for Azure functions with HTTP triggers

So far, we have created multiple Azure functions and validated their functionality using different tools. The functions that we have developed here have been straightforward but, in your real-world applications, it may not be that simple as there will likely be many changes to the code that was initially created. It's good practice to write automated unit tests that help test the functionality of our Azure functions. Every time you run these automated unit tests, you can test all the various paths within the code.

In this recipe, we'll learn how to use the basic HTTP trigger and see how easy it is to write automated unit test cases for this using Visual Studio Test Explorer and Moq (an open-source framework available as a NuGet package).

Getting ready

We'll be using the Moq mocking framework and xunit to develop automated unit test cases for our Azure function. Having a basic working knowledge of Moq...