Integration testing MongoDB with C# – More Fluent Syntax


This is similar to my post around Azure Storage Integration testing just with a mongo twist. I’ve been working with mongo and didn’t really like the debugging workflow: Do something, start mongovue and manually check the item changed in the way you thought it would.

I’ve written a set of extensions to allow a nice set of declarative fluent assertions about the state of the MongoDB after an action has been performed.

 .AssertCollectionHasItemWithProperty<ExampleType>(item, x => x.MyProperty == 1);

Alongside this I’ve used an awesome nuget package from the guys at FireFunnel, which lets me spin up and work with an embedded Mongodb instance. I’ve written some simple methods to spin up the embedded instance and clean it in-between tests like so:

 public class ExampleTestClass
  private static EmbeddedMongoDbServer mongoEmbedded;
  private static MongoClient mongoClient;
  private static MongoServer mongoServer;

 public static void StartMongoEmbedded(TestContext cont)
   mongoEmbedded = new EmbeddedMongoDbServer();
   mongoClient = mongoEmbedded.Client;
   mongoServer = mongoClient.GetServer();

 public static void ShutdownMongo()

 public void CleanMongo()
   var databases = mongoServer.GetDatabaseNames();
   foreach (var databaseName in databases)


Then I’ve also tweaked the extensions methods to give some nice actionable feedback when a test fails. For example when you create a query this is captured as an expression that is shown in the test output so you know exactly what query ran and can go about fixing it.

The source is up on Github, here. Let me know how you get on!


fluentMongo FluentMongoOutput

Integration testing azure storage – Fluent syntax


I recently set about writing a solution that’s heavily reliant on Azure Blob storage. I found my debugging cycle wasn’t nice, I’d spin up the code then spend ages in Azure Storage Explorer to work out what had happened. I also new I’d want some integration tests for the future.

So I did some research set about writing a quick set of helpers to allow me to write clean, quick and simple tests that worked in VS Test explorer.

The result is FluentAzureBlobTesting, this allows me to write lovely declarative statements like this:

                .AssertBlobContainsMetaData(expectedMetaDataKey, expectedMetaDataValue)
It also handles the starting, stopping and clearing of the storage emulator so all you have to do is click “Run All” and it handles the rest. *Dependency on Azure 2.3 SDK
        private static CloudStorageAccount account;
        private static CloudBlobClient blobClient;

        public static void StartAndCleanStorage(TestContext cont)
            account = CloudStorageAccount.DevelopmentStorageAccount;
            blobClient = account.CreateCloudBlobClient();

        public static void ShutdownStorage()

        public void CleanAndRestartStorage()
Should the test fail the extensions report back the reason for failures and log trace output on success.
FailedTest PassingTestWithTrace
Now my debugging cycle is nice a quick and I’m writing a good set of unit tests as I go.
The source is available on github here, hopefully useful to you!
Thanks to Rory for the starting point here:

Capture HTTP traffic with Fiddler on Devices with no Proxy option


This is how I ended up writing a custom DNS server to redirect network traffic.. code is here.

I recently got a smart TV and I wanted to see what it was up too, having heard all the stories of them leaking personal information left right and center.

Fiddler is my go to tool for any HTTP inspection, so I went about look for a proxy setting in on the TV … there isn’t one.

To get around this I started pondering and came up with a plan to write my own DNS server in C# which would respond to the TV with the IP address of my machine. On that machine I’d configure Fiddler to run on port 80 and allow remote clients. The upshot of this would be that all traffic from the TV would hit the Fiddler proxy, I would inspect it, then it would get forwarded on to the the internet as normal.

Having a search around I found this nuget package, ARSoft.Tools.Net, from ARSoft which gives me the basics of a DNS server. I then hacked together a bit of code to setup the DNS server to respond as I’d like and bound it up to the correct IPs.

The net result was I could now look at *some* of the traffic. The downside is that a lot of apps would break as the HTTPS connections are being forwarded but my machine, and fiddler, but the machine isn’t listening or forwarding port 443.

I had a couple of attempts at getting around this, you can see TCPForwarderSlim and PortForwardingWrapper, thanks to Bruno Garcia, in the code. This would setup a straight forward on 443 when a DNS request would come through but it wasn’t too reliable. I also playing with using fiddlerCore to listen on a number of ports at the same time but this lead to certificate errors in the apps on the TV as the certs it generated where self signed.

Either way it almost worked, screenshots below, I’ve put the code up on GitHub for anyone who wants to have a play!

Go a rough idea of some of the stuff my TV gets up to…

For example: If you want the TV version of BBC IPlayer set you’re UserAgent string to the below and hit

Mozilla/5.0 (DirectFB; Linux armv7l) AppleWebKit/534.26+ (KHTML, like Gecko) Version/5.0 Safari/534.26+ LG Browser/5.00.00(+mouse+SCREEN+TUNER; LGE; 42LS570T-ZB; 04.54.03; 0x00000001;); LG NetCast.TV-2012

fiddlersetup redirecting





Get every new post delivered to your Inbox.

Join 285 other followers