Being agile with Cucumber, Rails, and Scrum

I’m starting a new project, and I wanted to test out how cucumber (Behavior Driven Development framework), ruby on rails, and scrum would work together.  Essentially i’m going to create a “feature” for each user story.  Each scenario will be a test.  I’ll probably end up using just a plain old spreadsheet for the scrum part of it.

My hypothesis is that this experience will have a learning curve, but once the curve has learned it’ll be just a fast as defining user stories, and tests alike.  In fact, I think it will be faster and more verbose.

What are your thoughts?

Read full story Comments { 2 }

Jsonp and Mvc 2 & 3

I’m doing some JSONP requests are work (i’ll go into what that means in a different post). I wanted to use an action result that wrapped my jsonp request. I found this blog post http://blog.ronnieroller.com/aspnet-mvc-2-actionresults-for-xml-jsonp-and, which got me going, but it missed the part I love about the JsonActionrResult.  Anonymous objects!

Here is my attempt at fixing that.

using System.Text;
using System.Web.Script.Serialization;

namespace System.Web.Mvc
{
    public class JsonpResult : JsonpResult
    {
        public T Obj { get; set; }
        public string CallbackName { get; set; }

        public JsonpResult(T obj, string callback) : base(obj, callback)
        {
            Obj = obj;
            CallbackName = callback;
        }
    }

    public class JsonpResult : ActionResult
    {
        public object Obj { get; set; }
        public string CallbackName { get; set; }

        public JsonpResult(object obj, string callbackName)
        {
            Obj = obj;
            CallbackName = callbackName;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            var js = new JavaScriptSerializer();
            var jsonp = CallbackName + "(" + js.Serialize(Obj) + ")";

            context.HttpContext.Response.ContentType = "application/json";
            context.HttpContext.Response.Write(jsonp);
        }
    }

}

Read full story Comments { 0 }

Generic CRUD operations with Entity Framework

Messing around with Ruby and Rails in general makes you think a little bit about DRY (don’t repeat yourself) principles.  This mentality is scattered around the whole rails framework in general, and I started adopting it into my daily programming.  One of the sections that wasn’t very “DRY” was my entity framework and the CRUD operations.  This part of the code is not only tedious but the part of the code that is the most prone to errors.

Let me show you how this works.  First off, this post is assuming your using some sort of dependency injection (I prefer ninject).

I start off with an Repository class that inherits from IRepository.

public class Repository : IRepository
{
     public IFaqRepository Faqs { get; private set; }

     public Repository(IFaqRepository faqRepository)
     {
          Faqs = faqRepository;
     }
}

So what we have is a FAQ Repository. This repository is abstract of the data access layer. So essentially we want to build in any custom queries. We want to hide the queries against the entity framework. Let’s now look at the FAQRepository class.

public class FaqRepository : Repository, IFaqRepository
   {
      public FaqRepository(DataBaseEntities context)
         : base(context)
      {
      }

      public IQueryable AllPublished()
      {
         return All().Where(faq => faq.IsPublished);
      }
   }

Nothing too fancy going on here. You inherit from a base Repository class which takes as a generic parameter an Entity Framework Entities, and secondly an Entity Framework Entity. The other part is the IQueryable method. This is a custom method I wrote that filters out the published faq’s.

So what’s going on behind the scenes?

public abstract class Repository : Repository
    where TEntity : EntityObject, new()
    where TObjectContext : ObjectContext, new()
{
    protected Repository(TObjectContext context)
        : base(context)
    {  }

    public IQueryable All()
    {
          return DataContext.CreateObjectSet();
    }

    public TEntity Save(TEntity entity)
    {
          using (var transaction = new TransactionScope())
     {
          if (entity.EntityKey == null || entity.EntityState == EntityState.Added)
          DataContext.AddObject(EntitySetName, entity);

               if (entity.EntityState == EntityState.Detached)
               DataContext.Attach(entity);

               DataContext.SaveChanges();
          transaction.Complete();
               return entity;
      }
     }

     public TEntity ById(Expression> predicate)
     {
          return All().FirstOrDefault(predicate);
     }

     public IQueryable Find(Expression> predicate)
     {
          return All().Where(predicate);
     }

     public void Delete(TEntity entity)
     {
          DataContext.DeleteObject(entity);
     DataContext.SaveChanges();
     }

     protected string EntitySetName
     {
     get { return DataContext.CreateObjectSet().EntitySet.Name; }
     }
}

