Skip to content

Instantly share code, notes, and snippets.

View darrencauthon's full-sized avatar

Darren Cauthon darrencauthon

View GitHub Profile
@darrencauthon
darrencauthon / gist:1036421
Created June 20, 2011 19:53
AutoMapperAssist example
private class ProductViewMapper : Mapper<Product, ProductView>
{
public override void DefineMap(IConfiguration configuration)
{
configuration.CreateMap<Product, ProductView>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(orig => orig.Name + "WHOOPS"));
}
}
@darrencauthon
darrencauthon / gist:1092183
Created July 19, 2011 12:48
Simple.Data in SpecFlow example
[Binding]
public class AccountSteps
{
[BeforeScenario]
public void Setup()
{
Database.Open().Accounts.DeleteAll();
}
[Given(@"the following accounts exist")]
@darrencauthon
darrencauthon / gist:1092197
Created July 19, 2011 12:52
Simple.Data in SpecFlow example, Gherkin
Scenario: Submit a valid create account form
Given the following accounts exist
| FirstName | LastName | Email |
| Howard | Roark | [email protected] |
When I submit the following Create Account form
| Field | Value |
| FirstName | John |
| LastName | Galt |
| Email | [email protected] |
Then the following accounts should exist
@darrencauthon
darrencauthon / UnityRunner.cs
Created August 11, 2011 02:38
Example of error with Philip Mateescu's di_speed tests
public void Run() {
if (k.IsRegistered<IDummy>())
k.Resolve<IDummy>().Do();
else
throw new InvalidOperationException(string.Format("{0} couldn't find a dummy to practice on.", this.Name));
}
@darrencauthon
darrencauthon / Testing.feature
Created October 11, 2011 03:44
Loose Guid support in SpecFlow?
Feature: Loose Guids
Scenario: Sample loose guid
Given the account repository has the following accounts
| Id | LastName |
| 1 | Galt |
| 2 | Roark |
When I press the delete account '1' button
Then I should have the following accounts
| Id | LastName |
@darrencauthon
darrencauthon / AutomoqTest.cs
Created October 19, 2011 17:25 — forked from giggio/AutomoqTest.cs
AutoMoq problem when calling twice in a very specific scenario
using AutoMoq;
using NUnit.Framework;
namespace TestProject1
{
[TestFixture]
public class UnitTest1
{
private AutoMoqer mocker;
private SomeController controller;
@darrencauthon
darrencauthon / DropDownList.ascx
Created January 11, 2012 13:02
Dropdowns in ASP.Net MVC (with MVC Turbine)
<% Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Linq" %>
<%
var items = ViewData.ModelMetadata.AdditionalValues["SelectList"] as IList<SelectListItem>;
<select id="<%=ViewData.ModelMetadata.PropertyName %>" name="<%=ViewData.ModelMetadata.PropertyName %>" <%=(ViewData.ModelState.ContainsKey(ViewData.ModelMetadata.PropertyName) && ViewData.ModelState[ViewData.ModelMetadata.PropertyName].Errors.Any()) ? "class=\"input-validation-error\"" : string.Empty %>>
<%foreach (var item in items)
{%>
<option value="<%=HttpUtility.HtmlEncode(item.Value)%>" <%=item.Value == ViewData.Model.ToNullSafeString() ? " selected" : ""%>>
<%=Html.Encode(item.Text)%></option>
@darrencauthon
darrencauthon / WithAbstractions.cs
Created January 23, 2012 12:02
My comment on Ayende's queries v. abstractions
public void Index_should_return_the_best_selling_products(){
var products = new [new Product()];
var fakeService = new Mock<IHomeControllerWorkerServices>()
.Setup(x=>x.GetBestSellingProductCategories())
.Returns(products);
// regular work...
results.ShouldBeSameAs(products);
}
public class FindPotentiallyMatchingExamsForCompletionSignOffQuery : Query<IEnumerable<ExamResult>>
{
public override IEnumerable<ExamResult> Execute()
{
ExamResult er = null;
Component c = null;
VibrationPoint vp = null;
ExamMethod m = null;
var matchingCodeSectionIds = QueryOver.Of(() => er)
.Where(() => er.Surveillance.Id == Surveillance)
@darrencauthon
darrencauthon / employee.rb
Created May 9, 2012 03:02
Sample Ruby Unit Tests v. Specs
require 'minitest/autorun'
class Employee
attr_reader :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end