I recently had to add login functionality to one of our intranet sites, which incorporated quite a few constraints. Certain sections had to be restricted to admin users, and other sections had to be accessible without logging in at all. All passwords had to contain at least one number, upper case letter, lower case letter, symbols, and had a minimum and maximum length. The list went on! In the last week or so, I’ve written over 300 tests around this!
Most of the rules were relatively easy to accomplish using a combination of Forms Authentication, the default SQL Membership provider, and the various login-related controls that come out of the box in Web Forms. The rules that couldn’t be configured in the membership section of the web.config could still be accomplished easily enough using the various hooks built in to the login controls (e.g. adding various additional checks using the ChangePassword.OnChangingPassword event, unapproving users if their last login was too long ago, etc.).
The rule that presented the most difficulty, however, was the one that prevented users from using any of their most recent passwords. Having already implemented most of the other functionality using the System.Web.Security.SqlMembershipProvider, I now had a few options: Continue reading
Posted in Uncategorized
I haven’t been blogging for long now, and it’s been quite a while since my last blog. I’ve been working on the same problem for a while. I decided to move away from the Project Euler exercises in favour of doing an exercise that was put to me in an interview a few years ago. It was quite an interesting problem, and I was only asked to work through one aspect of the problem in the interview. It occurred to me that it would make a good kata and subsequent blog, so here goes…
Define an object graph to represent a mathematical expression.
I’ve elaborated on this original problem to also
create a parser that can take a mathematical expression inputted by a user as a string, and evaluate it.
Posted in Uncategorized
Ok – so I decided to skip blogging about exercise 3 – you can find it on my github account though. I’m trying to spend about 20 minutes a day doing these code katas, but I only have time to blog about once a week, so I’ll typically stick to blogging about the most recent / interesting one.
So I’m going to focus on my second attempt at exercise 4. I’m happy to say that this was “pure TDD”, in that I wrote the test not having any idea how I was going to implement it! I focussed purely on the design and how I wanted it to look to consumers of these components. I decided I’d try a Fluent Interface style – and I’m pretty happy with the result! So the first test I wrote is as follows:
public void CanFindMaximumPalindromeUsingFluentSyntax()
var result = Find.Maximum(number => number.IsPalindrome()).ThatIsProductOf.TwoNumbersEachLessThanOrEqualTo(99);
I need to start spending more time reading requirements!
Project Euler Exercise 2 is stated as follows:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
My first 2 implementations of this completely missed the “even-valued” aspect of this task – I just added up everything in the sequence. Let’s move swiftly on from that! After having re-read the problem, I started again and wrote the following test:
public void CanGetTotalOfAllEvenNumbersInFibonacciSequenceUpToAndIncluding4Million()
var fibonacci = new FibonacciSequence(4000001);
var result = fibonacci.GetValues().Where(i => i % 2 == 0).Sum();
Ok, so this is the first of what I hope to be a whole series of blogs about my attempts at each of the Project Euler exercises. I’m doing them all in C# – the main thing I’m trying to get from doing these exercises is more TDD practise.
Project Euler Exercise 1 is stated as:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
Take 1 – Iterator / Visitor Pattern
I decided to use something approximating a Visitor / Iterator pattern – this was a pattern I saw on JP Boodhoo’s Nothin’ But .NET course recently.