This is where most of the magic happens–Using generics I was able to abstract out all the crud (Create, Read, Update, Delete) operations. The only method that might be a little confusing is a helper method called EntitySetName. The method helps get me the name of the entityset. It’s marked as protected not private because I need it for a lower abstraction.

There are also other Repository’s in the source that allows you to make business rules engines and attaches them to the repository here.  These will allow you to add custom validation per entity, but I hear the new CTP6 of the Entity Framework code first will have an IValidate interface for putting business logic on the entities themselves.  One advantage my business rule engine has is it allows you to have the ObjectContext to allow you to query the database.

The last piece of code you need is the IRepository code. This interface will  load up all the repositories, and allow you to moq the interfaces for testing.

   public interface IFaqRepository : IRepository
    {
          IQueryable AllPublished();
    }

The IRepository interface is more of a helper than anything. To me it simlifies what custom methods I have on a given repository. The IRepository exposes all the methods that the other repository base has (All(), ById(), Save(), Delete()).

I will do a screen cast on this in the near future. For now, you can download the full version at bitbucket.  https://bitbucket.org/tylergarlick/nexbusiness-core

Kickit on DotNetKicks.com

Read full story Comments { 4 }

BitBucket just got a lot nicer… for free!

Mercurial is becoming my favorite SCM at the moment, and BitBucket just made it sweeter. I had signed up for an account at 10/month because I wanted the private repository feature. Today I got an email explaining that now my account has been cancelled because there are unlimited public/private repositories. Only caveat, 5 users per project for private accounts. This is beautiful because most of my projects are just me and a few others (less than 5).

Anyways, if you have tried out mercurial or BitBucket do it. It’s worth your while.

Read full story Comments { 0 }

Repository Pattern Helpers

If you use asp.net mvc, and haven’t heard of the repository pattern–you should check it out.

That said, if you also use ninject or some other dependency injection at some point in time as you make implementations of your interfaces you’ll probably want to mock some data.  I do this a lot, when i’m trying to abstract out my middle tier’s models.

Most of the time, when i’m creating a mock up of a repository I just save it in memory and it works.  On the web, it’s a little different because of the whole disconnected state of the web, and the easiest good way to persist data is in a session object.

So here is a base class i’ve made to inherit from your SessionBased repositories so you don’t have to code up a bunch of data storage properties.

public class SessionBasedStorage<T> where T : new()
   {
      private readonly string _sessionName = typeof (T).FullName;
      public T DataContext
      {
         get
         {
            if (HttpContext.Current.Session[_sessionName] == null)
            {
               HttpContext.Current.Session[_sessionName] = new T();
            }

            return (T)HttpContext.Current.Session[_sessionName];
         }
         set { HttpContext.Current.Session[_sessionName] = value; }
      }
   }
 

Read full story Comments { 0 }

College Football Madness

I can’t help but loving this time of year.  College football is upon us, and there have already been some great games.

Why do I like college football?  Well, mainly because these players are playing for the love of the game.  If you throw aside the whole Reggie Bush USC fiasco–you can see these guys are really playing for the love of the game.  I love how it’s truly anyone’s game.

Contrast that to the NFL, everyone is fighting over money, and how that pick in the draft sucked, and how this team is stacked, etc. etc.  Most of the time, you know who is going to win, and the upsets are few and far between.

Now, in my opinion the BCS has to go.  College football should learn from the NFL how to do their “super bowl.”  We all know that won’t go away with out BCS finding a way to re-coop the revenue.

Go BCS Busters! Go!

Read full story Comments { 0 }

Is cheap really better?

I think when we negotiate as a whole, we usually undervalue our products, and services (this is a broad generalization).  I know I’ve found myself trying to appease to stakeholders and getting them to use my products and services by “cutting them a deal.”  I pose a question is cheaper better.

