Contents tagged with c#

  • Repository and Unit of Work for Entity Framework (EF4) for Unit Testing

    Tags: Entity Framework, c#, linq, EF4

    If you are not familiar with the Unit of Work pattern you should firt look at Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10).  It's a great article that demonstrates what the Unit of Work pattern can do.

    Unfortunately, that article uses a different version of Entity Framework.  I am using the default tools that come with Visual Studio and didn't want to modify the project too greatly so for me, the code wasn't usable.  I also wanted to expose the IQueryable interface which as a side effect also simplified my Repository design.

    By using a Repository Pattern you'll find unit testing is now possible and quite easy to write.  This illustration (taken from asp.net) shows the differences between No Repository and the Repository Pattern.  Notice how there are no Unit Tests in the No Repository section also note the "Alternative Persistence Medium" node (this is where our MemoryRepository comes in).

    Read more...

  • Generic IQueryable Repository for Entity Framework 4 (EF4)

    Tags: c#, linq, Entity Framework, EF4

    Anyone who has tried to create tests with Entity Framework (EF) knows that EF is not very unit test friendly. I needed something simple, reusable and unit testable. this generic repository was the result.

    The goal of this project was high reusability, ease of implementation and to be unit tests friendly.

    There are a lot of Repository Pattern's out there that hide a lot of the underlying functions of your data access layer (in this case LINQ). Well, I really like LINQ to SQL and didn't want to hide any of that. Plus, if you really need encapsulation it should be done in your service layer and not your repository layer.

    Read more...

  • Data, Context and Interaction (DCI) & Windows Workflow (C#)

    Tags: DCI, Workflow, c#

    Disclaimer: This article assumes you already know the following: C#, WF4 and Extension Methods.

    Lately I have been reading a bunch about Data, Context and Interaction (DCI) and a lot of my current project have involved using Windows Workflow Foundation (WF4).  Recently I've come to the realizaion that a WF4 Activity can also be the perfect DCI context because both are basically use cases.

    I've taken some sample code written by Christian Horsdal about DCI in C# and applied to to a Workflow.  He's has some very good posts about DCI and C#, I'd recommend checking them out if you want to learn more.

    Read more...

  • MiniLinq for Script#

    Tags: script#, c#, javascript, linq

    Script# is my new favorite piece of technology. Write JavaScript with C#? Yes please! But since it's (currently) limited to ISO-2 C#, it can feel like you're stuck back in 2004. Using C# 2 means you're missing a lot of things you use daily... like LINQ. I do miss LINQ. So I read about Script# adding a few LINQ like extensions to the array class and decided to work them together into this MiniLinq class, which I am now sharing with you.

    Read more...

  • Akismet .Net 2.0 API (anti-comment-spam)

    Tags: .net, spam, akismet, c#

    It looks like spammers are set on ruining the entire internet. Not only do I get 1000's of unwanted emails every day, but now spammers are starting to pollute blog comments.

    Fortunately the guys over at Akismet have developed an anti-comment-spam web API. There are multiple libraries that have been developed for Akismet, though none for .Net. Since I am going to be implementing this on Joel.net, I figured I would just wrap it all up into an easy to use library for me and you too!

    Download source project