In-memory Automated UI Testing ASP.NET Core

Introduction

In this article, we look at how to run in-memory automated UI tests for an ASP.NET Core web app using Playwright and NUnit. The article provides demo code and solutions to issues found along the way.

Automated UI Testing

Automated testing of any web application is essential to ensure it functions correctly.  On the top of the “testing pyramid” proudly sits UI testing or end-to-end testing, above integration and unit testing.  Automated UI testing involves launching and controlling a browser to drive through a set of interactions that a user would perform.  Assertions are made to see if the web app and browser behave as expected.  Browsers are controlled by testing tools such as Selenium,  Puppeteer, or the new kid on the block, Playwright.

Writing Logs Into Elastic With NLog, ELK, and .NET 5.0

If you are using Microservice-based architecture, one of the challenges is to integrate and monitor application logs from different services and the ability to search on this data based on message string or sources, etc.

So, What Is The ELK Stack?

"ELK" is the acronym for three open source projects: Elasticsearch, Logstash, and Kibana. Elasticsearch is a search and analytics engine. Logstash is a server-side data processing pipeline that ingests data from multiple sources simultaneously, transforms it, and then sends it to a "stash" like Elasticsearch. Kibana lets users visualize data with charts and graphs in Elasticsearch.

How to Remember Nullable Value Types

Recently nullable reference types have become trendy. Meanwhile, the good old nullable value types are still here and actively used. How well do you remember the nuances of working with them? Let's jog your memory or test your knowledge by reading this article. Examples of C# and IL code, references to the CLI specification, and CoreCLR code are provided. Let's start with an interesting case.

Note. If you are interested in nullable reference types, you can read several articles by my colleagues: "Nullable Reference types in C# 8.0 and static analysis", "Nullable Reference will not protect you, and here is the proof".

Node JS (ish) for .Net and C#

NodeJS, PHP, Python, and all of these other super dynamic scripting types of languages are extremely rapid in the beginning, as you start out. However, after a while, they tend to break down due to complexity. This was the sole reason why Anders Hejlsberg created TypeScript according to his own account. Simply because although it complicates things in the beginning, strong typing over time increases your application's maintainability score. Hence, traditionally choosing a language has been the choice between extreme rapid initial productivity, and the ability to maintain stuff over time. However, why choose, when you can have both?

With Hyperlambda you can encrypt and sign a lambda object, and pass it to another server securely for execution, with 4 lines of code.

Cryptographically secured HTTP lambda invocations

A lambda function invocation is when the caller supplies a piece of code to a function, for then to have the other function execute the code the caller supplied. In the following video, I am illustrating how you can securely transmit code over the web, to another server, for then to have the other server execute your code (securely), and return the result of the invocation back to the client. As an additional bonus, all the traffic is encrypted between both parties.

The whole idea is based upon combining two simple ideas; Cryptographic signatures guaranteeing the invocation originated from some trusted party - And sandbox execution environments, assigning rights on a "per keyword level" to some other party, as long as he can establish the code originated from him or her. As a bonus, everything is encrypted back and forth, preventing a malicious adversary to understand what the clients are communicating about. The whole thing works due to cryptographic signatures, being a lookup into "which sandbox" the client is allowed to play in. Hence, a public cryptography key is associated with elevated rights, associated with a particular client.

Translate your app in 2 seconds to 200 languages you don’t know

If you have worked with enterprise software, you've probably been asked to translate your app at some point. This implies translating small pieces of text, such as buttons, checkboxes, radio buttons, etc. This process often implies exporting CSV files from some database, sending these files to the employee doing the translation, importing the files into the database afterwards, etc. It's normally an insanely manual process, requiring some of your most expensive employees, working with the problem for hours and sometimes days. With Magic you can completely automate this process however.

In the above video, I demonstrate how you can automate this job, by looking up entities you need to translate using Google Translate. I've used this pattern myself several times, and Google Translate actually does a decent job 95% of the times, especially for Latin languages. Sometimes it'll mess up things for far east languages, such as Japanese, Chinese, etc - But for these cases, you can easily edit the translated entity afterwards, by giving access to the "translation app" to some back office worker responsible for that language.

Salvaging .Net’s HttpClient

If you read my previous article, it's easy to become frustrated. HttpClient is at the core of everything we as software developers normally do when we integrate our stuff with other people's stuff. Somebody sounding the alarm, telling you that it's fundamentally broken, might result in everything ranging from a general concern about ones own code, to flat out panic attacks. Hence, I figured I'd be an asshole unless I also showed you an alternative.

Paradoxically, fixing HttpClient is very easy, it's just to cut away everything in it that's dangerous, and encapsulate everything that's beautiful about it into a much safer API, making it impossible for developers to retrieve the instance to the HttpClient you're using internally. Basically, treat most of HttpClient's API as if it was cancer, and salvage the rest. Here's a much safer version in case you care. For the record, to understand this class, you have to read my previous article here at DZone.

.Net’s HttpClient is a hot smoking pile of garbage

HttpClient is probably one of the most popular C# classes ever created. Most noobs looks at it to justify their faith in OOP, and howls over each other in joy, while screaming out loud "it's async", or something similar, to justify their newfound belief in OO as a construct. Now for the record, implementing an HttpClient type of thing async, is a major improvement over the previous crapware Microsoft released in this space - However, HttpClient is fundamentally broken, and the only "fix" that exists for it, is to give focus to the folder where its code resides, then hold down your SHIFT key on your computer, while simultaneously clicking the DELETE button.

