Posts

MongoDb seeding in Docker

For my last project I have been tinkering with Docker a lot, and one of the tasks I wanted to accomplish was to have a MongoDb instance in docker get seeded with data and users, as soon as the instance is created.

I have been trying several strategies. My first approach was the most naive one: after constructing the container, run manually a shell script that populated the database and created the users. It works fine, I guess. but is a manual process and is a step you must remember to run ... also when moving to prod environments will not work: you should never have Read/Write access to prod.

The second approach I took was to create a separate container that would execute the seeding script. This worked better, as the deployment will create the container; and within this container I can execute shell scripts that do mongoImport or mongo queries against the database. The only drawback I have is that the seeding container ringers in the application and eventually needs to be manually r…

Running Linux CMD in Windows - the webpack Case

So I am learning now that consistency is key: I was working on a Single Page Application (SPA)  project in windows, but running the tooling (npm, webpack, etc.) from WSL, just because I think the Linux native commands work better from Linux.

Well, it turns out there are larger differences than I thought: In this particular case, I ran npm install from WSL, which in turn created the node_modules dir, and populated all my dependencies. So far so good. no weird errors or anyting, I tried before to run it from PowerShell and I got permission issues.

The bigger problem appeared when I tried to run my project from Visual Studio. I am not certain what commands are run when in VS that trigger the webpack process, and that webpack process failed miserably on my application. I started debugging and I found out I was not even able to run the webpack command from windows CMD!.

It turns out that depending on the environment you are, the files created are registered in different ways in the node_mo…

Running Linux CMD in Windows - the RipGrep Case

Not a new thing, lots of posts there about it.. I have been trying to get it to a nice point, and I think I have been able to.
I installed a new CMD client that actually works better than the one OOB.

Go to https://github.com/goreliu/wsl-terminal  to get it. It allows changing the default font, which is necessary if you want to run the cool Oh My ZSH extension, on the zsh shell.

Now, I installed Angular CLI, Docker CLI, GIT, and I am in a better place.

Recently I needed to use RipGrep on my shell, so I tried the mythical apt-get, with no luck. I Went online to find another way to do it, and the installation notes on RipGrep tell you to install using snappy (for Linux). That didn't work either. Snappy is not functional in WSL ­čśľ.

However, the Debian install did work! so I ran the commands stated for Debian :

$ curl -LO https://github.com/BurntSushi/ripgrep/releases/download/0.8.1/ripgrep_0.8.1_amd64.deb$ sudo dpkg -i ripgrep_0.8.1_amd64.deb
That allowed me to run rg from my CMD!

Unity in a webAPI project

I have just created a proof of concept for a client where I demo how to configure Microsoft's Unity DI container to resolve the API controllers and their dependencies.

The code is available in this github repository.

The concepts that I tried to showcase are

How to configure Unity in OWINHow to do automatic registration of IObject->Object references.How to use an injectionFactory to resolve object that depedn on dynamic data.Different Lifetime managersContainer Controlled (Singleton)Per Resolve (Once per request)Transient (Once per call)Unit testing an application with dependenciesAbstracting away the HttpContext from the controller, which is useful for unit testing.
Take a look and comment in the blog or in the repo..

Testing Exceptions in Nunit 4.7

I am getting in TDD a lot, and of course, when thinking in border cases, you'll end up throwing exceptions, And you'd want to see ith they get thrown. With Nunit 4.7 the thing is that If, for example, you're testing that some parameter is null, when you decorate your test with [ExpectedException] it eventually gets thrown, but You'll never know what piece of code actually did it...
So, I created this little R# snippet to test excxeptions in a more granular way:
[Test] public void $TestName$() { try { $Code$ } catch (Exception e) { Assert.That(e, Is.TypeOf(typeof($ExpectedException$))); $END$ return; } Assert.Fail("Did Not Throw the Exception."); }
For example, if you want to test if a parameter is null before you excercise some code, you could have a test like this:

[Test] public void Intermediary_ParamOneCannotBeNull() { try { new Intermediary(null, null); } catch(Exception e) { Assert.That(e, Is.TypeOf(typeof(ArgumentNullException…

Alt.NET in Colombia

I recently found @jorgegamba, which has been very active on VAN meetings for hispanic community.

He is also from Colombia and share the same interest on making Alt.Net widespread on Colombia.

He is trying to build a community for Colombian programmers who want to grow as agile .net programmers. I beleive is a very good initiative and I'm planning on supporting his idea any way possible.

Adelante Jorge!

Debugging Sharepoint Applications

When developing sharepoint apps, it becomes a pain in the neck to know what process to lint to (via debug-attach process) because it usually has many w3wp process running, and knowing which is the one you need is usually a trial-and-error thing.

Spence Harbar has a very handy application called Application Pool Manager which lets you do several things:

1. Reset application pools, which is faster than iisreset.
2. Show the list of application pools running
3. Establish which application pool has which process ID associated, and refresh it if someone else recycled them (i.e. VSeWSS)

This way, by just having a look at the tool's menu, you can know for sure what process ID you need to attach to!