Category: Development
-
Mocking FunctionContext GetLogger using Durable Functions Isolated Worker
Although you can inject your ILogger<T> into the constructor of your function, sometimes you may want to use the FunctionContext from your trigger method. Mocking this for testing can be a bit tricky. Consider the following function: We want to write tests for our class. For this to be testable, we’ll need to somehow mock…
-
Using nginx to send webhooks to multiple upstreams
Forwarding webhook requests from a single endpoint, to multiple ‘upstream’ endpoints could be useful in many scenarios. A lot of applications that dispatch webhooks only allow one url, however, which can be a bit of a limitation. This pattern also simplifies maintenance. For instance, you can whitelist the relay IP while keeping your upstream endpoints…
-
Is user-agent a privacy concern?
Recently, I had a discussion with an e-commerce client about the implications of logging user-agents for their customers. Are there any privacy concerns involved? Can this data be used for anything other than identifying the browsers customers use to visit the site? And what about customers browsing in incognito mode – does the user-agent reveal…
-
Cosmos DB Change Feed Processed by Azure Functions – Application Insights Telemetry
While working with a Cosmos DB Change Feed processor running as an Azure Function, I noticed that ‘requests’ are logged as Application Insights telemetry, but show up with no URL, and a response Code of 0. I was able to reproduce this using a lean example, generated from the func new generators. (Code available here:…
-
‘No resources found’ error when publishing to Azure App Service using Visual Studio 2019
Yesterday, I tried to publish an app to Azure App Service from Visual Studio 2019 (right-click -> publish) (I know, I know… but I just wanted to try this feature out!) I had already set up my Linux App Service Plan (size B1) On clicking publish, and selecting “use existing” I was seeing a rather…
-
Amazon is blocking my VPN (which is hosted on AWS!)
I run a very simple OpenVPN server in an Amazon Lightsail VM. This is to provide me with a ’static’ IP address, I can whitelist for access to some services. However, recently, I’ve noticed Amazon (.co.uk) has been blocking me from using the shopping site when connected to my VPN. I will get the following…
-
NSwag build error – Project file does not exist / Unable to retrieve project metadata
While working on a project that used NSwag, when the solution was built, Visual Studio (and dotnet build from the command line) reported the following error: View the code on Gist. Pretty frustrating, as it wasn’t clear what the error meant. This project used NSwag.MSBuild to generate the client on build. As per their documentation,…
-
Opening first few lines of a huge file with VS Code
I’m currently doing some work looking at the GeoNames dataset. `allCountries.txt` is around 1.5gb, which is pretty large, and certainly too large to open up in vscode for a quick look. However, I found I could use `head` command, which reads the first n lines of a file, and pipe the output to `code -`…
-
Using Google Sheets and Azure Functions as a headless CMS
One of my clients came to me with a relatively simple requirement; they needed to take online payments for their fitness event photography business. The model is quite simple: There are several different competition dates per year. Competitors can purchase professional photos of themselves at a competition. Each competitor will have a ‘badge number’ to…
-
Using Mediatr with Azure Functions
I’ve used Mediatr for some time, to reduce controller action bloat, and have spoken about it a few times, on how I use it to avoid the classic ‘xService’ pattern: Controller Action -> ‘Service’ -> Repo Lately, I’ve been doing a lot of work with Azure Functions, and would like to be able to use…
-
Reliably Processing Azure Service Bus Topics with Azure Functions
At ASOS, we’re currently migrating some of our message and event processing applications from Worker Roles (within classic Azure Cloud Services) to Azure Functions. A significant benefit of using Azure Functions to process our messages is the billing model. As an example, with our current approach, we use a Worker Role to listen to subscriptions…
-
Disable gzip responses in Azure Functions
By default, responses from Http Triggered Azure Functions are gzipped: Not all clients are able to handle this (although they should be) Turning it off isn’t particularly trivial. A change needs to be made to applicationhost.config – which is located in LocalSiteRoot/Config However, this file is readonly, so the change needs to be made via…
-
Better assertions when verifying Moq’d methods have been called
Moq, according to its GitHub page, is “The most popular and friendly mocking framework for .NET”. Mocking frameworks allow you to create a ‘fake’ version of a dependency (typically an interface, or abstract class). With this fake, you can then instruct the methods return values, or invoke behaviour. Alternatively you can assert the methods were called,…
-
Reversing hashes of PwnedPasswords api using number of breaches
I was recently working on a requirement to log the number of breached sites a password appeared on when customers were registering (if that password had been breached at all) Importantly, we are not logging the breached password itself (nor the hash of the password) – just the number of breaches that particular password appeared in…
-
Hide Sensitive Data with Application Insights JavaScript SDK using a Telemetry Initializer
Application Insights is incredibly powerful, especially when using the JavaScript Client SDK. The problem is, sometimes we can be logging a little too much. We can use a Telemetry Initalizer to hide sensitive data in dependencies / requests logged with Application Insights.
-
Quickly add GSuite (Google Apps) MX Records to CloudFlare DNS
As some people know, I run a web development agency called Cohoda LTD. As part of our service, like most development agencies, we offer web hosting. To keep things as lean as possible, we deliberately don’t try to host email servers ourselves, instead we set up clients with email on Google GSuite (or Office 365…
-
Search git branch names using command line
Looking for a particular branch, and `git branch -a` returns a LOT of branches? If on Windows, you could use the Search feature in cmder (you’re using cmder, right?) Or on mac, cmd+f and then search the outputted text… OR you could use one of these two approaches: 1) git branch takes a `–list` argument , which in…
-
Adding additional colour themes to Jetbrains Rider
color-themes.com according to it’s description, offers “Color themes for IntelliJ IDEA, Webstorm, PyCharm, RubyMine, PhpStorm and AppCode” However, it turns out that these themes also work with Rider. After downloading it (it’s a .jar file) go to File > Import Settings Choose the downloaded .jar file, and it will import the colour theme. Once Rider…
-
An Introduction to the LEDS Stack
Full blog post is coming soon. For now, please see GitHub repository for demo project: https://github.com/alexjamesbrown/LEDS_Stack Talk slides at: http://bit.ly/leds_stack_slides
-
Azure function not receiving json messages using Topic Service Bus Trigger
While developing an Azure Function application, using this tutorial, I encountered a problem. Ultimately, using `func new` generated my function (the run.csx file) which looked like this: public static void Run(string mySbMsg, TraceWriter log) { log.Info($”C# ServiceBus topic trigger function processed message: {mySbMsg}”); } Side note: the `mySbMsg` is important – it’s defined in the…
-
Asserting multiple properties of argument with FakeItEasy
More often than not, I want to assert that my dependency has been called with a parameter that matches more than one condition. Let’s say we have a method that calls ICustomerService.Add method. We want to assert the Add method was called with a Customer that matches a few conditions. The way we’d typically achieve…
-
Physical 419 Letter Received
Last night I opened an innocuous looking letter delivered to my home address. It had a ‘commercial’ postage stamp on it (not one that you’d pick up in the post office) and it wasn’t addressed to anybody on the envelope. The content of the letter was what I’d expect to get via email – a…
-
Microsoft SQL Server on a Ubuntu Linux VM
As part of a blog post on the LEDS stack (Linux Nginx Dotnet, SQL Server) I’m putting together, I wanted to see how easy it is to install SQL Server on a Ubuntu VM, running on Digital Ocean. Turns out, very easy. I went with a Ubuntu 16.04.2 x64 box, with 4GB of RAM The…
-
Using different themes across Visual Studio versions
I’m currently working on a couple of solutions – one that is Visual Studio 2017 specific, one 2015. Primarily because the 2017 specific one is full of .net standard projects, and the support is better (or at least, built in) I wanted to have 2015 use a different theme – I’m only doing small bits…
-
Out Of Memory exception when deserializing with JSON.net – Use Streams instead
Calling an api and deserializing the returned json into a type is something I have to do quite often. I used to use the following: //assume client is an instance of HttpClient – this part isn’t important var response = await client.PostAsync(url, content); //read the response as a string var responseString = await response.Content.ReadAsStringAsync(); //use…