Tonight I went to Little Caesars for dinner.  Now i’m kind of a pizza snub.  I like the new Domino’s pizza, their new sauce or whatever they have changed to me is delicious.  Tonight, however, I decided what the heck, 5$ for a pizza, I can do that.  Plus I can get it quickly.  Now don’t get me wrong I have nothing against Little Caesars, I just want to illustrate a point.

The Experience.

When I drove up to this Little Caesars (yes, it has a drive-thru), I was prompted by an annoyed teenager who asked, “What can I get you?”  I told them I wanted a “Peperoni Pizza.”  5.77 at the next window the annoyed teenager said.  Now, I usually don’t care about the service, but it’s part of the point.  When I was handed my pizza the box was partially opened.  I sat it down on my seat in my car, and said, “Thanks.”  I gazed at the pizza and it seriously looked like cardboard, the cheese was melted, but greasy, and the pizza looked like it had been under the lamp for at least 1 hour.

Ordering from Domino’s is completely different.  I order online first of all.  This is very slick for me.  I don’t have to deal with a tweenager who can’t keep their hands off their phone, and can browse coupons and promotions in silence to make a logical decision on what I want to do.  When I’ve “built” my pizza, checking out is easy, and usually it prompts me for items i’ve missed.  Then the coolest part, the pizza tracker.  It literally tells me what’s going down with my pizza.  The driver (who knows me by name, or at least is smart enough to look at my receipt before hand) hands me my pizza, we inspect it, and he asks me to sign the receipt.  They are polite, and my experience has been, my pizza is litterally made “fresh.”

OK, so besides the price point, what experience would you rather have?  I guess unless your on a budget, or crave cardboard you’d probably choose Domino’s.  How do they get me to come back every time, even though I know I could get pizza for a 1/3 of the cost at Dominos.  First, technology.  I love the pizza tracker.  I know my pizza is being made where it is, etc.  In a project this is communication.  Two, the experience causes minimal friction with what i’m trying to do.  The online ordering is a tool.  It doesn’t damper what I’m trying to do, an empowers me to make logical decisions.  This is kinda like running scrum and empowering a customer to make logical decisions.  The comparisons could go on for a long time, but the bottom line is cheaper isn’t always better.

Remember when your doing a negotiation, that your not only providing a product, but a service.  The services is to make sure your customer has the right tools to make logical decisions, and to support them.  Remember tools

Read full story Comments { 2 }

Scrum, outside of software engineering

Scrum.  What is it?  Scrum is a software methology often associated with agile methodologies, and rugby.  The software methology is pretty unique as far as software methodologies are concerned.  Scrum focuses on getting stuff done with minimial friction of meetings, and being able to “hit a moving target.”

For software engineering, scrum is awesome. It allows a client to dictate what prorities are highest.  It allows developers to focus on the tasks without being interupted.  Each day status is accounted for in a daily standup.  It’s a great system.  I use it everyday.

What about in our daily lives?  I think we use scrum more than we think.  For example, in the morning I think “What did I do yesterday?”  “What do I need to do today?” “Of the things I need to do today what are my priorities?”  When something comes up, we re-arrange our priorities and execute.

So how can you get started?  Well, read more about scrum, then think to yourself how can I organize myself better.  Most likely you’ll implement scrum without knowing it, happy scrumming.

Read full story Comments { 4 }

Building a Great Website

One of the things i’m asked a lot in casual conversation is how to build a website, and how to determine a good design is.

I usually give a few pointers on how to build a good website.  The main thing is to pick someone who knows what they are doing.  There are a lot of firms and people out there who claim they know how to build a great website.  The problem is, they want to cram their solution they have pre-built and mold your project to conform to their technologies.  Now, i’m not saying that a CMS or other type of systems aren’t worth it.  Heck, my website uses wordpress–it’s a great tool for what I need it to do.  I usually just caution people when they are trying to scratch an itch to website development to seriously consider what problem you are trying to solve, and find someone who can help you make an educated decision that isn’t in sales and whom you trust.

