Skip to content

Instantly share code, notes, and snippets.

View harrybiscuit's full-sized avatar

Harry Biscuit harrybiscuit

View GitHub Profile
var serviceBroker = Substitute.For<IServiceBroker>();
var paymentRequest = Substitute.For<IPaymentRequest>();
var scenarioSteps = new ScenarioSteps(serviceBroker,paymentRequest);
var successfulSubmitPaymentArgs = new SubmitPaymentArgs(true);
serviceBroker.When((sb)=>sb.SubmitPayment(paymentRequest)).Do((sb)=>serviceBroker.ServiceBrokerEventHandler+= Raise.EventWith(serviceBroker, (PaymentEventArgs)successfulSubmitPaymentArgs));
var creditDebitPurchaseScenario = new CreditDebitPurchaseScenario(serviceBroker, scenarioSteps, null);
creditDebitPurchaseScenario.MakePayment(paymentRequest);
http://boxstarter.org/package/nr/url?https://gist.githubusercontent.com/harrybiscuit/a4d17f212057ed53b75f/raw/3d8f63d487e608fd045ea87452269170da007f3b/DevBoxTools
Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
cinst notepadplusplus
cinst git
cinst gittfs
cinst console2
cinst dotpeek
cinst sourcetree
cinst sysinternals
cinst linqpad
@harrybiscuit
harrybiscuit / Retry
Created October 1, 2014 08:59
A simple retry mechanism for C#
// This is not my code but I put it here so I can remember where to get it when I need it.
//http://stackoverflow.com/questions/1563191/c-sharp-cleanest-way-to-write-retry-logic
public static class Retry
{
public static void Do(Action action, TimeSpan retryInterval, int retryCount = 3) {
Do<object>(() => {
action();
return null;
}, retryInterval, retryCount);
}
public static class ExceptionExtensions
{
public static string UnwrapInnerExceptionMessages(this Exception exception)
{
var sb = new StringBuilder();
if (!string.IsNullOrWhiteSpace(exception.Message))
{
sb.AppendLine(exception.Message);
}
@harrybiscuit
harrybiscuit / gist:8711258
Created January 30, 2014 15:39
A simple workflow application monitor
using System;
using System.Collections.Concurrent;
public interface IWorkflowApplicationMonitor
{
bool IsRunning(Guid workflowDefinitionId);
void SetStatusToRunning(Guid workflowDefinitionId);
void SetStatusToNotRunning(Guid workflowDefinitionId);
}
@harrybiscuit
harrybiscuit / IterateSqlXml.cs
Last active December 20, 2015 04:18
Iterate through XML returned by SQL Server.
public IEnumerable<XElement> GetMyThings(string sqlCommandReturningXml)
{
var connectionString = ConnectionString();//You'll have to write this method. It should return a connection string.
using (var sqlConnection = new SqlConnection { ConnectionString = connectionString })
{
sqlConnection.Open();
var cmd = SqlCommand(sqlCommandReturningXml, sqlConnection);//You'll have to write this method. It should return a SqlCommand object.
using (var reader = cmd.ExecuteXmlReader())
{
@harrybiscuit
harrybiscuit / MyController.cs
Last active December 19, 2015 09:29
Custom error handling with .net MVC 3
public class MyController : Controller
{
[HandleError(View ="MyCustomError",ExceptionType = typeof(MyException))]
public ActionResult MyAction(string SaleType)
{
//Do stuff here that may throw an exception
// The following line will demonstrate what happens when an exception is thrown
throw new MyException("bang !");
}
@harrybiscuit
harrybiscuit / mex-1.xml
Last active December 19, 2015 00:09
mex endpoint configuration for wcf over net.tcp
<services>
<service behaviorConfiguration="InstanceControllerServiceBehavior" name="Services.InstanceControllerService.InstanceController">
<endpoint name="netTcpEndpoint" binding="netTcpBinding" contract="Services.InstanceControllerService.IInstanceController" />
<endpoint name="mexNetTcpEndpoint" address="net.tcp://my-server:41422/mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
</baseAddresses>
</host>
</service>
</services>
[Subject("Viewing Secured Home Page")]
public class when_viewing_a_secured_homepage_with_no_auth_cookie
{
private static HttpWebRequest request;
private static HttpWebResponse response;
private Establish context = () =>
{
request = HttpWebRequest.Create("http://localhost:53759/") as HttpWebRequest;
request.AllowAutoRedirect = false;