Above is a software developer trying to figure out how to correctly consume HttpClient in his own application.

8 Reasons Why PHP and .NET Rule the World of Web Development

If any company wants to succeed in the market, it needs to strengthen its digital presence. Though social media provides a place to gain some attention, it is impossible to create a brand without an official web page. This is why businesses hire firms offering web development services to get their website designed, which would enable them to get as much traction as possible. 

Web development covers actions such as web design, programming, content creation, network security tasks, and server-side & client-side scripting. Among the technologies available for web development, most web development companies make their programming choice between PHP and.NET.

The Big Rewrite

"The Big Rewrite" is a scary phrase for most software developers and software companies. Most developers probably spent years getting to the point where they are today, and they often overestimate the value of their existing code base. However, software development doesn't obey by the normal laws of nature. For instance, every time you re-engineer your software from scratch, you're destined to implement it 10x better, 10x faster, and 10x more stable - At least up to some "n number of rewrites". Hence, my proposition, is to create the same software 5 times, before you're happy with your end result, and willing to label it as "production ready". In fact, if you haven't created the same software at least 5 times, I'd argue it's probably garbage anyways.

According to modern studies of Leonardo DaVinci's Mona Lisa, this was the process Leonardo used when he painted Mona Lisa. He slowly over time added new layers of paint, on top of the old layers, until he finally died - At which point Mona Lisa was forever cast in stone, and ended up as it looks like today. Leonardo never finished Mona Lisa, he simply died of old age, before he could ever add the "final stroke of paint" on top of its old layers.

A Developer’s Guide to CQRS Using .NET Core and MediatR

“What is CQRS?” you might ask. I hope you didn’t think you were going to get a definition because that’s what Wikipedia is for. Instead, what I’m hoping to achieve with this blog post is to help you understand CQRS through some practical examples.

I will assume you’re either a beginner or someone who is unfamiliar with this topic, so maybe you get scared whenever you run into these big programming acronyms and concepts. I myself have been there, so I’m here to help you figure it out in the easiest way possible.

Write Integration Tests on MongoDB With .NET Core and Docker

Hi all! In this post, we’re going to explore a simple but effective way to write integration tests on MongoDB using .NET Core and Docker.

A while ago I wrote a small series about Unit Testing on MongoDB. A lot has changed since then, and I also received a few requests to add more details. To be fair, I am not even that happy now with those articles. I bet it’s the same feeling we’re all experiencing when we look at the code we wrote in the past.

Event Sourcing in .NET Core: A Gentle Introduction

Event sourcing, aka "the great myth". I've been thinking about writing a series of articles about this for a while, and now it's time to put my hands back on the keyboard. 

I thought that with this long period of confinement at least I could have had more time to write some nice articles, but it turns out the reality has been slightly different so far.

Alexa Skill With .NET Core

Alexa Skills can be developed using Alexa Lambda functions or a REST API endpoint. Lambda functions are Amazon’s implementation of serverless functions available in AWS. Amazon recommends using Lambda functions even though they are not easy to debug. While you can log to a CloudWatch log, you can’t hit a breakpoint and step into the code.

Alexa Skill With .NET Core

This makes live debugging of Alexa requests a challenge. This post explains a simple but useful solution: it is to wrap code in a .NET Standard class library and stand up a REST API project for debugging and development and a Lambda function project for AWS deployment. This article shows how to create an environment to debug a locally-hosted Web API that uses the same logic that is used by a Lambda function. Everything's written in C#.

How to Implement Producer/Consumer With System.Threading.Channels

What’s this “Producer/Consumer” thing? It’s around us, everywhere. Every time you see some kind of workflow with multiple serial steps, that’s an example. A production line in a car factory, a fast-food kitchen, even the postal service.

So why do we care about it? Well, that’s easy: in almost every piece of software we write, there’s a pipeline to fulfill. And as every pipeline, once a step is completed the output is redirected to the next one in line, freeing up space for another execution.

Server-Side Pagination Using ASP.NET Core and Angular 8

Introduction

In this article, we will learn how to create server-side pagination, which is very useful whenever we have to display a large number of records.  

This will come in a total of three articles. In this article, we are displaying a number of records, and with that, we will calculate the number of pages needed. But, in one page, we can see only selected records, so rather than fetching all records at one time, we are going to fetch records based on pages. This will increase our performance. 

Modernize Existing .NET Applications

Is cloud-native right for your .NET application?

Together, with the Cloud movement and its functions and benefits, Software practices and trends have been converging towards creating or migrating the applications towards a Cloud-Native compliant architecture. This may include:


  • Microservices, where you have independently deployable applications with their isolated data persistent layers, which are not shared along with other services.
  • Polyglot architecture, where you are not tied to a homogenous stack with a single programming language. You can also use the data persistency option, rather using different language stacks for different purposes and also benefiting from several different types of Database and Datastore options.
  • Containers, where you define all your application dependencies, thus guaranteeing the portability all the way from developer workstation to production.
  • Serverless, where you split your application into functions and deploy those functions to a Cloud-managed cluster where you do not notice any underlying server and middleware maintenance and can define several options to trigger those services.

Moving towards a cloud-native compliant architecture