That said, here are my guidelines for a good web design.

  1. I will not buy from a site that looks amateurish.  You’ve all seen these sites.  They look like they have been made by a punk teenage kid who does html programming at night, and goes to high school during the day.  Or maybe it’s one of those sites that can’t spell the word “the.” Whatever the case, Presentation is everything.  Your site should look like what target demographic your going for.  Take for example, President Obama’s website.  He uses a minimal interface to make it easy for people who aren’t very computer savvy.  Minimalism goes a long ways.
  2. The website must function.  This is the number one priority of any website.  Broken links?  I’m gone.   If the site takes 10+ seconds of loading time.  I’m gone.  For this reason I hate flash.  I agree with Apple on this issue.  Am I against a rich interface, No.  Just use your technologies appropriately.
  3. Purpose.  We’ve all been to these sites where the information is out of whack or misleading.  Peace out, click.  That is how your users will feel.  Probably the single more important information is content.  The rest while important content is king, to both your users and to search engines.
  4. Under-do, don’t over over-do.   I am biased.  I like minimalistic designs that are very usable, and good looking.  I take the phrase to heart a perfect design is one doesn’t need additions and to take something away leaves you wanting.
  5. Pick a web technology that will be around in 5+ years.  I remember working on a C++ web site back in the day, we were doing some cool stuff with CGI (not saying that CGI programming isn’t relevant, just in appropriate with the technologies we have).

Good Design

A lot of the principles above bleed over into this category.  However there are a few that stick out.

  1. Design for desktop and mobile.  Yes, the rise of the machines mobile is upon us.  Sites that look good on the desktop better look good on the mobile devices (focus on Android and iPhone).
  2. Make your designs consistent.
  3. Prototype early and often.  This will help out with number 2.
  4. Use fonts with discretion (you will die if you use comic sans).

These are some of my tips to get a great website built.  Please post any other tips you might have.

Read full story Comments { 1 }

iTransact C# Library

iTransact is a payment gateway that I use on almost a daily basis.  I’ve been using them with ruby on rails and found a great gem that tied in automatically.  However, the C# and .net libraries are weak or non-existant.  The result is an open source library I’ve created.

Why is this different than just pounding out xml and using iTransact’s developer api directly?  Strongly typed objects, simple error handling, and a code base you can build and customize are a few of the reasons.    There are a few different types of Requests such as: ChargeRequest, Reocurring Request, etc.  I’ll be providing more information about these requests and how they affect you.

Here is a link to the source code on CodePlex.

Here is the sample usage:

var chargeRequest = new ChargeRequest()
{
   iTransactApiKey = ConfigurationManager.AppSettings["iTransactApiKey"],
   iTransactGateway = ConfigurationManager.AppSettings["iTransactApiGateway"],
   iTransactUserName = ConfigurationManager.AppSettings["iTransactUsername"],
   BillingAddress = "123 Test Rd.",
   BillingCity = "Orlando",
   BillingState = "FL",
   BillingZip = "34787",
   BillingCountry = "US",
   BillingFirstName = "Billy",
   BillingLastName = "Bob",
   BillingPhone = "111-111-1111",

   Email = "tjgarlick@gmail.com",

   // Optional
   ShippingAddress = "123 Test Rd.",
   ShippingCity = "Orlando",
   ShippingState = "FL",
   ShippingZip = "34787",
   ShippingCountry = "US",
   ShippingFirstName = "Billy",
   ShippingLastName = "Bob",
   ShippingPhone = "111-111-1111",

   CreditCardNumber = "5454545454545454",
   Cvv = "111",
   ExpirationMonth = DateTime.Now.AddMonths(1).Month > 10 ? DateTime.Now.AddMonths(1).Month.ToString() : "0" + DateTime.Now.AddMonths(1).Month,
   ExpirationYear = DateTime.Now.Year.ToString(),

   OrderItems = new[]
   {
      new OrderItem() { Cost = 12.99m, Description = "Monthy Bill", Quantity = 1 },
      new OrderItem() { Cost = 2.99m, Description = "Shipping", Quantity = 1 },
      new OrderItem() { Cost = 12.99m, Description = "Tax", Quantity = 1 }
   },
   CustomerId = "1234"
};

var response = PaymentProcessor.ChargeCreditCard(chargeRequest);

Please feel free to comment or suggest any new features. Currently it only supports a AuthorizationRequest. Refund and other Requests coming soon.

Read full story Comments { 4 }