Skip to content

Instantly share code, notes, and snippets.

@msell
Created April 2, 2014 03:39
Show Gist options
  • Save msell/9927588 to your computer and use it in GitHub Desktop.
Save msell/9927588 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Headspring;
using Machine.Fakes;
using Machine.Specifications;
using Microsoft.Build.Tasks.Deployment.Bootstrapper;
using Moq;
using NServiceBus;
using NServiceBus.Unicast.Transport;
using Shouldly;
using It = Machine.Specifications.It;
namespace OnlineStoreBDD
{
public class when_an_applicant_has_a_low_credit_score
{
static ApplicationProcessingSaga _sut;
static BureauResult _creditBureauResult;
static INotificationService _mockNotificationService;
static DecisionResponse _decision;
Establish context = () =>
{
_creditBureauResult = new BureauResult{ApplicationId = Guid.NewGuid(), CreditScore = 400};
_mockNotificationService = Mock.Of<INotificationService>();
Mock.Get(_mockNotificationService).Setup(x => x.NotifyApplicant(Moq.It.IsAny<DecisionResponse>()))
.Callback<DecisionResponse>(decision => _decision = decision);
_sut = new ApplicationProcessingSaga(_mockNotificationService);
};
Because of = () => _sut.Handle(_creditBureauResult);
It should_notify_the_applicant_a_decision_has_been_reached = () =>
Mock.Get(_mockNotificationService).Verify(x=>x.NotifyApplicant(Moq.It.IsAny<DecisionResponse>()));
It should_indicate_the_applicant_was_declined = () => _decision.Result.ShouldBe(DecisionResult.Declined);
}
public class Decisions
{
}
public class DecisionResponse
{
public Guid ApplicationId { get; set; }
public DecisionResult Result { get; set; }
}
public class DecisionResult : Enumeration<DecisionResult>
{
public static readonly DecisionResult Submitted = new DecisionResult(0, "Submitted");
public static readonly DecisionResult Approved = new DecisionResult(1, "Approved");
public static readonly DecisionResult Declined = new DecisionResult(2, "Declined");
public DecisionResult(int value, string displayName) : base(value, displayName)
{
}
}
public interface INotificationService
{
void NotifyApplicant(DecisionResponse application);
}
public class CreditApplication
{
}
public class BureauResult
{
public int CreditScore { get; set; }
public Guid ApplicationId { get; set; }
}
public class ApplicationProcessingSaga
{
INotificationService _notificationService;
public ApplicationProcessingSaga(INotificationService notificationService)
{
_notificationService = notificationService;
}
public void Handle(BureauResult _creditBureauResult)
{
var applicationDecision = new DecisionResponse();
applicationDecision.ApplicationId = _creditBureauResult.ApplicationId;
applicationDecision.Result = (_creditBureauResult.CreditScore >= 650)
? DecisionResult.Approved
: DecisionResult.Declined;
_notificationService.NotifyApplicant(applicationDecision);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment