Twelve Days of .NET: Day 5: Unit Testing

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

I don’t actually have much to say here. I set up the standard unit testing project that’s built into the VS 2017 Web API project template, and went through the motions of setting up some tests for one of my controllers. (There’s documentation on that here.) But I didn’t get very far, since I don’t really have an effective mocking strategy for the external API that my API is calling out to.

I started looking at Moq, but didn’t get too far. So maybe this is something for the next project, or version 2 of this project.

Twelve Days of .NET: Day 4: Web API documentation

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

If you’re going to create a REST API, it’s important to document it. For a project at my last job, I created a whole Drupal site to document our REST API. I wrote all the documentation from scratch! With the standard Web API template in VS 2017, you get documentation for free. (Well, almost free.) Here’s an article explaining how to set that up.

I also decided to create Swagger docs with a library called Swashbuckle. Swagger is pretty cool, and seems to be very popular right now. (If you want to use Swagger with ASP.NET Core, here’s a good post on that.)

Twelve Days of .NET: Day 3: Logging

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

On past .NET projects, I’ve generally used log4net to handle logging. I like the rolling file appender and generally use that. For this project, I decided to look at what else was out there. I found Serilog, and decided to give that a try. It worked out really well. I think I’ve found my new default .NET logging library. It has a rolling file sink similar to log4net. And it’s very flexible and configurable.

Twelve Days of .NET: Day 2: Dependency Injection / IoC

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

One of the first things I wanted to figure out on this project was how to make use of Dependency Injection / Inversion of Control. I’d read about it before, but never really quite figured it out. The original source for the DI/IoC concept is from a Martin Fowler blog post from 2004.

I evaluated a few options for my project, and settled on using Autofac, which is a well-documented IoC container that works well with Web API. This video from Channel 9 helped me figure out how to get started with Autofac and DI in general.

I also considered Ninject and StructureMap. I don’t have much to say about those, since I didn’t wind up using them.

The end result of all this is that I think I finally have a decent working understanding of DI/IoC.

Twelve Days of .NET: Day 1: Web API

This post is part of my 12 Days of .NET series. This is a (not terribly ambitious) series of posts on .NET topics that came up while I was working on a recent C# Web API project.

For the .NET project that I’ve been working on recently, I’ve had to play a bit of “catch-up,” since I haven’t been doing too much .NET/C# development recently. My part of the project was to create a middleware API (for lack of a better term) that would provide a simplified internal interface to a more complicated external REST API. I decided to make my API a REST API also, since that’s pretty much the standard at this point. I’d done a lot of work with SOAP APIs in the past. And I’d created a REST API in .NET at least once before, using WCF. Back then, I probably started out by reading something like this article from 2008.

The way to do this stuff now is Web API. The most up-to-date way would be to do this in .NET Core. I couldn’t do that, for reasons that are kind of complicated and not worth going into. (Actually, at some point, I figured out that I probably could do it with .NET Core, but by that point I was too far along to go back.)

I used a few resources to get started. I watched a couple of video courses on Pluralsight: Jon Flanders’ Intro to ASP.NET Web API and Shawn Wildermuth’s Implementing an API in ASP.NET Web API. I also read the book ASP.NET MVC 4 In Action. This was somewhat out of date (last revised in 2012), but was still useful.

So let’s call that my day one post: I started a Web API project, using VS 2017, and the standard .NET Framework.

Twelve Days of .NET

Back around Thanksgiving, I got interested in stuff like the F# Advent Calendar, the C# Advent Calendar, and Advent of Code. I’ve been working on a pretty cool .NET project at work recently, and I got the idea that maybe I’d do a series of blog posts about various tools and techniques that I’d come across while working on this project. I haven’t written a lot of programming-related blog posts lately, so I though this would be a fun way to get some programming content back on the blog.

I originally thought I’d try to follow the Advent Calendar model, and do one post a day for 25 days, starting on 12/1. Then, when I didn’t get around to starting that, I thought maybe I’d do a Twelve Days of Christmas thing, and do twelve posts from 12/13-24. Now that it’s past Christmas, I’ve decided to just do twelve posts and skip the whole Advent/Christmas connection. I’ll just call it “12 Days of .NET”.

I’m not going to be too ambitious about this. Most of the posts will probably be short, and I’m not going to post a lot of code. Mostly just links to stuff that I found useful. I’ve got most of the posts written already (at least in rough form), so I’m going to set them up in advance to auto-post every day for the next twelve days.

Black Friday

My Black Friday spending, so far, has been limited to renewing my Pluralsight subscription for their usual Black Friday rate of $200. When I paid for my first year, I wasn’t sure I was going to renew it for a second, but I’m getting enough out of it, so I guess it’s worth paying for another year. So I’m good through 2018 now.

I’m not seeing too many other Black Friday sales that look interesting, but I’ll probably spend some money at Comixology before the weekend is over. They have a lot of good stuff on sale.

Trying to catch up with .NET

