Skip to content

Instantly share code, notes, and snippets.

/*
Write a test or tests to validate that the correct FubarData is passed to IFubarDataService.Validate(...)
from the Fubar that is passed to ValidateFubar.
e.g. did the Fubar.Name match the FubarData.Name
-- note: imagine there was 15+ properties on both Fubar and FubarData that needed validating
*/
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.ServiceLocation;
using Moq;
namespace ServiceLocatorMocking
{
[TestClass]
public class UnitTest1
{
public class CardValidationConfiguration {
public CallValidateConfiguration CallValidateConfiguration { get; set; }
public int MonthsFromLastPaymentExpiryDateIsValid { get; set;}
}
public CardValidationService(CardValidationConfiguration config
public class CardValidationService : ICardValidationService
{
private readonly CallValidationConfiguration _config;
private readonly ICallValidateDataService _callValidateDataService;
private readonly ILogger _logger = LoggerProvider.GetLogger<CardValidationService>();
public CardValidationService(CallValidationConfiguration config, ICallValidateDataService callValidateDataService)
{
_config = config;
_callValidateDataService = callValidateDataService;
public class CardValidationService : ICardValidationService
{
private readonly CallValidationConfiguration _config;
private readonly ICallValidateDataService _callValidateDataService;
private readonly ILogger _logger = LoggerProvider.GetLogger<CardValidationService>();
public CardValidationService(CallValidationConfiguration config, ICallValidateDataService callValidateDataService)
{
_config = config;
_callValidateDataService = callValidateDataService;
public bool ValidateExpiryDate(string cardExpiryDate, DateTime lastPaymentDate)
{
if (cardExpiryDate == null || !CardDateUtil.FormatIsValid(cardExpiryDate)) return false;
DateTime expiryDate = CardDateUtil.ConvertToDateTime(cardExpiryDate, SetDayOfMonth.LastDayOfMonth);
var invalidExpiryDate = lastPaymentDate.AddMonths(3); //TODO: pass as variable
var inDate = expiryDate >= invalidExpiryDate;
//ImportSessionContext?
public class ImportSession : IImportSession
{
private readonly IImportSessionRepository _importSessionRepository;
public ImportSession(IImportSessionRepository importSessionRepository)
{
_importSessionRepository = importSessionRepository;
}
@Fodsuk
Fodsuk / gist:3129520
Created July 17, 2012 13:57
Json Serialisation
public class JsonSerialiser : ISerialiser
{
public string Serialize<T>(T t)
{
var ser = new DataContractJsonSerializer(typeof(T));
var ms = new MemoryStream();
ser.WriteObject(ms, t);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
@Fodsuk
Fodsuk / gist:2836457
Created May 30, 2012 13:52
Application workflow controller
public class ApplicationController : WorkflowController
{
public ApplicationController(IWorkflowKeyStore workflowKeyStore, IWorkflowInvokerFactory workflowInvokerFactory)
: base("face2face", "Vanquis.NewBusiness.PL.Models", "Vanquis.NewBusiness.PL.Models", workflowKeyStore, workflowInvokerFactory) { }
[NoCache]
[Authorize]
public ActionResult Index()
{
LogSystem.log.Debug("ApplicationController/Index");
@Fodsuk
Fodsuk / gist:2836453
Created May 30, 2012 13:52
WorkflowController
public abstract class WorkflowController : BaseController
{
private string _workflowReference;
private readonly string _modelNamespace;
private readonly string _modelAssembly;
private IWorkflowKeyStore _workflowKeyStore;
private IWorkflowInvokerFactory _invokerFactory;
protected WorkflowController(string workflowReference, string modelNamespace, string modelAssembly, IWorkflowKeyStore workflowKeyStore, IWorkflowInvokerFactory workflowInvokerFactory)
{