Peter Gfader's brain noise
ASP.NET - Generic InMemoryCache helper

Nice helper to keep some data in memory…

This is how I use it in TwitterFish

public static IEnumerable GetLast20ScreenNames()
{
  InMemoryCache cache = new InMemoryCache();
  var result = cache.Get(Last20Screennamesfollowers, 
        () => new RepositoryMongoLastUsedScreenName().GetLastUsedScreenNames(20));
  return result;
}

How to cache data in a MVC application
http://stackoverflow.com/a/349111/35693

Nice code - Usage of fluent interfaces - Java code

Seen in a test that searches for products

aProduct("LAB-1234"
.named("Labrador Retriever")
  aProduct("CHE-5678")
.named("Chesapeake")
.describedAs("Chesapeake bay retriever")

   aProduct()
.named("Dalmatian")

Creates 3 products with the specified features.

The whole test looks like this

    @Test public void
    searchesAndFindsProductsInCatalog() {
        context.given(aProduct("LAB-1234").named("Labrador Retriever"),
                aProduct("CHE-5678").named("Chesapeake").describedAs("Chesapeake bay retriever"),
                aProduct().named("Dalmatian"));
        petstore.searchFor("retriever");
        petstore.displaysNumberOfResults(2);
        petstore.displaysProduct("LAB-1234", "Labrador Retriever");
        petstore.displaysProduct("CHE-5678", "Chesapeake");
    }

Read all the code here

https://github.com/testinfected/petstore/blob/master/petstore-system-tests/src/test/java/test/system/com/pyxis/petstore/SearchFeature.java

Test names can have whitespace #fsharp

How awesome is that!


 open NUnit.Framework 
   let [] ``This is a test with some whitespace`` () = Assert.IsTrue(true)

Tests are not DRY
  public class TennisGameSpecs
  {
    [TestFixture]
    public class GetScores
    {
      [Test]
      public void NewGame_Player1_ShouldReturn0()
      {
        TennisGame tennisGame = new TennisGame();  // = "NewGame"
        
	Assert.That(tennisGame.Player1.Score, Is.EqualTo(0));   
      }
    }
 

Test Names and the actual tests contain duplication. 
In the example above “NewGame” in the name of the test and the actual code… 

I think that is the reason why we had a discussion about Naming Tests

XUnit wins over MSTest, expecting an exception
// XUnit 
[Fact]
public void ThrowsException__PassingNegativeValues()
{
  Assert.Throws<ArgumentException>(() => sut.Add("-1"));
}
 
// MSTest
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ThrowsException__PassingNegativeValues_()
{
  sut.Add("-1");
}
Do you use microtypes / explicit types? via @NotMyself

As per my other entry it makes sense to use MicroTypes to improve readability and to avoid errors.

Bobby Johnson blogged a nice way on how to use the “implicit operator” to create new structs

Using the Implicit Operator in C# for Maximum Nerdy Good Times
http://iamnotmyself.com/2012/03/28/using-the-implicit-operator-in-c-for-maximum-nerdy-good-times/

Have some Nerdy Good Times!

Microtypes to improve readability and avoid errors

I haven’t used Microtypes myself, but I can certainly see the advantage of those. Especially after Refactoring and moving more functionality to those types…

Passing Strings and doubles around in an application can significantly increase the likelihood of inadvertantly passing incorrect parameters to methods. By strongly typing all string and number parameter types, this can be simply avoided. Its then also possible to add behaviour to these types, meaning that “utility” classes are removed, keeping behaviour close to the objects that need it.

http://www.time4tea.net/wiki/display/MAIN/Microtypes

Fluent interfaces #rock

If you havent come across the “Builder pattern” make sure to check this article out

My 2c: Fluent interfaces guarantee a nice coding experience

The Wizard Design Pattern
http://www.javacodegeeks.com/2012/01/wizard-design-pattern.html#ixzz1rm83hM2h

I had Sonar on my “things to look into” list for a while. And this feature makes it even more interesting.

What is Sonar?

Sonar is an open platform to manage code quality. As such, it covers the 7 axes of code quality: 

  1. Architecture & Design
  2. Comments
  3. Duplications
  4. Coding rules
  5. Potential bugs
  6. Complexity
  7. Unit tests

from http://www.sonarsource.org/

Aligns quite nicely with the 4 rules of simple design

A cool library that Llewellyn Falco and Dan Gilkerson put together.
I was skeptical about this library when I heard about it in the podcast, but now I like the idea. Especially for regression testing of external APIs. For writing your tests first TDD style it might not make sense ;-)

CopyCat is born.

CopyCat checks if your text is original and detects duplicates!

http://copycat.apphb.com/

CopyCat is a private pet project of mine, that I started to develop one month ago.

I always wanted to use all those nice shiny toys and techniques like: AppHarbour, Git, Continuous Deployment, NoSQL databases, MVC3, Cassette … and TDD, BDD approach on a green field…
So I started my own project with all those!

Bigger blog post on my blog coming soon… 

A couple of nice features in this base class for viewmodels:

  1. Strongly typed Property notification for databinding
  2. Automatic Method Execution

Code samples for #1

public string Text
{
    get { return Get(() => Text); }
    set { Set(() => Text, value); }
}

Code samples for #2

    public double Score
    {
        get { return Get(() => Score); }
        set { Set(() => Score, value); }
    }

    [DependsUpon("Score")]
    public void WhenScoreChanges()
    {
        // Handle this case
    }