Tech Blog

Unit Testing with Mocks

By: Chris Dunn on Tue Jul 16, 2019

If you are interested in an academic, or more intellectual understanding of Mocks, Stubs, Fakes which collectively are known as Test Doubles, it's always a good idea to visit Martin Fowler. Stubs Aren't Fakes. For this post I want to talk about testing in isolation using Mocks and Dependency Injection.  The examples in this post will be using Moq(https://github.com/moq/moq) but there a number of other options out there to choose from. Making your code testable In order to unit test in isolation, ...

Password Hashing using Rfc2898DeriveBytes

By: Chris Dunn on Tue Jun 25, 2019

With the recent data security breaches, we as developers need to make sure we are doing our best to secure the application data the best we can.  One very obvious problem is passwords and other sensitive data stored in plain-text in a user's database record on the server. For data that you must maintain intact, like perhaps a social security number or similar identifier, you need to encrypt the data completely.  It's always a good idea to take a long hard look at what data you must maintain.  Th ...

Initialize data before Angular App Starts

By: Chris Dunn on Tue Jun 11, 2019

It's generally a good idea to separate client configuration options from the rest of your code and display logic. These options could include API Endpoints, Language options, logging configuration or display settings. It makes it easier to customize these options for the various environments in the development process (development, test, staging, production).   Angular supports the concept of client configuration with environment files.  At first this may seem like a perfect place for these conf ...

Many to Many Relationship in EF Core

By: Chris Dunn on Tue May 21, 2019

A many-to-many relationship is one where you have two entities and entity x can have one or more of entity y, and entity y can have one or more of entity x.  Examples of this relationship are Products <-> Orders, BlogPosts <-> Tags, Albums <-> Artists, and in this post Courses <-> Students. In our example let's pretend we're writing course scheduling software for a University.  In that scenario, we might have two models for our Entities, Course and Student declared as fol ...

Clean sensitive files from GIT Repo

By: Chris Dunn on Tue May 7, 2019

Have you ever committed sensitive or at least unwanted files to a GIT repo?  You thought the file was ignored or unstaged and pushed your changes.  That's one problem with the nice GUI git desktops and IDE integrations.  It's easy to just push the button without thinking.  I find this is most often done at the beginning of projects before you're fulling thinking about the details of Source Code Management. So we accidentally commit a password.txt file or a configuration file config.json with pas ...

Multiple Authentication Schemes

By: Chris Dunn on Tue Apr 23, 2019

If you haven't read my post on cookie authentication in .net core, I suggest you do that now since I will be referencing it in the following post. There will be times when you will want more than one sign in under a web application.  This usually involves a member section and an administrative section of your application.  You could write two separate applications, one for the front-end, and another for the back-end.  Sometimes this is overkill and tricky depending on your deployment infrastruct ...

Typed AppSettings in .net core

By: Chris Dunn on Tue Apr 9, 2019

It's always easier to work with typed information in a program than trying to remember string keys in a configuration file. So when working with the appsettings.json file in .net core, I advise you load the configuration file into a class object and work with the object directly, instead of GetSection() repeatedly throughout your code. It's also a good idea to create the class object as a service so you can inject it into controllers for ease of use while still maintaining test-ability. I'll do ...

Watch your case in Linux Containers

By: Chris Dunn on Tue Mar 19, 2019

I am subconsciously Windows biased.  Maybe not subconsciously, but I do take case sensitivity and the file system for granted.  I am use to certain path information, special folders names, and file naming conventions. Embarking on the cross-platform possibilities available in .net moving forward, I (and you) will need to rethink some things we take for granted in windows. I recently ran into a situation while deploying a .Net Core web application to a Linux Docker container. The application was ...

Determine Current Operating System in .Net Core

By: Chris Dunn on Tue Mar 5, 2019

What Operating System is my .net application running on?  Seems weird to ask that question doesn't it.  But with .net core we now have the opportunity to more easily deploy cross-platform solutions using .Net and C#. So previously the question of which OS platform we were running for our application didn't really concern many .net developers. Fortunately, we now have to consider such things. (I'm not forgetting mono). Luckily .Net Core has us covered with OS information included with the Runtime ...

Linq First vs Single

By: Chris Dunn on Tue Feb 19, 2019

What's the difference between LINQs Single method and First method? While they can both return the same result, they serve a different purpose depending on the underlying sequence of data. Using the wrong method can cause problems in your code now, and as your data grows. First() First() should be used on sequences of data with a count of one or more. This method is returning the "FIRST" of possibly "MANY". If there are no results an exception will be thrown. One option, in this case, is to use ...

Configure Sessions in .net core

By: Chris Dunn on Tue Feb 5, 2019

With .net core, if you want to use functionality you will, in most cases, need to explicitly configure it yourself via middle ware.  This is actually a good thing.  It keeps your code and dependencies clean.  So if we want to utilize sessions in our application, we'll need to configure the middle ware. Configuring Sessions Even though you need to configure it yourself, it's not hard by any means. I'll explain the process and then show the code.  First you will need to add the following code in t ...

Canceling an Asynchronous Task

By: Chris Dunn on Tue Jan 22, 2019

When we have a long running operation, it nice to have the option to cancel the operation.  Luckily when they designed the TASK they gave developers the ability to more cleanly exit long running operations.  A TASK is part of the task based asynchronous pattern, which is the suggested pattern moving forward.  With this pattern they have included the idea of a CancellationToken which allows us to signal to a running TASK, that is should cancel. In the following example I've written a simple conso ...

Understanding the Limits of AI: When Algorithms Fail

By: Chris Dunn on Tue Jan 8, 2019

I am lucky to live close to a wonderful institute of learning, Indiana University. I decided it was time to take advantage of some of the opportunities available to me to grow as a developer. So, I have been making an effort this year to attend seminars and colloquiums sponsored by the Computer Science department. I recommend everyone take the time to see what's available locally. At the end of October I had the great pleasure of attending a lecture by Timnit Gebru, a postdoctoral fellow at Mic ...

Copyright 2023 Cidean, LLC. All rights reserved.

Proudly running Umbraco 7. This site is responsive with the help of Foundation 5.