Posts

Cool Way to Fake IConfiguration for unit testing

Image
  I was working on a project the other day and I came across a need to fake/mock an IConfigutration object. Tried MOQ I started with MOQ.  This is always quick and easy to use.  I have used this in the past but this time I needed to change the values within the configuration.  Which is totally possible but the more I dig into how to do that the more of a pain it became. Since I am lazy, I figured there has to be a better way. Simpler Method I quickly discovered, there was an easier way.  There is a class in .Net called ConfigurationBuilder.  With this class, you can easily create an in-memory configuration collection with whatever settings you want. 1. Create a dictionary of values                var inMemorySettings = new Dictionary<string, string>()             {                 { "Location", "TestLocation"}         ...

File Upload Button Styling

Image
 I came across an article that said you can actually style the file upload button, so I decided to apply styling to my new File upload project. As it turns out, this is quite easy:      input[type=file]::file-selector-button {          border: 2px solid #6c5ce7;          padding: .2em .4em;          border-radius: .2em;          background-color: #a29bfe;          transition: 1s;      }      input[type=file]::file-selector-button:hover {          background-color: #81ecec;          border: 2px solid #00cec9;      } As you can see you just use the input[type=file] CSS selector to select the upload button.  Once you have the element selected, just like any other HTML element, you apply your styling. [source]

Blazor File Upload (Updated)

Image
  With the release of .Net 5.0, a new Blazor file upload component was released.  I wanted to replace my old file upload component that I published way back in Oct of 2019, post  with the new 5.0 one. This post is working with the Blazor Server side, but this will work with Web Assembly except you will need a server API to do the actual file upload. Changes I started by updating my Blazor project to /net 5.0.  That part was easy.  My next step was to replace the component.  As it turned out, my old component was named the same as the new one:           <InputFile OnChange="@HandleSelection" /> For the selection handler, I had to make a couple of changes.  The changes were 1. Switched the agreement from IFileListEntry to InputfileChangeEventArg 2. The collection of files that were selected changed from FileListEntry to IBrowserFile.   Working with IBrowser file object does change the information that we have...

Yes, Blazor Server can scale!

Image
From the very beginning of the release of Blazor Server naysayers have incorrectly stated that Blazor Server can not scale.  They usually state that the limit is 5,000 concurrent users. There are several misconceptions and wrong assumptions about their statement.  Let's break it down and get a better understanding of Blazor server-side scaling. What is the "limit" for users When Microsoft talks about the need to scale an application, what they are saying is that when a normal response for any concurrent user is taking longer than 200 ms, the system is not performant and needs to scale. We will accept that definition: If any normal user response is taking longer than 200 ms, the system needs to scale for concurrent users. By a normal response, we are referring to a page get, a post, etc.  Large database access requests would not be included in this measurement. What is scaling There are 2 common ways to scale, scale, out horizontally, and scale-up, up vertically. In our di...

Fun with Dad Jokes

Image
I was browsing Javascript projects that are available online so I can convert them to  Blazor.  It is fun to try to do everything they did in JavaScript in Blazor.  I came across this application.   This project was created just for pure enjoyment.   There are a couple of Blazor changes that were needed, but overall it is fairly straightforward and a ton of fun to implement. The implementation was to make an API call to get a Dad joke from a Dad Joke service, yes they have those.  Then get a random image to display, then display the image on each request. The project was inspired by Brad at Traversy Media .  He has a ton of great videos and courses on web development.  He does a good job of explaining the details as well.  You should check him out. Applications Objective The application is an entertaining project that just felt good to build.  It will randomly display a dad joke with a random image. It is that simple. Blazor Pa...

Blazor UI Component Library

Image
 I was reviewing some sample code the other day and I noticed that the index.html file had a lot of linked CSS files.  This got me thinking: "Question: If UI components are in separate assemblies and use CSS isolation, would you still need to include the CSS file?" The short answer is NO.  if you use CSS isolation, you don't need to include the CSS files. We can go from this: <link href="ComponentLibCSS.styles.css" rel="stylesheet" /> <link href="/_content/Assembly1/styles.css" rel="stylesheet" /> <link href="/_content/Assembly2/styles.css" rel="stylesheet" /> <link href="/_content/Assembly3/styles.css" rel="stylesheet" /> <link href="/_content/Assembly4/styles.css" rel="stylesheet" /> To just this: <link href="ComponentLibCSS.styles.css" rel="stylesheet" /> A key point to remember for this you must be on .Net 5 or gre...

Static Bootstrap website to Blazor - Updated

Image
I have been spending some time working with Azure static websites and it got me thinking I should do a post about them.  The more I have been working with the Azure static websites, the more I like them. So I decided to dust off an old post, Static Bootstrap website converted to Blazor .  In this old post, I took a common Bootstrap-themed static website and "Blazorized" it. In the original project, I created components, removed as much of the javascript as I could, and used Blazor.  This was done back in Nov of 2019 as a server-side application.  This was right around the time Blazor server-side went GA and the Web Assembly was still at least 6 months left to go in development. For this post, I will be creating a Blazor Web Assembly version of the project that is built for Azure Static Websites and that actually works.  I hope to document as many of the changes as I can.   Once I fired up the old project, the project did not even compile anymore. ...