Perhaps the most exciting feature in C# 8.0 was IAsyncEnumerable. At work, we have been dealing with a LOT of async calls. Prior we were having to block the thread just to get the data, and process it accordingly.
One of the more annoying things was converting existing enumerable to IAsyncEnumerable so we wouldn’t have to block the thread and could keep trucking on. The following is a neat little Gist that I partially found and partially developed that I figured I’d show off.
This is an extension method, just drop into your project and call “.SelectAsync” on a collection you want to pull data out of asynchronously as well as convert to an asynchronous enumerable.
Working with any form of a secret in development such as usernames, connection strings, passwords, etc is always difficult. Simply finding a convenient and efficient way of storing them without putting them in source control can be a daunting task. While there are many ways of handling this such as dotNet secrets, Azure Key Vault, and Hashicorp Vault. I, however, decided to go with AWS’s secret manager.
For the past few days, I’ve been working with a fairly large dataset (2.87GB) that is in a collection of 66 different tabular delimited files. This in and of itself isn’t bad, but the problem is that I was wanting to be able to easily place it into various formats and have an easy way of working with it. This is where dynamically creating objects comes in handy.
Normally in this situation, I would go through and create POCO’s to hold the data while I worked with it, but with this number of files and with each file being its own collection of objects that would prove fruitless. Coincidentally, the day before I started on this I also started reading Metaprogramming in .NET, this provided me with a better path of handling this issue.
Let’s start off by saying that if you’re not writing Unit Tests….you should. Unit testing is everywhere these days, from Bootcamps, to tutorials, to books. There is a good reason behind this too. Unit tests help developers create a fully functional, bug-free applications. Giving near instant feedback on whether you just broke your code or not can save many headaches in the long run. I see many of those new to unit testing falling trap to a common pitfall: Changing access modifiers. Let’s take a look at how to write your unit tests without having to change your modifiers.
.NET languages have a variety of forms of flow control, if statements are easily among the most noticeable. When having to compare multiple statements it is common practice to utilize switch statements due to it’s improved performance, but is there another way? It turns out there is! We can actually use a dictionary and delegates for flow control! Before we delve into this, how exactly are switch statements utilized by the compiler?
TLDR;
You can use dictionaries in place of large switches and the code is found here.
So what exactly is code lint? I’m sure we’ve all heard of a linter but how many out there have actually taken the time to sit down and use one? What are they used for? Well, getting rid of code lint, of course! A linter is defined by Wikipedia as:
A linter or lint refers to tools that analyze source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.
So obviously feeding off of the definition of a linter, a good explanation for the lint itself could possibly be clearly defined as:
Code lint is a software programming “smell” that is identified by programming errors, bugs, stylistic errors and/or suspicious constructs.
I personally believe that this is a good explanation to those. There are linters out there for nearly every language, however; I’m going to focus on JavaScript for soon-to-be apparent reasons.
So it’s Friday and I haven’t published anything this week yet. Figured I’d push out a short and quick tutorial on OWIN and give everyone something to play with over the weekend!
What is Owin?
OWIN is an acronym that stands for Open Web Interface for .NET and is meant to define a standard interface between web servers and applications. The goal of OWIN is to decouple servers and applications. Due to this it encourages the development of simple modules for .NET web development. Because of this OWIN is great for building small, simple, self-hosted applications. It’s ability really shines when it comes to the creation of micro-service APIs. Within this tutorial I will take you through the basic process of creating a small self-hosted API. We will go from inception all the way to implementation and discuss possible use cases.
Say hello to C# 8.0 and goodbye to those nasty little null-reference exceptions! That’s right, Microsoft is getting ready to release yet another major version of the language! This has been common knowledge for a little while now, so I may be slightly behind. Behind or not, I still wanted to bring it up. I am excited about all of the changes and features coming in the new C#. I don’t have the time or the space here to cover all of them but I will touch on some of the most drastic and useful features being added in.
Null references
Let’s face it, we’ve all been there. Everything compiles, we run our program eagerly awaiting it’s output. Then BAM! A big nope screen is thrown in your face, saying something about a NullReferenceException. Believe it or not Null References were suppose to be a thing of the past a long time ago. Thankfully the C# designers have finally gotten around to trying to get rid of them. Currently by default all reference types as well as variable types are nullable, this is all about to change.
Non-nullable by default
Starting with C# 8.0 reference types, by default, will be non-nullable. Now this isn’t to say that you can’t make them that if you so choose, but again this is by default. The C# compiler is also going to help you on this quest by throwing some helpful warnings if you forget to check for nulls or forget to make them nullable. Take a look at the example below:
1 2 3 4 5
ISomeType notNull;
ISomeType? mayBeNull;
notNull =null;//This will throw a compile warning
mayBeNull =null;//This won't
Another nice aspect about this is now it will also throw a warning if you forget to check if a nullable is actually null. This is a feature I believe is going to come in very handy. Take a look below:
mayBeNull.Execute();//This will throw a warning (we didn't make sure it wasn't null!)
notNull.Execute();//This will run fine
if(mayBeNull !=null){
mayBeNull.Execute();//This won't throw a warning (because we checked) }
Records
I’m sure most of us have worked with POCOs, creating numerous classes that are simply just going to be used to define a data structure and hold it. Traditionally this meant writing out a whole new class and defining it’s properties. Thanks to C# 8.0 we now have records! With records you can easily and quickly create these “container classes” with one line of code! For example, instead of having to type of this:
Now, I don’t know about you but this is definitely one of the more helpful features that I’ve seen.
And many more!
These are just two examples that I decided to speak on simply because I find them fascinating but there are many other features in C# 8.0! Check out the links below to find out more!
In Part 1 we set up Selenium and created our first test showing a browser being opened and then immediately closing. While that was interesting, I don’t know many people that would be super exciting by that alone. Since the whole point of these tutorials is UI testing, why don’t we actually test a UI? In this article we’re going to walk through creating a few more tests to actually log in to a website and verify that only a user with the right credentials can log in, we don’t want just anyone logging in now do we?
It seems everyone is making the move towards automated testing these days, and why shouldn’t they? How many times have you been working on a web project and had to constantly retest the same thing over and over simply to verify that it works? Or maybe you’re an analyst on the surface but a code monkey at heart and would like to blend the two together? Enter Selenium.
What is Selenium? Selenium is a browser automation framework. I was exposed to it a few years ago when I was still heaving into web scraping. Selenium is perfect for UI testing as it can easily mimic an actual browser with human input. You can even change the type of browser you want! Ok, so hopefully by this point you’re interested (or maybe not) and want to get started.