I’ve really fallen behind with recent developments in the .NET ecosystem. At work, I spend most of my time in Dynamics AX, so I don’t get to work on a lot of pure .NET stuff. I’ve been trying to get current, but it’s really an uphill battle. Stuff changes faster than I can keep up!

I just finished a book on ASP.NET Core, ASP.Net Core Application Development: Building an Application in Four Sprints. (Even just reading the title on that book is exhausting!) I posted a review on Goodreads, so I won’t repeat myself here.

I have a little extra respect for the book, because it includes a quote from Lord Baden-Powell, the founder of the Boy Scouts:

Try and leave this world a little better than you found it and when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best. ‘Be Prepared’ in this way, to live happy and to die happy — stick to your Scout Promise always — even after you have ceased to be a boy — and God help you to do it.

I think this was in the chapter on refactoring code. So with respect to programming, I guess it means I can die happy if I’ve done my best to refactor poorly-written legacy code, renaming obscurely-named variables, reducing cyclomatic complexity, and all that good stuff.

Anyway, while I got a lot out of that book, I didn’t really come out with what I’d call an actual working understanding of ASP.NET MVC. I mean, I understand the basics, but I’ve got a long way to go. And there’s so much related stuff to learn too. One thing I’ll say is that this book had the first explanation of dependency injection that actually made sense to me. (I’d heard it described in podcasts before, and had probably read a few blog posts about it. But I don’t think I really got it until the explanation in this book.)

I’m also trying to read ASP.NET MVC 4 in Action right now. This one dates back to 2012, so it’s a little frustrating trying to reconcile stuff in this book vs. the way ASP.NET Core 2 works now. But it seems like a good book so far.

ASP.NET Core 2 is pretty recent of course. Here’s a What’s New in ASP.NET Core 2.0 post from July and an Announcing ASP.NET Core 2 post from August. (The new Razor Pages feature is pretty interesting, by the way. I listened to a podcast about it last week.)

The two ASP.NET books mentioned above are both available via my ACM Safari subscription, so that’s how I’ve been reading them. There’s a lot of good stuff there. I’m also getting a little bit of use out of my Pluralsight subscription, but probably not enough to justify the cost. It was really useful for the SharePoint stuff I watched on it a while back, but for general .NET stuff, there’s plenty of free video training out there, through Channel 9 and other sites.

My bookshelves are a mess

Scott Hanselman posted a tweet yesterday with a photo of a bookshelf, asking people to reply with photos of their bookshelves. I was bored last night, so I took a few photos. This morning, I posted them to Twitter. A lot of other people replied to him too, with some cool photos.

I thought I’d post my photos here too. Of course, a large portion of my reading these days gets done via Kindle, iPad, and laptop, so my physical bookshelves aren’t necessarily reflective of what I’m reading these days.

It would be nice to have organized bookshelves, but what I have is really just piles of stuff, sometimes on bookshelves and sometimes on the floor or on various horizontal surfaces. It seems like the piles just grow, until they become structurally unsound, at which point I need to toss some books and/or reorganize. That’s one of the many reasons why ebooks are so great. I can buy as many as I want, and they never become a fire hazard.

I feel a little like I need to justify and explain these photos a bit, but maybe it’s better if I just let them speak for themselves. Or maybe not. The first one is a pile of random computer books, most of which I’ve read, but a few of which I never really got around to. The second is a pile of paperbacks, mostly Vonnegut, that I got from one of my brothers. (I can’t remember which brother.) I haven’t actually read most of them. (Oh, and there’s a couple of Ghost in the Shell DVDs on top of the paperbacks.) The third is some random SF paperbacks, all of which I have read. Mostly Gibson and Zelazny. The fourth is one of several “to be read” piles of graphic novels. There’s some stuff in there that I’m really looking forward to, including Grant Morrison’s X-Men run, a few volumes of Bill Winningham’s Fables, and some Usagi Yojimbo. (I’m a little embarrassed by the Vampirella book in that pile, but I’ll own up to liking Vampirella. It’s goofy cheesecake, but it’s fun.)

 

 

more TypeScript and SharePoint

I got a chance to work on another TypeScript / SharePoint project at work recently. I’m finding these projects to be a nice change of pace from my usual Dynamics AX work.

I’m not doing anything that’s much more complicated than I did on the last one, but I got a little more ambitious on this one. I’m still using Q for promises and Papa Parse for parsing an input CSV file. I think I’m getting a little better with promises, but I still occasionally have problems with them.

On my last project, I put all my TypeScript code in one file. For this one, I’ve broken things up into several classes and files. I’ve even gone as far as having an abstract base class with two child classes inheriting from it.

And, for the last project, I just deployed the generated JavaScript as-is. For this one, I’m using Web Essentials to combine and minify the JavaScript. That’s working better than I thought it would.

I’ve also given up on the idea of deploying this thing as a regular SharePoint sandbox project, though I’ve set it up that way in Visual Studio. Instead, I’m simply copying the HTML and JS files to the SharePoint server with SharePoint Designer. Maybe that’s not the best way to do it, but it’s the easiest, and the least disruptive to the server. (I should look into whether or not it’s possible for me to do that with PowerShell.)