- hey @marthakelly have you met @garannm? she is also a big javascript fan... 7 hours ago
- woot looks like i get to spend a week working with the Know Your Meme team haxoring on some ruby in the near future. 8 hours ago
- Cheezburger is hiring C# devs. If you are lol-curious you should apply. cheezburger.theresumator.com/apply/NONdUl/A… 11 hours ago
- My weapon would be a ghost. #Blackwater 2 days ago
- RT @Cheezburger: Stick 'Em with the pointy end. A Game of Thrones Cheezburger Site chzb.gr/LBpFrw 4 days ago
I Am Not Myself
Bills.Pay(Developer.Skills).ShouldBeTrue()
Getting Started Building iOS Applications with MonoTouch
Posted by on January 16, 2012
I have been flirting with the idea of getting into mobile development in my spare time. I have went so far as to offer myself out as a developer to startups in Chicago to develop simple iOS applications in exchange for tool licenses. I am a firm believer in the idea that a craftsman buys his own tools. I am not buying them with my own money here, but I certainly am with my effort.
I also wanted to turn this experience into a few blog posts that might help someone else who has chosen to go down the same path that I have.
So what does a .NET developer need to get started writing an iOS application? There are three things to consider here. The first being picking up Objective-C as a language, second is learning the iOS API and third is relearning how to do stuff we already know like consuming a JSON service. Put another way, we need to learn a language, a platform and the idiomatic way of doing things in this particular development culture. That is a lot to bite off in a short period of time and still be productive and getting stuff done.
For this reason, I chose to develop my first few applications using Xamarin’s MonoTouch. Taking this route allows me to leverage my current skills with C# and the .NET platform while learning the iOS API and still manage to be productive. I can noodle around with Objective-C at a later time.
The first thing you will notice about MonoTouch is the price, at $399 it is quite a leap of faith. But you can install and use the evaluation version to your hearts content. You only have to pony up money once you are ready to ship to the App Store.
To get up and running with MonoTouch, you will need to install the following things in this order:
- XCode 4 – If you don’t mind paying $5, you can get this from the Apple App Store.
- MonoDevelop – This is a completely free IDE for the Mono framework.
- MonoTouch Evaulation
You will also need a Mac. Yes sorry, thems the breaks.
To create an iOS application simply select File > New Project and dig down to the MonoTouch iPhone project template. There are also templates for iPad and Universal. Universal allows you to create a single application that will work on both the iPhone and the iPad. You can also create library assemblies just like you would expect in Visual Studio.
There is one catch though, MonoTouch project types are limited in the amount of the framework you will have access to work against and what 3rd party libraries you can reference. It is similar to working with Client Profile projects in Visual Studio. Everything you reference needs to target MonoTouch as well.
For instance, I have been working on an application that consumes a Xml-Rpc service. There is already a fairly awesome OSS library from Cook Computing for all your Xml-Rpc needs. You cannot simply download the dll and reference it in your project. The dll needs to be compiled as a MonoTouch assembly. And all code needs to conform to the limited framework profile of MonoTouch. Cook Computing’s library has both client and server components in one library. The server components depend on HttpResponse & HttpReqeust which are not available in a MonoTouch application.
I was able to solve this problem fairly easily by creating my own fork of the Cook Computing library and pulling in only the types needed for client communication. I even went so far as to publish this work on GitHub so others can simply use my fork and get back to making things awesome. Yay, OSS!
If you would like to look at a couple nontrivial applications written using MonoTouch to get an idea of where to start, the Washington State Department of Transportation has a great application published to the App Store now that is fully open source. I used this application as a guide post when creating my first MonoTouch app which you can find here.
This should be enough to get you on your way to writing your first application. I have some more tips around using OSS libraries and Unit Testing, but that will have to wait for another day in another blog post. Enjoy and happy non-conformist .NET application development day.
Adron Hall Visual Studio AWS Toolkit & SDK Presentation Video
Posted by on January 14, 2012
Overview
During this presentation I will provide an overview of what is needed to get started using Visual Studio 2010 with the AWS Toolkit & SDK. We’ll also cover the basic design ideas behind the do’s and don’ts of cloud architecture and development. There will be some hands on coding (if you’d like to bring a laptop to follow along) and we will deploy code (wireless/cat5 connection pending) into AWS Cloud Services & get EC2 instances up and running live!
About Adron
I’m a jovial, sometimes TDD (Test Driven Development), sometimes BDD (Behavior Driven Development), get things done well, software architect, engineer, code monkey, coder, or what have you. I run the gamut of development stacks between the .NET Framework & Microsoft Technologies but will admit my latest favorite is Ruby on Rails and .NET MVC work with a touch of Sinatra’s clean architecture covered with an awesome layer of Javascript for tasty perfection. I love what I do and commonly add a very business oriented, get the job done, agile (sometimes eXtreme Agile, sometimes whatever it takes), and entrepreneurial effort to my work. I also like to mentor (teach), write (re: blog, etc), and even work on projects in addition to work related things.
You can find more on his site.
Video
Slides
Source
The source for this presentation can be found on Adron’s github account.
Testing Rendered Output of NancyFx with the Razor View Engine Gotchas
Posted by on January 3, 2012
I have been working on a small sample application called SignMeUp. My intention is to practice concepts I am learning while reading Growing Object Oriented Software Guided by Tests. I am using the awesome NancyFx micro-framework my web delivery mechanism and Razor as my view engine.
To start I have the following unit test.
[TestFixture]
public class when_visiting_the_root_of_the_site : with_a_browser
{
private BrowserResponse response;
public override void Given()
{
Configure(with =>
{
with.Module<RootModule>();
with.Dependency<IEmailService>(Substitute.For<IEmailService>());
with.Dependency<DataContext>(TestDataContextFactory.Build());
});
base.Given();
}
public override void When()
{
response = subject.Get("/");
}
[Test]
public void it_should_be_successful()
{
response.StatusCode.ShouldBe(HttpStatusCode.OK);
}
[Test]
public void it_should_show_the_signup_form()
{
response.Body["form"].ShouldExistOnce()
.And.Attribute["action"].ShouldBe("/");
}
}
I have been beating my head against a problem for a few days (over the course of several 1-2 hour development sessions) that has been baffling me. This test compiles and executes and the first test returns successful. The second test has always failed because the Body collection was always empty. The truly enraging thing is I could fire up the site in IISExpress and see that it worked properly.
After searching the internet high and low, trolling source repositories of example apps and finally breaking down and scouring the NancyFx source I have discovered the root of my problem.
Gotcha #1: When executing end to end tests like this from a test library you need to makes sure that your test assembly has knowledge of your views. The simplest solution for this is to set all your views to “Copy if newer” in the properties dialog in visual studio. The default view location should work from here.
Gotcha #2: Your test assembly needs to reference Nancy.ViewEngines.Razor. If you do not have this reference, Nancy will happily process your request and simply return an empty body. No error, no warning, nothing.
Will Write iOS Application for Licenses
Posted by on December 30, 2011
I am interested in getting more into iOS development. I have written some prototypes with XCode and MonoTouch. I really like MonoTouch and would really like my own license, so I can create some personal applications and play in the space. But sadly am unable to afford it at the moment.
That is where you come in. If you would like a simple iOS application for your organization and are willing to fund the purchase price of an Apple Developers license and a MonoTouch license, I will develop an application for you and walk it through the Apple submission process to get it up on the App Store.
Here are some more details:
Apple Developers License: $99
MonoTouch Professional License: $399
Payment Method: PayPal
Example of what I can do with the MonoTouch trial.
This application consumes & displays rss & twitter feeds as well as showing some nice existing web content. This is the type of application I am offering to build for you.
Sound like a deal? Are you interested? Contact me.
Getting Gilded Rose Under Test
Posted by on December 22, 2011
While I was attending the Software Craftsmanship North America conference this year, Ian Davis post a video of himself performing the Gilded Rose Kata. I really enjoyed watching it and wanted to take a stab at it myself. I had a couple hours to kill sitting at O’Hair waiting on my flight so I fired up my environment and took a stab at it.
This video is the result of that session. The video consists of me getting the system under test. I did attempt a refactoring a couple times but kept driving to Ian’s solution because it was to fresh in my head. So I trimmed the solution out of my video and left only the testing. Go watch Ian’s video for a elegant solution to the problem. Do note that there is a signifigant amount of play and experimentation in this video, I am just dorking around.
It took me a while to post this because I originally recorded the session using Camtasia:Mac, which is a horribly broken piece of software. I had to wait until I could get a license for ScreenFlow before acutally producing the video. If you are in the market for software to do this kind of video, go with ScreenFlow.
If you are interested, I am using the Giles auto test runner, Nunit and several Resharper macros in the video. You can find my source on github.
Be sure to watch in HD it makes the text much more readable.
The Four Rules of Simple Design
Posted by on December 21, 2011
When you first get involved with agile development, you quickly hear about the SOLID principals and design patterns. They are a bit much to bite off at first. Through the Ruby community I have discovered a simpler more fundamental set of guidance for beginners that appear to be fundamentals for the higher level principals of SOLID, called the Four Rules of Simple Design:
- Pass all tests
- Clear, expressive & consistent
- Duplicates no behavior or configuration
- Minimal methods, classes & modules
Here is an amazing introduction to the concept by JB Rains.
Test Driven Evolutionary Design with Entity Framework
Posted by on December 18, 2011
NOTE: I am not an Entity Framework expert nor do I claim to be. I am a user of ORMs in the general developer space and this exercise is an attempt to map my workflow and knowledge to EF and it’s associated tools. Here there be dragons.
Introduction
I have been an ORM fan for many years using open source projects in the NHibernate/Castle ecosystem. I try to push my development experience as close as I can get to the Ruby on Rails way. Combining NHibernate, Fluent NHiberate and Fluent Migrator, I am able to achieve level of malleability that allows me to evolve my data storage needs around the growing discovery of the business problem at hand. Despite getting a “thank you” in Julia Lerman‘s book on it, I have not taken Entity Framework for a serious spin because I did not feel I could achieve the same level of malleability and persistence ignorance. With the recent release of Entity Framework Migrations the last missing piece has been added and EF is now on feature parity with my beloved OSS stack.
I wanted to build something real with Entity Framework, so I came up with a simple web application to drive the project. I am going to create a simple web site that allows a user to enter their first name, last name and email address to sign up for a news letter. The system should verify that the email has not already been registered and send the registered user a validation email. The validation email should contain a link the user can click to validate the email address goes to a real person. This is a fairly simple application with a little bit of complexity to keep it interesting.
Spiking On Data Access
To get started, I know I will need to be able to save the users details. I realize this might be an odd place to start but it allows me to get to the interesting data access bits that have me curious. I start my solution with a Core library where all my core business logic will live. I like to have this assembly be completely environment agnostic, so you will notice that all dependent assemblies in the solution tend to point in toward this one. Here is where I will put my User object.
namespace TestingEntityFramework.Core
{
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
}
I know that my current goal is to be able to persist a user object and retrive it. So, I want to clearly state that goal in the form of a unit test. The idea here being that the unit test describes a portion of the behavior of the system and then that test is run thought the development of the application ensuring that the behavior still works the way we specified it should. These are of course basic Test Driven Development principals. So, I create my next assembly Tests, fire up the Nuget Package Manager Console and get a test environment set up using the following commands.
install-package NUnit install-package NSubstitute install-package Shouldly
These are the standard three testing tools I typically start out with. NUnit is my default unit testing system, Shouldly adds a nice fluent assertion syntax over the top of NUnit asserts and NSubstitute is my current favorite mocking framework. I don’t have a need for NSubstitute yet, but the style of testing I do generally leads me to it. So I add it by default. Now to make sure my testing environment is all ready to go, I add my first test.
using NUnit.Framework;
using Shouldly;
namespace TestingEntityFramework.Tests
{
[TestFixture]
public class RealityTests
{
[Test]
public void true_should_be_true()
{
true.ShouldBe(true);
}
}
}
Hitting F1 shows me that everything compiles, test run and I am ready to get going with my current goal. With Entity Framework the unit of work concept is wrapped up in the DbContext type. Typically a developer will inherit from DbContext and modify to expose aggregate roots. So I know that I will need to create a DbContext to be able to save my User instance. I think I understand enough to get my first test written.
using NUnit.Framework;
using TestingEntityFramework.Core;
namespace TestingEntityFramework.Tests
{
[TestFixture]
public class UserPersistenceTests
{
private DataContext context;
[Test]
public void can_persist_user()
{
var user = new User { Id = -1, FirstName = "Dirk", LastName = "Diggler", Email = "dirk@diggler.com"};
context.Users.Add(user);
context.SaveChanges();
Assert.That(user.Id, Is.EqualTo(1));
}
}
}
This test fails to even compile because I do not have a DataContext type in the system yet. To get the test to compile I need to create that type. So I add my third assembly to the solution, Data. The goal with the Data assembly is to completely encapsulate persistance concerns. It will have a dependency on the Core library but the Core library will have no knowledge of Data. I know that I will be using Entity Framework and Migrations, I can add them to the assembly via NuGet with the following command.
install-package entityframework.migrations
This will reach out to the NuGet server and download the migrations assemblies as well as check it’s dependencies and pull them as well. So I end up with the latest version of Entity Framework including Code First and Migrations. The Migrations package includes some initialization code that creates a Migrations folder in my Data project and adds a Configuration object that we will get to later. I can now add my DataContext type to the Data project, It looks like this.
using System.Data.Common;
using System.Data.Entity;
using TestingEntityFramework.Core;
namespace TestingEntityFramework.Data
{
public class DataContext : DbContext
{
public DbSet Users { get; set; }
}
}
My unit test will now compile and fail with a null reference exception on the calls to the DataContext object. I need some way to construct a DataContext object that has been configured for unit testing purposes.
Now I am attempting to unit test actual data access, this is generally considered an anti-pattern in unit testing circles. If I need to actually have an instance of sql server running with a database that I can communicate with that is set up with perfect test data to run my test against this is going to add a large level of complexity and brittleness to my testing. How do I interpret a failing test that failed because data was missing or the sql server was down for maintenance?
The idea solution for this would be to have a way to spin up a database instance, push my schema into it, add test data and then execute my tests against it. Optimally this process should happen for every test case and be very fast. In the OSS stack I mentioned above I would accomplish this with a combination of Fluent Migrator, Sqlite and Fluent NHibernate. Here I plan to tackle it with Code First, SqlCE and EF Migrations.
I’ll start by creating a migration for my Users table. Migrations are a way of declaratively describing a set of schema operations like creating tables, columns and keys and indexes. Migrations typically have two methods Up and Down. The up method applies the database changes to upgrade the database to the latest version an the down method removes those changes in the event of a downgrade. My User migration looks like this.
using System.Data.Entity.Migrations;
namespace TestingEntityFramework.Data.Migrations
{
public class AddUser : DbMigration
{
public override void Up()
{
CreateTable("Users", b => new
{
Id = b.Int(nullable: false, identity: true),
FirstName = b.String(nullable: false, maxLength: 255),
LastName = b.String(nullable: false, maxLength: 255),
Email = b.String(nullable: false, maxLength: 255),
})
.PrimaryKey(t => t.Id);
}
public override void Down()
{
DropTable("Users");
}
}
}
This migration will create a new table called Users with four columns Id, FirstName, LastName & Email with Id being the primary key.
Next up I need to tell Code First how to map my User type to the Users table defined by my migration. I can do this by modifying The DataContext and overriding the OnModelCreating method to look like this.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().HasKey(x => x.Id)
.ToTable("Users");
base.OnModelCreating(modelBuilder);
}
Notice that I am leaving a lot of information here out. I am simply telling Code First that the entity type User has a key Id and should be saved to the Users table. I am taking advantage of Code First’s default conventions. It will figure out what to do with all the other columns based on their type and names base on sensible conventions. For instance the User property FirstName will be saved in the column FirstName because the types and names match. This is a feature of Fluent NHibernate that I love and am glad that EF is following the same model. This allows me to focus on functionality instead of writing reams of code to specify every detail of persistence. I hope that the conventions in EF are as easily overridden as FNH because it is truly a killer feature. See my previous post on the topic for more details.
Now that I have my migrations and mapping defined I need a way to combine them and create a DataContext that communicates with an instance of SqlCE database. Back in my Test library, I add a dependency to SqlCE via NuGet with the following command.
install-package sqlservercompact
This adds a bin deployable version of SqlCE to my project that does not require any installs. This is an awesome change in SqlCe as well. In the past I have done this with Sqlite and was bitten by odd differences between Sql Server and Sqlite, but the friction added by switching to SqlCE was to great due to required installations. The latest bits removes that friction completely which is great. The only advantage that Sqlite has in this situation now is it’s ability to create in memory databases which are insanely fast which is a good thing from a unit testing stand point. SqlCE forces us to use a file which adds the overhead of IO communication into your tests. Please SqlCE team, make in memory databases happen.
With all the pieces available I can now create a factory to build up my test data context.
using System;
using System.Data.Common;
using System.Data.Entity.Migrations;
using TestingEntityFramework.Core.Extensions;
using TestingEntityFramework.Data;
using TestingEntityFramework.Data.Migrations;
namespace TestingEntityFramework.Tests.Helpers
{
public class TestDataContextFactory
{
private const string ConnectionString = "Data Source={0}.sdf";
private const string ProviderName = "System.Data.SqlServerCe.4.0";
public static DataContext Build()
{
var databaseName = DateTime.Now.Ticks.ToString();
StandUpTestDatabase(databaseName);
return CreateDataContext(databaseName);
}
private static DataContext CreateDataContext(string databaseName)
{
var connection = DbProviderFactories.GetFactory(ProviderName).CreateConnection();
connection.ConnectionString = ConnectionString.FormatWith(databaseName);
return new DataContext(connection);
}
private static void StandUpTestDatabase(string databaseName)
{
var config = new Configuration
{
ConnectionString = ConnectionString.FormatWith(databaseName),
ConnectionProviderName = ProviderName,
AutomaticMigrationsEnabled = true
};
new DbMigrator(config).Update();
}
}
}
This factory generates a random database name, creates a database connection object for SqlCE, runs all migrations on it and then constructs a DataContext and returns it. Now all I need to do is wire it up in my persistance unit test like this.
using NUnit.Framework;
using TestingEntityFramework.Core;
using TestingEntityFramework.Data;
using TestingEntityFramework.Tests.Helpers;
namespace TestingEntityFramework.Tests
{
[TestFixture]
public class UserPersistenceTests
{
private DataContext context;
[SetUp]
public void SetUp()
{
context = TestDataContextFactory.Build();
}
[Test]
public void can_persist_user()
{
var user = new User { Id = -1, FirstName = "Dirk", LastName = "Diggler", Email = "dirk@diggler.com"};
context.Users.Add(user);
context.SaveChanges();
Assert.That(user.Id, Is.EqualTo(1));
}
}
}
Hitting F1, I discover I now have a passing unit test. Every run of this test fixture generates a completely new database file, runs migrations and saves a new user validating that all the pieces (migration & mapping) work as expected. During the process of developing this application, this test will get run thousands of times ensuring that as the application evolves persistance still works the way it is expected to work. With minimal effort deployment scripts can be generated based on the migrations or I can use the migrations themselves. This gives a high level of confidence in this data access layer that you usually do not get with traditional approaches.
Driving Functionality from the Outside In with Nancy
My original goal was to build an application, I have my data access spike complete and want to get my focus back on that goal. In my next post, I will discuss test driving web applications using the NancyFX framework. If you want to take a peek at what I am up to the source is currently evolving along with the source for this post.
January 12 / Adron Hall Visual Studio AWS Toolkit & SDK, Building For the Cloud
Posted by on December 17, 2011
The South Sound .NET Users Group is proud to present Adron Hall on Visual Studio AWS Toolkit & SDK, Building for the Cloud this coming January 12th at 7:00PM at the Olympia Center, 222 Columbia NW in downtown Olympia. Adron is a personal friend and brilliant developer who I have had the personal pleasure of working with. This presentation is one you will not want to miss.
Overview: During this presentation I will provide an overview of what is needed to get started using Visual Studio 2010 with the AWS Toolkit & SDK. We’ll also cover the basic design ideas behind the do’s and don’ts of cloud architecture and development. There will be some hands on coding (if you’d like to bring a laptop to follow along) and we will deploy code (wireless/cat5 connection pending) into AWS Cloud Services & get EC2 instances up and running live!
Bio: I’m a jovial, sometimes TDD (Test Driven Development), sometimes BDD (Behavior Driven Development), get things done well, software architect, engineer, code monkey, coder, or what have you. I run the gammut of development stacks between the .NET Framework & Microsoft Technologies but will admit my latest favorite is Ruby on Rails and .NET MVC work with a touch of Sinatra’s clean architecture covered with an awesome layer of Javascript for tasty perfection. I love what I do and commonly add a very business oriented, get the job done, agile (sometimes eXtreme Agile, sometimes whatever it takes), and entrepreneurial effort to my work. I also like to mentor (teach), write (re: blog, etc), and even work on projects in addition to work related things.
December 8th SSDNUG Presents: Charlie Poole on NUnit – Beyond the Basics
Posted by on November 30, 2011
Most .NET developers have some familiarity with NUnit, but often they learn to use certain basic techniques and never go beyond them. In this talk I’ll present a some ideas you may want to try, including: parameterized tests and fixtures, generic tests, theories, the use of the TestContext and the creation of adding. The presentation will be based on the Beta 2 release of NUnit 2.6.
Charlie Poole has spent more than 35 years as a software developer, designer, project manager, trainer and coach. After a long career in the government sector, he began working independently in 1996 with clients ranging from Microsoft to government agencies to internet startups.
Charlie’s technical background is long and broad. In recent years, he has specialized in C++ and C# development in cross-platform settings. He has worked with the .NET framework since its inception, is one of the authors of the NUnit .NET testing framework and contributes to several other Open Source projects.
For the past fifteen years, Charlie has worked as an Agile coach and trainer. He is a familiar presence at Agile and Open Source events and is one of the founders of the Agile Open Northwest conference.
SCNA 2011 Brain Dump Edition
Posted by on November 18, 2011
Corey Haines started the conference off a bit worried. Are we repeating the mistakes of the ’90? Are “learn to code in 24 hour” mentalities populating startups with unprepared developers writing tomorrows legacy code? He suggests reading Learn to Program in 10 Years instead. Businesses are desperate for for people who can code. If they were desperate for people who can build houses, would we see a glut of houses falling apart two years from now? He then pointed out a few rays of hope GirlDevelopIt and Craftsmanship Academy; prime examples of the professional community reaching out to beginners and peers to help guide them past the mistakes of the past. We bring value to the businesses that hire us, part of that value is sustainability. Here is a great mind map of the entire talk by Zee Spencer, for more details.
Michael Feathers, a personal hero, followed up by challenging us to invest in learning functional concepts. He describes functional techniques as a DSL for a wider domain and it is time to integrate these techniques into a shared understanding in our programming languages. Traditional OOP developers initially have a “WTF is that?” reaction to functional techniques, proclaiming a lack of clarity. But Mr. Feathers points out that Arabic is gibberish to him, but millions of people communicate effectively every day using it. This reminded me of Rich Hickey‘s Simple Made Easy presentation at Strange Loop this year. Something that is unfamiliar to you does not make that thing complex. It may be very simple, just not easy from your current context. The line between readable and “clever” is relative to shared vocabulary. Here is a nice mind map of the talk by Chris Powers.
More to come…
Recent Comments