Posts

Showing posts with the label tdd

Comparing Excel files, take two

Image
I already wrote this project once, on GitHub , but I can't say that I like the result. I wrote that code without TDD, mostly to see if I can still work in the "normal" fashion. I can, but I had a bug that took me a while to even discover and then was difficult to write tests for. I also hate the temporal dependency in that design (if you don't call the SortBy method first, the ExcludeRecords method will return incorrect results). Anyway; here's attempt number two, writing that code using TDD. Structure I start by creating my usual structure for projects of this type - a library for the logic, a console application for the main program and a test project for tests. I also use the Enable NuGet Package Restore option (right-click on the solution node) to add the three NuGet files that will allow someone to automatically download all the packages I'm referencing without wasting space in the source code repository. (Right now I've only added the Moq pa...

Fail-over algorithm

oDesk and similar sites are an interesting source of programming ideas - there are a couple of job descriptions I've seen that I have found interesting. One of them went something like this (paraphrasing): I need to continuously get data from a site and write it to a database. They have a main API that I coded for, but it fails sometimes. There is a secondary API and I coded for that too, but the first one fails unexpectedly and I haven't yet figured out all cases. Plus, the secondary one can fail too, I want to be informed if that happens. Expressing this requirement in a different way, and assuming that the "want to be informed" part can also fail, the algorithm would look something like this: try the first API if that fails, log and try the second API if that fails, log and inform the client if that fails, log and write to an alert file if that fails… do nothing, it's more important for the program to keep running "Challenge accepted," as th...

Unit tests vs integration tests

Great article on the difference and on why both are important.

Write your own blog engine, part 6

Adding features What new features can I add to this to make it more useful? Paging is one that would be immediately useful (right now I will return the most recent five posts but I have no way of getting to older ones). Comments are also necessary; I will keep them in mind for later. There are two aspects of paging: I need to return a list of links pointing to pages and I need to be able to display that page when I click on the link. A problem comes to mind: since the posts are sorted in descending order based on their date, each time I add a new post the content of all pages will change. I don't know how this affects something like search engines; you might want to use paging based on the month of the post instead. I'll start with the first part, the navigation links. I will return those using the new HTML5 nav tag: <nav> <ul> <li><a href="/Home/Index/1">1</a></li> <li><a href="/Home/Index/2">2</a...

Write your own blog engine, part 5

Post management I have decided to change the scope of this chapter: it won't be limited just to deleting but instead it would be about general post management: identifying, adding, deleting and modifying posts. I will use the value of the Id field to identify posts; that means that an URL like /Home/Post/guid would take me to a specific post. However, before I start to go in that direction I realize that it makes more sense to create a new PostController class to handle everything about posts. That way, the URL for adding them would be /Post/Add and the one for displaying a single post would be /Post/Details/guid. That means changing a lot of tests; I verify that they're all green, including the one that I disabled earlier (they are) and then start searching for the AddPost string in the tests. The first one is in the acceptance test I just re-enabled so I'll change "Home/AddPost" to "Post/Add". It is now failing with a (404) Not Found. error. ...