Skip to content

Instantly share code, notes, and snippets.

@benfoster
benfoster / InboundRouteTests.cs
Created January 28, 2012 11:37
Inbound Route Tests
[TestFixture]
public class PortfolioInboundRouteTests
{
[SetUp]
public void SetUp() {
RouteTable.Routes.Clear();
new PublicRouteRegistry().RegisterRoutes(RouteTable.Routes);
}
// Project Routes
@benfoster
benfoster / gist:2346138
Created April 9, 2012 19:51
Validating the referrer url against a collection of route value dictionaries
public static string PreviousUrl(this UrlHelper url, string defaultUrl, RouteValueDictionary[] validRoutes)
{
var previousUrl = url.GetPreviousUrl(false);
if (previousUrl == null)
return defaultUrl;
var request = url.RequestContext.HttpContext.Request;
var stubContext = new StubHttpContextForRouting(request.ApplicationPath,
VirtualPathUtility.ToAppRelative(previousUrl.AbsolutePath));
@benfoster
benfoster / gist:2360471
Created April 11, 2012 16:49
BDD with MSpec
namespace BDDDemo
{
//Story: Account Holder withdraws cash
//As an Account Holder
//I want to withdraw cash from an ATM
//So that I can get money when the bank is closed
//Scenario 1: Account has sufficient funds
//Given the account balance is \$100
@benfoster
benfoster / gist:2397891
Created April 16, 2012 11:24
BDD with MSpec and Machine Fakes
[Subject("Domain Events: Raising an event")]
public class Raising_an_event
{
public class When_an_event_publisher_is_not_defined
{
Because of = ()
=> new TestDomainObject().Start();
It Should_do_nothing = () => { };
}
@benfoster
benfoster / gist:2416766
Created April 18, 2012 21:37
Vacancy State Specs
public class VacancyStateTransitions
{
public class When_Submitting_a_new_vacancy : WithDomainEvents
{
static Vacancy vacancy;
Because of = ()
=> vacancy = new Vacancy(1);
It Should_be_unapproved = ()
@benfoster
benfoster / gist:2420047
Created April 19, 2012 09:57
MSpec output
Filling a vacancy, When it is open with appointed candidates and no running campaigns
¯ Should be filled
¯ Should send me a notification (FAIL)
Machine.Specifications.SpecificationException: Should contain elements conforming to: e => (e.GetType() == Fabrik.Recruit.Domain.Events.VacancyFilledEvent)
entire list: {
Fabrik.Recruit.Domain.Events.VacancySubmittedEvent,
Fabrik.Recruit.Domain.Events.VacancySubmittedEvent,
Fabrik.Recruit.Domain.Events.VacancySubmittedEvent,
Fabrik.Recruit.Domain.Events.VacancySubmittedEvent,
@benfoster
benfoster / Authentication and Membership
Created May 2, 2012 22:33
Is Authentication really that complicated.....
IAuthenticationService
bool IsValidLogin(string username, string password);
bool CreateLogin(string username, string password);
string GeneratePasswordResetToken(string username, int lifeInMinutes);
bool ResetPassword(string username, string token, string newPassword);
IMembershipService
UserProfile FindUserWithLogin(string provider, string providerId);
UserProfile Register(string name, string email, string provider, string providerId);
@benfoster
benfoster / gist:2586265
Created May 3, 2012 14:57
Using the clients from DotNetOpenAuth.AspNet in ASP.NET MVC
[HttpPost]
public void OAuth(string provider, string returnUrl)
{
var client = OAuthHelper.GetOAuthClient(provider);
client.RequestAuthentication(
HttpContext,
new Uri(Url.QualifyAction("OAuthCallback", "Auth", new { provider = provider, returnUrl = returnUrl }))
);
}
@benfoster
benfoster / gist:2649514
Created May 9, 2012 22:56
Raven multi map index
public class Vacancies_SummaryWithApplicationCount : AbstractMultiMapIndexCreationTask<VacancySummary>
{
public Vacancies_SummaryWithApplicationCount()
{
AddMap<Vacancy>(vacancies => from v in vacancies
select new
{
Id = v.Id,
Position = v.Position,
StateId = v.StateId,
@benfoster
benfoster / gist:2763877
Created May 21, 2012 18:45
Fluent Extensions for Image Resizer
@{
ViewBag.Title = "Index";
var builder = new ImageBuilder()
.Resize(img => img.Width(400).Height(300).Crop())
.Transform(img => img.FlipAfter(FlipType.X))
.Style(img => img.PaddingWidth(10).PaddingColor("FF0066").Margin(20).BackgroundColor("000000"))
.Output(img => img.Quality(90).Format(OutputFormat.Png));
}